表单提交返回无内容的白页

问题描述 投票:0回答:1

我正在尝试提交表单,然后发送包含数据的邮件。我有它与AJAX一起工作,但是当没有启用javascript时,我想和PHP处理程序一起使用。目前,这是所有正在执行的代码。 (禁用ajax事件监听器进行测试)。但是,我得到的只是一块完全没有任何东西的白色屏幕。当我将form-handler-nojs.php代码直接放到form.php模板中时,所有代码都可以正确执行。我不明白为什么使用action属性时它不起作用...

form.php:

<div class="form-container">
        <form method="post" action="<?php echo get_template_directory_uri()?>/forms/form-handler-nojs.php">
          <input type="hidden" name="post_id" value="<?php echo get_the_ID(); ?>">
          <input type="hidden" name="nojs" value="nojs">

          <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">

          <label class="custom-input">
            <input type="text" name="company_name" value="" aria-invalid="" autocomplete="off">
            <span class="label-text">Company name*</span>
          </label>

          <label class="custom-input">
            <input type="email" name="email" value="" aria-invalid="" autocomplete="off">
            <span class="label-text">E-mail address*</span>
          </label>

          <button class="btn animated light" type="submit" name="submit-order-form">
            <span class='bar top'></span>
            <span class='bar right'></span>
            <span class='bar bottom'></span>
            <span class='bar left'></span>

            <span class='inner-text'>
              Order now!
            </span>
          </button>
        </form>

        <span id="message-order-form" class="form-message"></span>
      </div>

现在我的form-handler-nojs.php包含:

<?php
  if ( isset($_POST["submit-order-form"]) ) {
    //Name and email from form
    $name = filter_var(
      ucfirst($_POST['company_name']),
      FILTER_SANITIZE_STRING
    );

    $email = filter_var(
      strtolower($_POST['email']),
      FILTER_SANITIZE_EMAIL
    );

    //Set default e-mail
    $to = filter_var(
      strtolower(get_field("general", $product_id)['default_email']),
      FILTER_SANITIZE_EMAIL
    );

    //Set mail parameters
    $from = "[email protected]";

    $replyto = $email;

    $subject = "help me stackoverflow.com";

    $email_body = "
      test
    ";

    $header = array(
      'Content-Type: text/plain; charset=UTF-8',
      "From: {$from}",
      "Reply-To: {$replyto}"
    );

    //Send mail
    $sent = wp_mail($to, $subject, $email_body, $header);
  }

?>

但是我所得到的是一个空白页面,页面上绝对没有任何内容。邮件也不发送。

php wordpress forms submit form-submit
1个回答
0
投票

使用按钮输入的输入,注释是否起作用。

<input class="btn animated light" type="submit" name="submit-order-form">
© www.soinside.com 2019 - 2024. All rights reserved.