require user login/registration after form submission

By: Mike Soriano | Asked: 02/05/2024
ForumsCategory: General questionsrequire user login/registration after form submission
Mike Soriano asked 7 months ago
Hi! I would like to know if this is possible. I would like to create a form that is visible to all users (logged in or not). After a visitor (not logged in) submits the form, he will be required to log in/register in order to save the entry.  I know I can just hide the form or page from guest users but I would like the form to be visible to all users. And I need the form submissions to be tied to a user account. Thanks in advance!
1 Answers
Rob LeVineRob LeVine answered 7 months ago
If I understand your situation correctly, you can pass the submitted entry ID or key to the login or registration form and when the login or registration happens, you can set the userid field of that submitted entry to the current user's ID. One flaw in this is if the user leaves the website without logging in or registering, their entry will be in limbo permanently.
Mike Soriano replied 7 months ago

Thanks Rob! Just to clarify, does the above example only work if the login/registration form is built using Formidable?

Rob LeVineRob LeVine replied 7 months ago

The strategy will work as long as the login and registration actions provide a developer hook that will allow you to do your thing post-login and post-registration.

Mike Soriano replied 7 months ago

I'm now trying to give this a go and I can now successfully pass the entry ID or key to another page containing the login/registration form. But I can't figure out how to set the userid of the submitted entry. Could you please provide some guidance here? Thanks much!

Rob LeVineRob LeVine replied 7 months ago

Assuming you're in a hook belonging to a non-Formidable product, you'll have set the value via Formidable commands or direct SQL. You either update (if the user ID field has a value already) or insert the data into the frm_item_metas table. User FrmEntryMeta::update_entry_meta or FrmEntryMeta::add_entry_meta to do that. See this example - https://formidableforms.com/knowledgebase/php-examples/#kb-update-a-field-value

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right