Forum
Is it possible to mix perch:content with perch:form?
Hi,
I've made a simple jobs listing section, using the How do I create list and detail pages in Perch solution as a starting point.
One of the Perch fields on the jobs_detail.html template is <perch:content id="job-reference" />, it'd be neat if I could pull that into the form (in the same template). So when the form is submitted the job reference is sent with it.
Is this possible?
Yes, if you display the form using either
perch_content()
orperch_content_custom()
Ah, great that it's possible!
I can see in the
perch_content_custom
documentation, under the section Using content from different pages shows this can be done (brilliant).Question:
I've taken the code example from the documentation as a starting point:
I want to pull
<perch:content id="ref-code"/>
out of the jobs_detail.html template, which is being used on the work-with-us page. work-with-us uses a template called jobs.php. I've put the code below on jobs.php.I've used the * (wildcard) in 'page' because as I mentioned in my first post I\m using the How do I create list and detail pages in Perch solution as a starting point.
At the moment this isn't working....
Here's the PHP i'm using on jobs.php
Hope you can help.
I don't quite follow what you're hoping will happen with those two
perch_content_custom()
calls. Is the intention that the data will get passed from one to the other?The PHP uses a if / else statement, so I figured if I wanted the form to appear on the job page I had to put (the code below) within the
if statement
What I want to happen is:
To have the form appear beneath the job (on the detail page, not the listing page) and pass the
<perch:content id="ref-code" />
to the form. when the form is submitted I'd like to include the<perch:content id="ref-code" />
with it.I realise the current code doesn't even begin to do that bit, but I was hoping to at least get the form working before tackling that bit :)
Hi Drew
I've managed to get this to half work.
I used another
perch_content_create
to create a new region calledJob-Form
. This uses the form template I want to appear under each job.I then used
perch_content('Job-Form');
within theif statement
to pull in the Perch region only when the page is inDetail Mode
I'm rather happy!
The last bit of the puzzle (which I hope you can help with) is:
How do I pass
<perch:content id="job-reference" />
from jobs_detail.html to the form?Try:
Thanks for replying so quick (and on a Sunday!)
Unfortunately that code doesn't appear to work. The page doesn't render any HTML.
Maybe I've implemented it wrong?
Do you get any errors on the page or in your server's error log?
Page was blank but the
php_error.log
helped identify (part of) the problem.I used the error log to locate and remove the semicolon here:
The page works now and the form displays on the page under the job, but it's not pulling in the
<perch:content id="ref-code" />
from jobs_detail.html into the form.How would I do that?
What's the ID from the content region that you're trying to use?
Hi Drew
The content region ID is called Jobs.
I would like to be able to use
<perch:content id="ref-code" />
from content region ID Jobs and insert it into content region ID Job-FormThe idea being (hopefully) when the form is submitted the unique
ref-code
is sent along with it.So the ID is
ref-code
in both? (which is an invalid ID, btw)Hi Drew
Yes.
<perch:content id="ref-code" />
is set (and used) on the jobs_detail.html template. It's also used on the jobs_listing.html template to display the unique job reference code.When a job is selected from the jobs_listing page, the jobs_detail page is shown. At the bottom of the page is a form. I'd like to be able to re-use the
<perch:content id="ref-code" />
in the form (if possible).Why is
ref-code
an invalid ID? It seems to be working fine. Is it a system only ID? Or is it the hyphen?Thanks for taking the time to reply!
Hyphens aren't legal in IDs. It may work, but I can't guarantee it continuing to work.
Does
<perch:input type="hidden" id="ref-code" />
work?.....
It works! :)
I was sure I tried that right at the start of all of this, before posting to the forums.
It must of been the hyphen...
Thank you so much for your help (and patience).
I'm off to Twitter now to write a glowing tweet about the phenomenal support you guys give.