簡體   English   中英

WordPress頁面中的自定義表單不會提交/刷新

[英]Custom Form in WordPress Page Won't Submit/Refresh

我有一個使用自定義HTML / CSS / JS構建的普通網站。 我將該網站更改為WordPress網站(並將自定義的html / css / js設置為自定義WordPress主題)。 我在網站首頁上有一個聯系表,當我更改為WordPress時,該聯系表中斷了。

表單正常運行時,它將刷新頁面並將用戶帶回表單(使用錨ID = contactphilly),然后用戶將看到一條消息,確認其電子郵件已發送。

我做了很多谷歌搜索,我認為它與表單中的“動作”選項有關,但是無論我嘗試將其更改為什么,它都行不通。 我嘗試了以下操作值:

<?php the_permalink(); ?>/#contactphilly
#contactphilly
<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>
$_SERVER['REQUEST_URI']

他們都沒有工作。

這是表格的代碼:

<?php
      if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $subject = $_POST['subject'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'WebKeep.com'; 
        $to = 'info@webkeepteam.com'; 
        $subjectemail = 'Message from WebKeepTeam.com Contact Form ';

    $body = "From: $name\n E-Mail: $email\n Subject: $subject\n Message:\n $message";

        // Check if name has been entered
        if (!$_POST['name']) {
          $errName = 'Please enter your name';
        }

    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
      $errEmail = 'Please enter a valid email address';
    }

    //Check if message has been entered
    if (!$_POST['message']) {
      $errMessage = 'Please enter your message';
    }

// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
  if (mail ($to, $subjectemail, $body, $from)) {
    $result='<div>Thank You! We will respond shortly.</div>';
  } else {
    $result='<div>Sorry there was an error sending your message. Please try again later</div>';
  }
}
}
?>

    <form name="contactform" method="post" action="#contactphilly">
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">

  <fieldset class="form-group">
    <input type="text" value="<?php echo $name;?>" class="form-control transparent-input" id="name" name="name" placeholder="Name">
  </fieldset>
    <?php echo "<p class='text-danger'>$errName</p>";?>
        <fieldset class="form-group">
    <input type="email" value="<?php echo $email;?>"  class="form-control transparent-input" id="email" name="email" placeholder="Email">
  </fieldset>
    <?php echo "<p class='text-danger'>$errEmail</p>";?>
    <fieldset class="form-group">
    <input type="text" class="form-control transparent-input"  value="<?php echo $subject;?>" id="subject" name="subject" placeholder="Subject">
  </fieldset>
</div>
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
  <fieldset class="form-group">
    <textarea class="form-control  transparent-input" id="message"  value="<?php echo $message;?>" name="message" rows="6" placeholder="Message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
  </fieldset>
    <?php echo "<p class='text-danger'>$errMessage</p>";?>
  <input id="submit" name="submit" type="submit" value="Send" class="btn btn-index pull-right">
</div>
    <?php echo $result; ?>
</form>

我找到了自己問題的答案! 我完全忘記了GitHub上的這段代碼: https : //github.com/dwyl/html-form-send-email-via-google-script-without-server我在網站上的其他地方使用了它,並且有效它也適用於頁面內的表單!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM