Form custom options not being saved using post method

  • I've got a form which has a select input and the options are set using a separate template and passed into the form by way of PerchSystem::set_vars. This works fine and the options are populated ok and the form is rendering as expected on the page. When the form is submitted the custom options are not being saved using app='perch_forms'. The form is saving and other field values are being captured - just not the options from dynamic content. If I manually add options then it saves the option value.

    I have tried placing the form using perch_content_custom()' and 'perch_form()' but same result either way.

    If I change the form method to 'get' I can see the form fields in the url are showing the correct 'option' values so I know the values are being seen and processed by perch_forms to an extent.

    Anyone encountered this before? Any suggestions?


  • Upon submission, Perch checks the submitted data against the form fields in the form template. Perch does this to validate the form.

    So when you add dynamic fields at runtime (on page load), these dynamic fields are not accessible to Perch for validation. As a result, they are ignored. It doesn't matter what function you use to render the form here.

    What works is having your form and your dynamic options in a content region, and outputting the form with perch_content(). This works because the dynamic options are rendered and cached when you save the region. To elaborate, when you save the content region Perch renders perch:content tags, but does not render the Perch form tags (these are rendered at runtime). So the cached contents of your region should contain your Perch form tags, which Perch can access upon form submission.

  • Thanks hus_hmd for confirming, I understand what you've described and tried the following code, still only part works.

    form added to page using:

    1. <?php perch_content('Request Form'); ?>

    perch content template:

    The form renders and display as expected.

    I can see all the values using <perch:showall />

    When i submit the form using method="get" I see this:


    which, to my mind, proves the values are there and processed by the form.

    But if I use method="post" and view the saved submission in Perch>Forms the selection field isn't there at all. The entry for 'text' text field is there however.

    I have also added a radio button group to test using the same content as the select field. It displays as expected and saves the selection to the form in perch.

    Definitely something not right with the select options.

    Any further thoughts appreciated.

  • I have a form very similar to yours which works fine, the only differences to your select is I have a name attribute on it. I'm also calling perch_content_custom instead of perch_content

    1. <perch:input type="select" id="position" name="position" class="c-select__field" options="<perch:content id="positions" type="text"/>" allowempty/>
  • Adding perch:content within a perch:input can cause problems when Perch parses the tags during validation, so make sure it is the last thing you add and after all other attributes:

    1. <perch:input id="p1Finish" type="select" options="<perch:content id="finishOpt" type="text" label="Options List" />" />

    Plus I wasn't aware you're only dynamically adding values (and not dynamically adding perch:input tags). In this case, perch_content_custom() or perch_form() should also work like Byron Fitzgerald suggested. Though I'm not sure whether the name attribute is required.

  • Thanks for the input, that's helped me find the issue!

    It wasn't the addition of the name property rather the order of the properties I had.

    1. <perch:input type="select" options="<perch:content id="opts" type="text" />" id="p1Finish" />

    but when I changed the position of the id property to before the options property (as you had it in your code) it started saving it!

    1. <perch:input type="select" id="p1Finish" options="<perch:content id="opts" type="text" />" />

    Hard to believe the order should make that difference, it was driving me crazy!

    Yeah I pretty much had it working using perch_content_custom() too so figured it should also work using runtime processing.

    Thanks everyone!