我试图将一些jQuery插入一个gravity forms的钩子(gform_post_paging),以便在一个多页的表单上禁用上一个按钮。 我得到一个jQuery没有被定义的错误。 我确信jQuery被调用了,所以不确定发生了什么。 多页表单使用的是ajax,如果这很重要的话。
我的代码。
add_action( 'gform_post_paging_4', 'alert_user', 10, 3 );
function alert_user( $form, $source_page_number, $current_page_number ) {
if ( $current_page_number == 2 ) {
$to = $_POST['input_3'];
$subject = ot_get_option( 'consultant_verification_email_subject' );
$headers = array('Content-Type: text/html; charset=UTF-8');
// get the email content from option tree. We are setting a static value for the code.
// if this code needs to change, it should be updated in gravity forms for now
// @todo: we could randomize this value if we want then check the value using jquery
$body = ot_get_option( 'consultant_verification_email' );
wp_mail( $to, $subject, $body, $headers );
<script type="text/javascript">
alert( 'An email was sent to <?php echo $to; ?> with your verification code. Please enter this code to continue. Should you have failed to receive this email, please click the previous button, confirm your email, and click next again. Should you continue to encounter difficulty, please contact us.' );
</script>
} else if ( $current_page_number == 3 ) {
// disable the previous button so user cant go through verification steps again
<script type="text/javascript">
jQuery(".gform_previous_button").prop("disabled",true);
</script>
也许使用vanilla js来做这个也很容易。