Ajax form resubmission after failed validation (causes invalid error message)
Support › MB Frontend Submission › Ajax form resubmission after failed validation (causes invalid error message)Resolved
- This topic has 9 replies, 2 voices, and was last updated 3 years ago by
Nicholas Cox.
-
AuthorPosts
-
March 3, 2022 at 6:19 AM #34240
Nicholas Cox
ParticipantHi,
I was just testing a form and found an issue when ajax is enabled. I have tested this on several forms and can reproduce the error.
So if you create a basic form e.g. post_title
add_filter( 'rwmb_meta_boxes', 'dc_product_register_meta_boxes' ); function dc_product_register_meta_boxes( $meta_boxes ) { $meta_boxes[] = [ 'title' => 'Products', 'post_types' => 'product', 'storage_type' => 'custom_table', 'table' => $wpdb->prefix . 'dc_products', 'id' => 'dc-product', 'context' => 'normal', 'fields' => [ [ 'type' => 'text', 'name' => 'Title', 'id' => 'post_title', 'class' => 'dc-post-title', 'limit' => 50, 'required' => true, ] ], ]; return $meta_boxes; }
Then add the shortcode to a page with ajax enabled
[mb_frontend_form id="dc-product" confirmation="Your post has been successful" ajax="true"]
Go to the form and enter the post title field as 'test'. The form fails and displays the error message
add_filter( 'rwmb_frontend_validate', function( $validate, $config ) { if ( 'dc-product' !== $config['id'] ) { return $validate; } if ( $_POST['post_title'] == 'test' ) { $validate = 'test error'; // Return a test error message } return $validate; }, 10, 2 );
Then go an update the post title to be anything else (so it validates) and then you will see that instead of the form submitting successfully you see the following error message
"Invalid request. Please try again."
I have tested this several times and cannot get it to validate if the form fails using 'rwmb_frontend_validate'. I assume the problem is from
/mb-frontend-submission/src/Shortcode.php (line 104)
Thanks
March 3, 2022 at 3:03 PM #34259Long Nguyen
ModeratorHi,
From the new version 4.0.0, MB Frontend Submission uses table wp_options to store form config and errors with the option key mbfs_key. Please check the frontend form on your site if it has this hidden field https://monosnap.com/file/M01XVOw9JKsR1ZGxlOTPgPOtWuwQ5n
March 3, 2022 at 4:34 PM #34261Nicholas Cox
ParticipantMarch 3, 2022 at 4:58 PM #34263Nicholas Cox
ParticipantI have done some screen recordings for you
If the form fails validation and then you resubmit the form, the invalid error message displays.
https://drive.google.com/file/d/1L6QiqZkXKsl70IdC_ajPM4TOk3mDXHxR/view?usp=sharing
If there are no validation errors the first time, the same form submits successfully.
https://drive.google.com/file/d/1moTAPLOdVy0X81NnXiqaOdgoIGr5Xjxe/view?usp=sharing
also to note, this does not happen when ajax is not enabled; as I assume the page refresh has something to do with it.
March 4, 2022 at 12:54 PM #34290Long Nguyen
ModeratorHi,
I'm not able to reproduce this issue on my local site, screen record https://monosnap.com/file/h8wFhZBQM4AEKylGz5l2y4Xo7f3esY
If you have online hosting, please share the staging site credentials, I will help you to check the issue.
March 4, 2022 at 5:32 PM #34305Nicholas Cox
ParticipantHi Long,
ok I have setup a staging website as I do not have a test environment.
So I have cloned my local setup (no website design yet as I'm just developing)
https://samsskip.co.uk/stg_155a6/with the following shortcode on the homepage
[mb_frontend_form id="dc-product" confirmation="Your post has been successful" ajax="true"]
then if you enter the word 'test' into the input field and then retry, the form fails.
screen recording
https://drive.google.com/file/d/1iOypa0dYmMin2YMCgyOqSMJI9qfFeKiE/view?usp=sharingif you need access to files/login then let me know so I can send you this privately.
March 5, 2022 at 10:37 AM #34325Long Nguyen
ModeratorHi,
Please share your site credentials via this contact form https://metabox.io/contact/. I will forward this to the development team to take a closer look.
Thank you.
March 5, 2022 at 6:37 PM #34331Nicholas Cox
ParticipantHi
That would be great thanks! I am at a loss on what the issue is.
I have sent an email just now via the contact form with admin access and ftp details.
Thanks
Nick
April 1, 2022 at 3:58 PM #35401Long Nguyen
ModeratorHi,
Please update the plugin MB Frontend Submission ver 4.0.1 or Meta Box AIO ver 1.15.8 and re-check this issue. Let me know if it works.
April 1, 2022 at 4:47 PM #35403Nicholas Cox
ParticipantHi
Thanks for looking into this. I have tested this and can confirm the issue has been fixed! I have tested a few forms and so far there has been no issues.
Thanks
-
AuthorPosts
- You must be logged in to reply to this topic.