Forum
Form autopopulate from previous posted form
Does anyone know if there a is a way of populating Name, Address and Email fields on a second form from data already posted on a previous different form?
I have two forms, the user fills in the first form and successfully posts it to perch... upon submission, a second button is presented that allows the user to navigate to a second form, this second form requires their Name, Address and Email once more. Is there a way of pulling in this data from the previous form and autopopulating the relevant fields?
I'm still new to Perch and unsure where to start with this. Any help would be appreciated. Thanks in advance.
Am using Perch version 2.8.29, php 5.5.30.
Many thanks
Have found a way around this by using an action to bypass the second button and redirect users to the second form....
on the second form am just using <?php echo $_POST["Name"]; ?> to prepopulate the same fields. It's working as expected but if anyone knows a way to do this and keep the interim button (as detailed above), that would be helpful.
Thanks
If a field has the same ID as a value posted to the page, that field will be repopulated with that value. Same goes for both POST and GET, actually.
Be sure to never use
echo $_POST["Name"];
without escaping the output, as you'll allow anybody to post any content onto the page.Hi Drew, thanks for the tip here, though I don't understand what you mean by escaping the output. Have googled it, but still not making complete sense. I found this but I'm still unsure how I would go about writing this so it's safe?
Can you advise please?
https://stackoverflow.com/questions/5141513/how-to-escape-output-in-php
You can use
Many thanks for your help! Much appreciated.
Hi Drew,
Apologies. One last question regarding how this is written within the code? The current php echoes were written as the following and I've only ever seen PerchUtil written in conditional statements. Does this replace the php echo or is it written differently within the form?
<perch:input type="text" id="Title" required="true" label="Title" class="form-control" /><?php echo $_POST["Title"]; ?> <perch:error for="Title" type="required"><span class="error">Please enter your title</span></perch:error>
Many thanks Drew!