We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question, Problem, Forms

Perch variable in a form is being 'urlified'

Hi,

I am passing a Course Title into a form as a variable, but on receiving the form submission the Course Title is formatted like a slug, rather than normal text (with capitals and spaces).

eg. Instead of 'Equine Veterinary Course', I get 'equine-veterinary-course'.

I create the variable like this:

$result = perch_content_custom('Courses', array(
      'page'=>'/continued-professional-development/index.php',
      'skip-template'=>true,
      'count'=>1,
      'filter'=>'slug',
      'match'=>'eq',
      'value'=>perch_get('course'),
    ),true);

PerchSystem::set_var('course_title', $result[0]['title']);
perch_form('cpd_booking_form.html'); 
?>

Then call it in the form like this:

<perch:input type="hidden" id="course" label="Course" value="<perch:forms id="course_title" />" />

If I echo $result[0]['title'] on the page, or even in the template, it shows as: 'Equine Veterinary Course' so I'm confident that the variable is set correctly. But on submitting, the hidden input shows like a 'slug'.

Simon Clay

Simon Clay 127 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you view source on the page to see the hidden field, what value does it have?

Simon Clay

Simon Clay 127 points

The result of putting this in my Form template:

<p><perch:forms id="course_title" /></p>
<perch:input type="hidden" id="course" label="Course" value="<perch:forms id="course_title" />" />

is this:

<p>Tissue Repair with Professor Tim Watson</p>
<input id="form1_course" name="course" value="tissue-repair-with-professor-tim-watson" type="hidden" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try adding env-autofill="false" to the perch:input tag. Its name is course so it's auto-filling with the value of course from the URL.

Simon Clay

Simon Clay 127 points

Wow, you're right, even with:

<input id="form1_course" name="course" value="" type="hidden" />

the course url is being pulled in.

So adding env-autofill="false" fixed it.

Thanks Drew.