0

首先我的代码:

<?php
$postTitleError = '';
$postCompany = $_POST['postCompany'];
$postCompanyUrl= $_POST['postCompanyUrl'];  

if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) &&     wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {

if(trim($_POST['postTitle']) === '') {
    $postTitleError = 'Please enter a title.';
    $hasError = true;
} else {
    $postTitle = trim($_POST['postTitle']);
}


$post_information = array(
    'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
    'post_content' => esc_attr(strip_tags($_POST['postContent'])),
    'post_type' => 'opinie',
    'post_status' => 'pending'
);

$post_id = wp_insert_post($post_information);

add_post_meta($post_id, 'nazwa_firmy', $postCompany, true);
add_post_meta($post_id, 'url_firmy', $postCompanyUrl, true);

if ( $post_id ) {

}
}
?>

和html:

<form action="" method="POST" id="primaryPostForm" >
<div class="row-fluid">
    <div class="form-group span6">
            <label for="postTitle">Imię i nazwisko<span class="wymagane">*</span></label>
            <input type="text" name="postTitle" class="form-control required" id="postTitle" placeholder="Imię i nazwisko" value="<?php if(isset($_POST['postTitle'])) echo $_POST['postTitle'];?>">
    </div>
    <div class="form-group span6">
            <label for="postEmail">Adres e-mail<span class="wymagane">*</span></label>
            <input type="email" name="postEmail" class="form-control required" id="postTitle" placeholder="Twój e-mail" value="<?php if(isset($_POST['postTitle'])) echo $_POST['postTitle'];?>">
    </div>
<?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
        <input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" class="btn btn-primary">Dodaj</button>
</form>

我需要在不刷新页面的情况下发布此表单。我希望使表单消失,并显示此表单已成功发送的消息。我不知道该怎么做,我在谷歌上看过,但没有任何效果。

4

1 回答 1

0

Add another div that says that the submit was ok with a display:none, and add a onSubmit handler to hide the form.

roughly :

<form .... onSubmit="javascript:{getElementById('primaryPostForm').style.display='none';getElementById('myMessage').display='block';}">
</form>
<div id="myMessage" style="display:none">
      Submit OK
</div>
于 2013-09-16T13:39:03.017 回答