1

所以我一直在我的网站上使用这个联系表格,效果很好。但是,该页面在“服务”选项卡的中途打开,而不是像往常一样在页面顶部打开。我是 PHP 新手,所以我真的不知道如何修复它。其他人似乎没有这个类似的问题,所以我一直无法在谷歌上找到解决方案。

这是网站: http: //katyasarmiento.zzl.org

这是主页上的 PHP (index.php):

<hr id="Contact">
  <p class="spechead">Contact<small>alovely<a href="http://about.me/katyasarmiento">lady</a></small></p>
  <div class="row">
    <div class="col-lg-4"><span class="glyphicon glyphicon-envelope"></span> &nbsp;<span class="specbody">katwebd@gmail.com</span></div>
    <div class="col-lg-4"><span class="glyphicon glyphicon-earphone"></span> &nbsp;<span class="specbody">305.890.9834</span></div>
    <div class="col-lg-4"><span class="glyphicon glyphicon-calendar"></span> &nbsp;<span class="specbody"><a href="http://www.doodle.com/katwebdesigns">Schedule</a> a free consultation</span></div>
  </div>
  <br />
  <p class="specbody"> DO NOT TRY THE CONTACT FORM, I AM STILL WORKING ON IT. THANK YOU!</p>
  <div id="contact-form" class="clearfix">
    <p class="specbody">Fill out the contact form below to get in touch with me! Please provide as much information as possible so I can help you with your enquiry :)</p>
      <?php
      //init variables
      $cf = array();
      $sr = false;

      if(isset($_SESSION['cf_returndata'])){
        $cf = $_SESSION['cf_returndata'];
        $sr = true;
      }
            ?>
            <ul id="errors" class="<?php echo ($sr && !$cf['form_ok']) ? 'visible' : ''; ?>">
                <li id="info">There were some problems with your form submission:</li>
                <?php 
        if(isset($cf['errors']) && count($cf['errors']) > 0) :
          foreach($cf['errors'] as $error) :
        ?>
                <li><?php echo $error ?></li>
                <?php
          endforeach;
        endif;
        ?>
            </ul>
            <p id="success" class="<?php echo ($sr && $cf['form_ok']) ? 'visible' : ''; ?>">Thanks for your message! I will get back to you ASAP!</p>
            <form method="post" action="process.php">
                <label for="name">Name: <span class="required">*</span></label>
                <input type="text" id="name" name="name" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['name'] : '' ?>" placeholder="First Name" required autofocus />

                <label for="email">Email Address: <span class="required">*</span></label>
                <input type="email" id="email" name="email" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['email'] : '' ?>" placeholder="email@example.com" required />

                <label for="telephone">Telephone: </label>
                <input type="tel" id="telephone" name="telephone" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['telephone'] : '' ?>" />

                <label for="enquiry">Enquiry: </label>
                <select id="enquiry" name="enquiry">
                    <option value="General" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'General') ? "selected='selected'" : '' ?>>General - Say Hello!</option>
                    <option value="Sales" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'Sales') ? "selected='selected'" : '' ?>>Sales - Services & Pricing</option>
                    <option value="Support" <?php echo ($sr && !$cf['form_ok'] && $cf['posted_form_data']['enquiry'] == 'Support') ? "selected='selected'" : '' ?>>Support - Current Clients</option>
                </select>

                <label for="message">Message: <span class="required">*</span></label>
                <textarea id="message" name="message" placeholder="Your message must be greater than 20 charcters" required data-minlength="20"><?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['message'] : '' ?></textarea>

                <span id="loading"></span>
                <input type="submit" value="Send" id="submit-button" />
                <p id="req-field-desc"><span class="required">*</span> indicates a required field</p>
            </form>
          <?php unset($_SESSION['cf_returndata']); ?>
      </div> <!-- form -->

这是一个名为“process.php”的单独文件中的 php,但我认为这不是问题所在。

<?php
if( isset($_POST) ){

//form validation vars
$formok = true;
$errors = array();

//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');

//form data
$name = $_POST['name']; 
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$enquiry = $_POST['enquiry'];
$message = $_POST['message'];

//validate form data

//validate name is not empty
if(empty($name)){
    $formok = false;
    $errors[] = "You have not entered a name";
}

//validate email address is not empty
if(empty($email)){
    $formok = false;
    $errors[] = "You have not entered an email address";
//validate email address is valid
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
    $formok = false;
    $errors[] = "You have not entered a valid email address";
}

//validate message is not empty
if(empty($message)){
    $formok = false;
    $errors[] = "You have not entered a message";
}
//validate message is greater than 20 charcters
elseif(strlen($message) < 20){
    $formok = false;
    $errors[] = "Your message must be greater than 20 characters";
}

//send email if all is ok
if($formok){
    $headers = "From: Katya@katyasarmiento.com" . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $emailbody = "<p>You have recieved a new message from the enquiries form on your website.</p>
                  <p><strong>Name: </strong> {$name} </p>
                  <p><strong>Email Address: </strong> {$email} </p>
                  <p><strong>Telephone: </strong> {$telephone} </p>
                  <p><strong>Enquiry: </strong> {$enquiry} </p>
                  <p><strong>Message: </strong> {$message} </p>
                  <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

    mail("KatWebD@gmail.com","New Enquiry",$emailbody,$headers);

}

//what we need to return back to our form
$returndata = array(
    'posted_form_data' => array(
        'name' => $name,
        'email' => $email,
        'telephone' => $telephone,
        'enquiry' => $enquiry,
        'message' => $message
    ),
    'form_ok' => $formok,
    'errors' => $errors
);


//if this is not an ajax request
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
    //set session variables
    session_start();
    $_SESSION['cf_returndata'] = $returndata;

    //redirect back to form
    header('location: ' . $_SERVER['HTTP_REFERER']);
}
}

就像我说的那样,表格工作正常。它发送电子邮件等。我只是不喜欢页面在联系表单上方的打开方式。

4

2 回答 2

1

您在联系表单中的第一个输入具有自动对焦功能。这导致浏览器向下滚动到表单,以便,嗯,咳咳,自动对焦。

于 2013-11-06T23:07:33.000 回答
0

jquery 被加载两次。第二个 jquery 已经加载,页面转到服务选项卡,因为所有事件都被触发了两次。

您应该调用相同的脚本 1 次

于 2013-11-02T00:11:19.343 回答