2017-07-18 88 views
0

如何在數據提交後清除for域。點擊提交後,文本框中的數據沒有被清除。在wordpress中提交後清除表單域

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 = '[email protected]'; 

    $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'; 
    } 
} 
} 
+0

請問你的表單被提交,通過AJAX? – 31piy

+0

您在ID#cf-email中選擇您的字段沒有該ID,只有名稱。設置一個ID =「cf-email」 – VA79

+0

對不起..我的壞...它確實。 :) – VA79

回答

1

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

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

你可以編輯我的腳本 – user8001297

+0

我強烈提及任何與myform類,我們需要在表單中添加此類或提交按鈕 – user8001297

+0

給你的

標籤這樣的類或ID: echo''; (「#myform」)[0] .reset();然後使用 – Deepa

0

嘗試下面的場景:

第一:使用$ _ POST空在那裏你完成你的過程。

$_POST = array(); 

二:使用下面的腳本:

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

三:完成你的過程只是referesh頁面使用PHP後:

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

它不在覈心PHP它是wordpress – user8001297