Forum

Thread tagged as: Question, Discussion

Passing perch system variable into perch_form template

Is it possible to do this? I was hoping I could use:

PerchSystem::set_var('usage_type', 'test');
<?php perch_form('search_form.html'); ?>

AND in my search_form.html template

<perch:content id="usage_type" />

But I don't get any output. If this isn't possible does anyone have a work around to set a variable in a perch_form template?

Just to add a little more information about what I'm trying to do. I have a number of select boxes which use javascript to show hide other selects based on the selection. When the form is submitted I need to pass in which one is currently in use, else the 'active' select box isn't showing and defaults to hidden.

Jonathan Clift

Jonathan Clift 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_form() won't render any <perch:content /> tags.

What does <perch:showall /> output?

Ah yes, it's showing in there with the correct ID "usage_type" and the correct value but I can't work out how to output it?

ID  Value
perch_page_path /venues/index.php
brochure    /cms/resources/jc-test-pdf.pdf
usage_type  meetings
perch_namespace perch:forms

ah got it, I used


<perch:forms...>

is that stable/ok to use?

Secondly, I'm then trying to use this variable to show/hide the appropriate select boxes so if the variable equals meetings I'm trying to do something like this:

<perch:if id="<perch:forms type="text" id="usage_type"/>" value="meetings">
        <p>Something with meetings</p>
    </perch:if>

Isn't quite right as that is related to 'content' but is something like that possible?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's ok to use.

<perch:if id="usage_type" value="meetings">
...
</perch:if>

Thanks for helping me over the line Drew, much appreciated!