1

だから私は自分のウェブサイトでこのお問い合わせフォームを使用してきましたが、うまく機能しています。ただし、通常のようにページの上部ではなく、「サービス」タブでページが途中で開きます。私はPHPが初めてなので、それを修正する方法が本当にわかりません。このような問題を抱えている人は他にいないので、Google で解決策を見つけることができませんでした。

ここにウェブサイトがあります: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

0

jquery が 2 回読み込まれています。2 番目の jquery が読み込まれると、ページはサービス タブに移動します。これは、すべてのイベントが 2 回トリガーされるためです。

同じスクリプトを 1 回呼び出す必要があります

于 2013-11-02T00:11:19.343 に答える