Use API hook/filter to populate fields before submit?
-
Is there an API hook or filter we could use to populate certain fields on a form when it’s loaded on the page, before submitting?
What we’d like to do is create a ‘confirmation page’ that takes data entered on a previous form and shows it in a textarea field on a new form, where the user can confirm their choices without changing them, and pay an amount previously determined on the first form via a Stripe checkout.
So we’d like to also populate a ‘calculation’ field (preferably, since it’s ‘read only’ or a ‘number’ field to be used for the amount for Stripe.
Or is there another solution for a confirmation/checkout type page?
Thanks for any help.
-
Hi @jamminjames,
Would recommend exploring the following hook for the text area:
apply_filters( 'forminator_field_text_markup', $html, $field );For calculations, it is important to note that both JavaScript and PHP are utilized. Initially, calculations occur on the front end using JavaScript, and subsequently, these calculations are replicated on the back end with PHP.
To ensure this works smoothly, you can try to implement
apply_filters('forminator_field_calculation_markup', $html, $id, $required, $value)for markupAnd
apply_filters('forminator_field_calculation_calculable_value', $formula, Forminator_CForm_Front_Action::$prepared_data, $field_settings)for applying calculations.This two-phase approach ensures consistency and accuracy
You can also check the following docs for more info and see if that helps:
https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/However, this will require custom coding. I’m afraid providing the custom code will be outside the scope of support. For that, you’ll need to hire a developer to provide the required custom code for you. WordPress provides a jobs directory here https://jobs.wordpress.net/
If you need further advice about it, feel free to email us at [email protected] using the following subject.
“Subject: ATTN: WPMU DEV support – wp.org”
Regards,
Nithin
Your link to the api docs doesn’t specify any hooks or filters. Where can we find a list?
@delanthear, they don’t have such a list, unfortunately! They’ve told me in the past to download the Forminator plugin folders and search for hooks or filters.
@wpmudevsupport11, thanks. I am a coder, so this is the type of thing I was looking for, and could help. However, I came up with a non-coding solution that seems like it’ll work:
- Create an html field and put the fields in it that I want to show, using the ‘insert’ button. This will effectively copy the data from those fields into the html field. You can put text in there as well, to create a list of the user’s inputs to the various fields with descriptions, like “Name: {name-1}” etc.
- Save the form as draft using js, so that you can direct the user where you want them to go, along with the Draft id.
- Hide the new html field and the Stripe (or whatever you use) payment field at first, until the user returns with a parameter in the url (created by your code in the location you previously sent the user to).
- When they return, hide the original fields and un-hide the html field, which now serves as a ‘confirmation list’, as well as the Stripe field, so they can now pay.
Update: Upon testing this method (which I described in my last post), Forminator doesn’t seem to save fields upon submission if they are hidden, is this right? Very disappointing, if true.
When the form was saved as draft, it recorded all the fields, but they all seemed to have disappeared once the form was submitted with the Stripe payment. This seems totally illogical. I highly doubt there are any Forminator users who want all that data to disappear, simply because fields are hidden.
Also, once a draft form is submitted, its entry_id changes (also illogical, seems to me). How can we get the new entry_id programmatically if we want to update fields upon submission? The ‘forminator_custom_form_after_save_entry’ hook that we’re using requires the entry_id.
-
This reply was modified 11 months, 2 weeks ago by
jamminjames.
-
This reply was modified 11 months, 2 weeks ago by
jamminjames. Reason: how to get new entry_id upon form submission?
Update: Neither the ‘forminator_custom_form_after_save_entry’ nor the ‘forminator_custom_form_after_handle_submit’ hook seems to fire after submitting the form. We have logging set up, and nothing gets logged from these hooks, nor is anything we’re trying to do with them happen. How do we troubleshoot this?
After much hunting around, I found a hook: forminator_form_ajax_submit_success
Is this the one to use for a form submitted via ajax?
I still cannot get it to work, but it would sure be nice not to have to put effort into hooks that we find out later are no longer working. If we could at least be sure that a certain hook is supposed to work, and is current, then we could not waste a lot of time on hooks we find out later are deprecated.
Forminator REALLY needs to post something in documentation that makes it clear what actions and filters are current and not deprecated! There is so much misinformation and confusion out there, what with all the changes over the years.
-
This reply was modified 11 months, 2 weeks ago by
jamminjames.
Hi @jamminjames
We have some hooks:
forminator_form_before_handle_submit forminator_form_after_handle_submit forminator_form_before_save_entry forminator_form_after_save_entryNote that we replaced the _custom_form keeping it as _form only.
Create an html field and put the fields in it that I want to show, using the ‘insert’ button. This will effectively copy the data from those fields into the html field. You can put text in there as well, to create a list of the user’s inputs to the various fields with descriptions, like “Name: {name-1}” etc.
The HTML field accept macro out of the box so entering the {name-1} will work fine without an insert button, but in case you need that button then you would be using JS code for that since it is a dynamic thing.
Save the form as draft using js, so that you can direct the user where you want them to go, along with the Draft id.
A workaround is to trigger the click() on save as draft, but yes, this can be a bit tricky to achieve.
Hide the new html field and the Stripe (or whatever you use) payment field at first, until the user returns with a parameter in the url (created by your code in the location you previously sent the user to).
It is doable with hidden field.
https://monosnap.com/file/jhUIfWUQu4kFxXBQP8mLwx58hwAq7W
Create a hidden field using “query parameter” then in your payment field conditional you will set the value you expect https://monosnap.com/file/rbIkXGhn4Jhtc4XJNJ1NURPe7Xh840
example ?payment=true would trigger the PayPal to be visible in my example.
When they return, hide the original fields and un-hide the html field, which now serves as a ‘confirmation list’, as well as the Stripe field, so they can now pay.
It wouldn’t be possible out of the box, but you may explore the same hidden approach or otherwise it would require a JS code to hide / show the fields on fly.
Update: Upon testing this method (which I described in my last post), Forminator doesn’t seem to save fields upon submission if they are hidden, is this right? Very disappointing, if true.
If you are referring to hidden by conditional yes, it is a security matter not saving hidden content unless you specifically want to for example by using hidden field.
The save and continue also has the following limitations:
Upload, Paypal, Stripe, Signature, Password, Consent and Captcha fields won’t be saved in the form draft.
https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#save-and-continue
In case you need any further information for specific hook or approach please let us know and we can check with our developers what would be the best way to achieve it. However note, as mentioned before we can’t give the custom coding as it is out of our support scope, we can guide you to the direction by explaining the hooks and what can and cannot.
Best Regards
Patrick FreitasThank you for your response. Will the hooks you listed work with Ajax submissions?
Thank you for your response. Will the hooks you listed work with Ajax submissions?
One that you listed, “forminator_form_after_handle_submit”, would probably be the one we’d want, if it works, but I’m pretty sure I’ve tried it. Will try again.
Meanwhile, there’s a support thread from nearly three years ago that says this about that hook: “We’ve recently made changes to the actions and filters in Forminator – forminator_form_after_handle_submit is no longer available because of this and instead you can use forminator_form_submit_response and/or forminator_form_ajax_submit_response and reverse the parameters.”
So, did the API switch back again? Or is this correct?
Hi @jamminjames,
It looks like there was a confusion in the forum response that you mentioned. We are extremely sorry about the same. It was “forminator_custom_form_before_handle_submit” which has been deprecated, “forminator_form_before_handle_submit” should work fine.
Best Regards,
Nebu JohnThanks. Will that work with AJAX form submission?
Do those hooks trigger when the form is submitted? Is there a hook or filter that can be used for adding data to the entry fields when the form first loads, before they submit?
Hello @jamminjames
Do those hooks trigger when the form is submitted?
The shared hooks will run after and during the form submission.
Is there a hook or filter that can be used for adding data to the entry fields when the form first loads, before they submit?
I asked our developers about your question, and will get back to you soon once we have further updates.
Best Regards
AminThanks. Really all it has to do is trigger when the form loads.
Also, another question: Is there a hook that can take a draft save and finish the submission of the form?
-
This reply was modified 11 months, 2 weeks ago by
jamminjames. Reason: hook to finish submission?
The topic ‘Use API hook/filter to populate fields before submit?’ is closed to new replies.