We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

Pass form information to second form

I have a current client site that I would love to use perch on. My only hesitation is that they have a complicated form situation. They have a lead generating form that is split across 2 pages, the homepage and a second page. The homepage is https://www.normandyins.com/index.html. They have a form with 2 fields that passes the information to the next page and prepopulates those fields in the next form.

For example the homepage form: Name and Email

Pressing 'continue' button records this form as a submission and passes the information via the url to the next page where name and email are pre populated. The person then fills out a longer form without having to fill out his name and email again.

It was done this way so that my client can still capture information from people who don't fill out the second page.

Is there a way to do this with perch and how?

Sara Apfelbaum

Sara Apfelbaum 0 points

  • 1 year ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Sara,

I think you can do this with Perch.

If you add the second page link to the action attribute in your form tag, you should be able to get the data on the page you specify. The Forms app should still record the submission as long as you add it to the app attribute.

<perch:form id="first_form" method="post" app="perch_forms" action="/second-page">
<!--* form fields *-->
</perch:form>

On the second page you can check whether you have the data with $_POST or perch_post():

if (perch_post('email')) {
  // you have data from the first form field with id="email"
}

And you can pass the data into your second form template with:

if (perch_post('email')) {
  PerchSystem::set_var('post_email', perch_post('email'));
}

In the form template you can pre-fill the name and email fields with the value attribute if you have the data:

<perch:input id="email" type="email" <perch:if exists="post_email">value="<perch:forms id="post_email" />"</perch_if> />

Docs:

Drew McLellan

Drew McLellan 2638 points
Perch Support

Forms will actually auto-fill from any posted field with the same name. So if your second form has hidden fields to duplicate those from the first, they'll be filled automatically and be submitted with the second form.