Support Forum
Support › MB Frontend Submission › Ajax Updating post BehaviourResolved
Hi,
I have an issue, where after you click submit on an update, the form disappears and is replaced by the Comfirmation Text. This means if I need to edit that post again, I have to reload the page, which defeats the purpose of using ajax. Is there a way for the form to stay visible and the confirmation text just pops up for a second?
Thanks,
Ger
Hello,
Due to some unexpected errors, the development team has decided to remove the form after submitting it if you use Ajax. If you enable the "edit" attribute, the Ajax setting will be disabled.
Ajax: Enable Ajax submission. true or false (default).
Edit: Allow users to edit the post after submitting. true or false (default). If true then ajax submission will be disabled.
Refer documentation https://docs.metabox.io/extensions/mb-frontend-submission/
Thanks Peter. Yeah, I'm aware of the Edit option, but unfortunately it won't work in my scenario. I am creating a task manager, and I have the task shown in a query loop. The user can edit the task directly from the shown task posts using the MB submission form. This works, except once they save the post, the form dispears for that task, and can't be edited again unless the page is reloaded. I can't use the edit option, as it also reloads the page and adds the post id to the url.
From your comment, it sounds like there is no hook that I can use to modify this behaviour, is this the case?
Thanks,
Ger
Yes, the form is removed by JS code so there isn't a hook to modify that behavior.
Can I reload the form for the current post using ajax after the rwmb_frontend_after_submit_confirmation?
Hi Peter,
I was able to use the action rwmb_frontend_after_display_confirmation, to recreate the form for the current post.
But, if I click update again, I get this error
Service Unavailable
The server is temporarily unable to service your request. This normally means the PHP worker exited unexpectedly. Please try again later.
It looks like ajax fails to run on the new form. Is this the unexpected errors you where referring to?
If I set ajax to false on this new form, then the form saves and the page reloads and I the form can be saved by ajax this time. Is there anything you can think of to allow the newly created form to use ajax as well?
add_action(
"rwmb_frontend_after_display_confirmation",
"reload_edit_form_on_submit",
10,
1
);
function reload_edit_form_on_submit($config)
{
if (isset($config["post_id"]) && $config["post_id"]) {
// Modify the 'edit' and 'post_id' configurations for form to be reshown
//$config['edit'] = 'true';
$post_id = $config["post_id"];
//$config['ajax'] = false;
// Create new form with updated configurations
$form = \MBFS\FormFactory::make($config);
// Start buffering
ob_start();
// Render the newly created form
$form->render();
// Flush buffer and get all content
$form_html = ob_get_clean();
// Save the changes to the form_html variable
$form_html = $document->saveHTML();
echo $form_html;
}
}