Forum

Thread tagged as: Problem, Forms

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
Gary Hughes

Gary Hughes 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does the generated HTML look like?

Hi Drew,

<form id="apply" action="/careers/post.php?ref=disposals-development-surveyor-disp-apr-17" method="post" enctype="multipart/form-data">

    <fieldset>
    <input id="job_ref" name="job_ref" value="disposals-development-surveyor-disp-apr-17" type="hidden">

    <label for="first_name">First Name</label>
    <input id="first_name" name="first_name" type="text" required="required">


    <label for="last_name">Last Name</label>
    <input id="last_name" name="last_name" type="text" required="required">


    <label for="email">Email Address</label>
    <input id="email" name="email" type="email" required="required">



    <label for="phone">Telephone</label>
    <input id="phone" name="phone" type="text" required="required">

    </fieldset>

    <fieldset>
    <label for="cv">Upload your CV</label>
    <input id="cv" name="cv" accept="pdf office richtext" type="file" required="required">

    <p class="note">Your CV must be a .doc, .pdf, docx or rtf and no bigger that 1MB</p>
    </fieldset>

    <fieldset>
    <label for="letter">Upload your Covering letter</label>
    <input id="letter" name="letter" accept="pdf office richtext" type="file">
    <p class="note">Your CV must be a .doc, .pdf, docx or rtf and no bigger that 1MB</p>

    <label for="referrer">Where did you hear about this position?</label>
    <select id="referrer" name="referrer" placeholder="Select one…" required="required"><option selected="selected" value="">Select one…</option><option value="building">Building</option><option value="construction-news">Construction News</option><option value="estate-gazette">Estate Gazette</option><option value="indeed">Indeed</option><option value="jobs-in-kent">Jobs in Kent</option><option value="kent-county-council">Kent County Council</option><option value="kent-messenger">Kent Messenger</option><option value="property-week">Property Week</option><option value="rics">RICS</option><option value="total-jobs">Total Jobs</option><option value="other">Other</option></select>


    <input id="colour" name="colour" type="text">

    <input id="submit" name="submit" value="Send Application" type="submit"><input type="hidden" name="cms-form" value="YXBwbHk6cGVyY2hfZm9ybXM6L3RlbXBsYXRlcy9mb3Jtcy9hcHBseS5odG1sOjE0OTgwNTgzNjc=">
    </fieldset>


  </form>
Drew McLellan

Drew McLellan 2638 points
Perch Support

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 –

<form id="apply" action="/careers/post.php?ref=disposals-development-surveyor-disp-apr-17" method="post" enctype="multipart/form-data">

    <fieldset>
    <input id="job_ref" name="job_ref" value="disposals-development-surveyor-disp-apr-17" type="hidden">

    <label for="first_name">First Name</label>
    <input id="first_name" name="first_name" type="text" required="required">


    <label for="last_name">Last Name</label>
    <input id="last_name" name="last_name" type="text" required="required">


    <label for="email">Email Address</label>
    <input id="email" name="email" type="email" required="required">



    <label for="phone">Telephone</label>
    <input id="phone" name="phone" type="text" required="required">

    </fieldset>

    <fieldset>
    <label for="cv">Upload your CV</label>
    <input id="cv" name="cv" accept="pdf office richtext" type="file" required="required">

    <p class="note">Your CV must be a .doc, .pdf, docx or rtf and no bigger that 1MB</p>
    </fieldset>

    <fieldset>
    <label for="letter">Upload your Covering letter</label>
    <input id="letter" name="letter" accept="pdf office richtext" type="file">
    <p class="note">Your CV must be a .doc, .pdf, docx or rtf and no bigger that 1MB</p>

    <label for="referrer">Where did you hear about this position?</label>
    <select id="referrer" name="referrer" placeholder="Select one…" required="required"><option selected="selected" value="">Select one…</option><option value="building">Building</option><option value="construction-news">Construction News</option><option value="estate-gazette">Estate Gazette</option><option value="indeed">Indeed</option><option value="jobs-in-kent">Jobs in Kent</option><option value="kent-county-council">Kent County Council</option><option value="kent-messenger">Kent Messenger</option><option value="property-week">Property Week</option><option value="rics">RICS</option><option value="total-jobs">Total Jobs</option><option value="other">Other</option></select>


    <input id="colour" name="colour" type="text">

    <input id="submit" name="submit" value="Send Application" type="submit"><input type="hidden" name="cms-form" value="YXBwbHk6cGVyY2hfZm9ybXM6L3RlbXBsYXRlcy9mb3Jtcy9hcHBseS5odG1sOjE0OTgwNjE0Njc=">
    </fieldset>


  </form>

I've resolved it. In the form template I've moved the ID for the field ('referrer') to the start of the input, so –

<perch:input type="select" id="referrer" options="<perch:forms id="var_referrers" type="hidden" />" allowempty="true" label="Referrer" placeholder="Select one…" required="true" />

rather than

<perch:input type="select" options="<perch:forms id="var_referrers" type="hidden" />" allowempty="true" label="Referrer" placeholder="Select one…" id="referrer" required="true" />

Is it therefore important to declare the ID of the input before including a variable?

Drew McLellan

Drew McLellan 2638 points
Perch Support

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.