在wordpress

时间:2017-07-18 11:36:04

标签: javascript php jquery wordpress

如何在提交数据后清除for,字段。点击提交后,文本框中的数据不会被清除。

HTML:

function html_form_code() {
echo '<div class="thb_subscribe">';
echo '<h3 class="subscriberlogin">SUBSCRIBE</h3>';
echo '<p class="subscribertext">Subscribe now to get notified about latest updates!!</p>';
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';

echo '<div class="emails" style="margin-left: -308px;">';
echo '<input type="email" id="cf-email" name="cf-email" placeholder="Your E-Mail" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="42" required />';
echo '</div>';

echo '<div class="subjectline" style="display:none;">';
echo 'Subject (required) <br/>';
echo '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value=" Subscription List"  />';
echo '</div>';

echo '<div class="signup"><input type="submit" name="cf-submitted" value="Sign Up"></div>';
echo '</form>';
echo '</div>';
 }

脚本:

jQuery(document).ready(function($) {
$('#cf-email').val(''); //txtID is textbox ID
});​

尝试使用此代码,但无效。

发送电子邮件:

function deliver_mail() {

// if the submit button is clicked, send the email
if ( isset( $_POST['cf-submitted'] ) ) {

    // sanitize form values
    $email   = sanitize_email( $_POST["cf-email"] );
    $subject = sanitize_text_field( $_POST["cf-subject"] );
    $message = "This person $email  has been subscribed to your channel. ";

    // get the blog administrator's email address       
    $to = 'XXXX@gmail.com';

    $headers = "From:  <$email>" . "\r\n";

    // If email has been process for sending, display a success message
    if ( wp_mail( $to, $subject, $message, $headers ) ) {
        echo '<div>';
        echo '<div id="deletesuccess">Thanks for Subscribing .</div>';
        echo '</div>';
    } else {
        echo 'An unexpected error occurred';
    }
}
}

2 个答案:

答案 0 :(得分:1)

您可以在表单上使用.reset()。

$(".myform")[0].reset();

答案 1 :(得分:0)

尝试以下方案:

首先:在完成流程的地方使用$ _POST为空。

$_POST = array();

第二:使用以下脚本:

 $("form").submit() {
    $(this).closest('form').find("input[type=text], textarea").val("");
 });

第三:完成你的过程后,只需参考页面使用PHP:

header("Location: http://example.com/");