Forum
Select list generated from category not submitting selected option.
I've created a form that includes a 'Where did you hear about us' select list. This is being generated from a 'referrers' category list that the client can update. Although it displays in the form correctly it doesn't appear in the submission. If I swap the generated select options for hard-coded ones, of the same options, then it does appear in the submission. I don't get any errors during the submission.
I'm going about this by creating a category template that outputs the 'referrer' category list appropriately for the form template –
<perch:category id="catTitle" type="smarttext" label="Title" required="true" />|<perch:category id="catSlug" type="slug" for="catTitle" /><perch:if not-exists="perch_item_last">,</perch:if>
Then, in the page, storing this as a variable and passing it to the form –
$referrer = perch_categories([
'template' => 'referrer',
'set' => 'referrer',
'skip-template' => true,
'return-html' => true,
]);
PerchSystem::set_var('var_referrers', $referrer['html']);
perch_form('apply');
And in the form template –
<perch:input type="select" options="<perch:forms id="var_referrers" type="hidden" />" allowempty="true" label="Referrer" placeholder="Select one…" id="referrer" required="true" />
I'm passing another variable into the form from the page slug which is correctly outputting as a hidden field. I've also tried using perch_content_custom() to insert the form in the page but the result was the same.
Am I missing something obvious or trying to do this in a way that just won't work?
Thanks
Perch: 3.0.8, PHP: 5.6.30, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id$, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_blog (5.5), perch_forms (1.9)
App runtimes: <?php $apps_list = array( 'perch_blog', 'perch_forms', );
PERCH_LOGINPATH: /manage
PERCH_PATH: /Library/WebServer/Documents/site/publish/manage
PERCH_CORE: /Library/WebServer/Documents/site/publish/manage/core
PERCH_RESFILEPATH: /Library/WebServer/Documents/site/publish/manage/resources
Image manipulation: GD
PHP limits: Max upload 190M, Max POST 200M, Memory: 200M, Total max file upload: 190M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: site.dev
DOCUMENT_ROOT: /Library/WebServer/Documents/site/publish/
REQUEST_URI: /manage/core/settings/diagnostics/
SCRIPT_NAME: /manage/core/settings/diagnostics/index.php
What does the generated HTML look like?
Hi Drew,
That certainly looks valid.
That's what I thought. If I put the pipe-separated options directly into the form template it outputs identical html but the selected option is in the submission.
Just for reference this is the generated html with the options added directly in the form template –
I've resolved it. In the form template I've moved the ID for the field ('referrer') to the start of the input, so –
rather than
Is it therefore important to declare the ID of the input before including a variable?
Ah yes, that would do it. The form handler will actually trip up on your nested tags, but as log as it's got the ID first then it's no big deal.
Great thanks for the clarification Drew.