【发布时间】:2020-07-01 08:46:40
【问题描述】:
我在 php 中有一个模态表单(wordpress 网站的 bootstrap4 主题)。用户在此模式下提交表单后,页面“重新加载”并且“表单提交成功”消息替换了表单。这意味着当用户单击按钮再次打开模态框时,那里没有表单;只是一个成功的消息。如何防止这种行为?我想将用户的表单“重置”为干净的表单,以便他们每次都可以一次又一次地提交。 这是上下文中的站点代码:https://github.com/bettersg/mediaspin/blob/master/articlemodal.php
这就是表单本身:
<div class="fade modal pg-show-modal" id="article_modal" tabindex="-1" role="dialog" aria-labelledby="article_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<?php $mailer = new PG_Article_Form_Mailer(); ?>
<?php $mailer->process( array(
'form_id' => 'article_form_mailer_id',
'send_to_email' => true,
'save_to_post_type' => true,
'post_type' => 'article',
'captcha' => true,
'captcha_key' => get_theme_mod( 'captcha_key' ),
'captcha_secret' => get_theme_mod( 'captcha_secret' )
) ); ?>
<?php if( !$mailer->processed || $mailer->error) : ?>
<form action="#" class="wordpress-ajax-form" method="post" onsubmit="event.stopImmediatePropagation();event.stopPropagation();">
<div class="modal-content" id="article_form_mailer_id">
<div class="modal-header">
<h5 class="modal-title" id="article_modallabel"><?php _e( 'New Article Submission for Current Issue', 'mediaspintheme' ); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php global $post; ?>
<input type="hidden" placeholder="CurrentIssue" name="issue" value="<?php echo $post->ID; ?>"></input>
<div class="form-group">
<label for="message-text" class="form-control-label">
<?php _e( 'Link to news article (not social media or forum post) that spins it:', 'mediaspintheme' ); ?>
</label>
<input type="text" class="form-control" id="article1" required placeholder="https://linkhere.com (do not post social media or forum links)" name="article1" value="<?php echo ( isset( $_POST['article1'] ) ? $_POST['article1'] : '' ); ?>">
</div>
<div class="g-recaptcha" style="margin:10px 0;" data-sitekey="<?php echo get_theme_mod( 'captcha_key' ) ?>"></div>
<input type="hidden" name="article_form_mailer_id" value="1"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
<?php _e( 'Close', 'mediaspintheme' ); ?>
</button>
<button type="submit" class="btn btn-primary">
<?php _e( 'SUBMIT', 'mediaspintheme' ); ?>
</button>
</div>
</div>
</form>
<?php endif; ?>
</div>
</div>
<?php if( $mailer->processed ) : ?>
<?php echo $mailer->message; ?>
<?php endif; ?>
我怀疑这是因为 if 语句 ( <?php if( !$mailer->processed || $mailer->error) : ?>) 是围绕表单框起来的,但我不确定正确的方法是什么。有关如何更改 if 语句或移动它以使其在成功提交后不会导致表单消失的任何建议?
表单提交正确,一切正常。但是这个界面怪癖很烦人。
【问题讨论】:
-
我理解这个问题,但不是你想要达到的目标。在用户提交表单并重新加载页面后,表单必须再次出现。但是您是否还想显示成功消息?
-
是的,@Raffobaffo 是正确的。我希望表格首先出现。用户完成并提交表单。根据php表单处理提交后页面重新加载。然后用空白字段重置表单,但成功消息位于该表单的顶部。 “您的表单已成功提交。在下面提交另一个输入:”
-
好酷。我会给你写一个答案。
-
为什么这个问题被否决了?