联系表单不在iphone上验证 [英] Contact form does not validate on an iphone

查看:91
本文介绍了联系表单不在iphone上验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下联系表单无法通过iPhone提交时进行验证...
可以在此处预览: loaistudio .com / contact

The following contact form is not validating when submitting from an iphone... It can be previewed here: loaistudio.com/contact

当我试图提交表单而不用记录字段时,它打开了一个新的空白页面,只显示左上角的数字1 这根本不应该这样做,并且实际上是将表单空白地发送出去......它不会在桌面上这样做。

When I tried to submit the form without felling the fields, it opened a new blank page showing number 1 only on the top left side "which is not suppose to do at all" and actually sent the form empty... It does not do that on desktop.

我玩弄了代码尝试找到问题,但不知道问题出在哪里!请帮忙。

I played around with the code trying to find the issue but no idea where is the problem! please help.

   <?php
       session_start();

       if ($_SERVER['REQUEST_METHOD'] == 'POST'){
          ob_start();

          if(isset($_POST['name'])
          && isset($_POST['email'])
          && isset($_POST['message'])
          && isset($_POST['token'])){

             if($_SESSION['token'] != $_POST['token']){
                $response = "0";
             } else {
                $_SESSION['token'] = "";
                $name = $_POST['name'];
                $email = $_POST['email'];
                $message = $_POST['message'];

                $to = "EMAIL GOES HERE";
                $subject = "New Message From: $name";
                $message = "$message";

                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                $headers .= 'From: '.$email . "\r\n";
                $mailed = ( mail($to, $subject, $message, $headers) );

                if( isset($_POST['ajax']))$response = ($mailed) ? "1" :
                "0"; else $response = ($mailed) ? "<h2>Success!</h2>" :
                "<h2>Error! There was a problem with sending.</h2>";
                echo $response;
             }

          } else {
             echo "Form data error!";
          }

          ob_flush();
          die();
       }

    ?>
    <!DOCTYPE html>
    <html class="no-js">
    <head>
       <title>Contact us | Website</title>
    </head>

    <body>
          <div class="wrapper" id="contactPage">
             <div class="content">

                <?php
                   $token = md5(uniqid(rand(), TRUE));
                   $_SESSION['token'] = $token;
                ?>

                <!--Contact Form-->
                <form action="contact.php" id="contactForm" method="post" name="contactForm">
                   <input name="token" type="hidden" value="<?php echo $token; ?>">
                   <input name="ajax" type="hidden" value="1">

                   <div class="name">
                      <p>Your Name</p>
                      <input name="name" placeholder="Enter Name" required="" type="text">
                   </div>

                   <div class="email">
                      <p>Email Address</p>
                      <input name="email" placeholder="Enter Email" required="" type="email">
                   </div>

                   <div class="message">
                      <p>Message</p>
                      <textarea name="message" required=""></textarea>
                   </div>

                   <button id="submit" type="submit">Send</button>
                </form>

                <script type="text/javascript">
                   $("#contactForm").submit(function(event) {

                      event.preventDefault();
                      $submit = $(this).find('button[id="submit"]');
                      var posting = $.post($(this).attr('action'), $('#contactForm').serialize());

                      posting.done(function(data) {
                         $('span.error').remove();

                         if (data == "1") {
                            $submit.text('Sent. Thank You!');
                            $submit.addClass("sent");
                            $submit.attr('disabled', 'disabled');
                         } else {
                            $submit.after('<span style="display: inline-block; padding: 15px 5px; color: #bd3d3d">Failed to send the message, please try again later.</span>');
                            $submit.text('Try Again');
                         }
                      });
                   });
                </script>
    </body>
    </html>


推荐答案

您在html的末尾添加了jquery,但是你在使用jquery之前,所以JavaScript打破了 Uncaught ReferenceError:$没有被定义

尝试将这一行移动到标题:

you are adding jquery at the end of the html but you are using jquery before that, so javascript breaks with Uncaught ReferenceError: $ is not defined.
try moving this line to header:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

这篇关于联系表单不在iphone上验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆