Forum
Pull content id into a hidden form field
Hi,
Is there anyway to pull the value from a content field in one region, to a hidden field in a form which lives in a seperate region? I know if they were in the same template for a region that I could do it, but what if they are seperate?
For instance:
training-camp.html
<perch:content id="trainingCampTitle" type="text" />
training-camp-form.html
<perch:form id="trainingCampForm" class="is-Form" method="post" prefix="form" app="perch_forms" role="form">
<perch:input type="hidden" id="ref" value="<perch:content id="trainingCampName" type="text"/>" />
</perch:form>
Hi Mat,
In your page's .php you can display the form with perch_content_custom() and pass the first region as the first argument.
So if the name of your first region was * Training Camp Title* you would do
https://docs.grabaperch.com/functions/content/perch-content-custom/
I hope this helps.
Hi Prokopios,
That didn't seem to do it for me. I did managed to sort of achieve what I was after, although it had issues.
So here my template
training-camps.php
single-Paymentform.html
So I create my two regions, then call them in using
perch_content_custom()
- the problem is that I am getting two forms appearing. But I am getting thecamp name
placed into my hidden form field. I just can't work out why I am getting two forms - once I enter the thank you text into the editable field for the form region. It's at the point of hitting enter and submitting the data that I get a second form appearing.I found the method for it here: https://docs.grabaperch.com/perch/content/functions/content-from-multiple-pages-and-regions/
You'll need to get the value and pass it into the form template with
PerchSystem::set_var()
.https://docs.grabaperch.com/templates/passing-variables-into-templates/
Hi Drew,
Thanks! I have managed to pull out an array of the contents from that region using:
I'm stuck trying to work out how I can then access one of the individual IDs from that array. The output of that system var is:
Which property do you want?
Trying to access
campName
You'd use:
$camptitle[0]['campName'];
to call the ID from the array. e.g.Thank you Simon and Drew. Working perfectly.