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


Thread tagged as: Question

Using dynamic Perch form id

I am trying to use same perch form in different pages and want their response in different email addresses. So i am trying to use dynamic Id passing through variable in perch template. Please find the below code where perch:content id="site" is passed as in document :- https://docs.grabaperch.com/templates/passing-variables-into-templates/

<perch:form id="<perch:content id="site" type="hidden" encode="false" />_Sales-form" method="post" app="perch_forms" role="form" name="form3_form2_Sales-form">
    <div id="contact">
            <div class="form-group">
                <div class="box">
                    <perch:input name="optionvalue" type="select" options="<perch:content type="text" id="OptionsQuery1" label="Titles (Comma separated values)" />" id="Query1" class="nice-select small"/>
            <!--   select box -->
            <div class="form-group">
                <perch:input type="text" id="name" class="form-control" required="required" placeholder="Name" maxlength="50" autocomplete="off" />
            <div class="form-group myEmailC">
                <perch:input type="email" id="email" class="form-control" required="required" placeholder="Email" maxlength="100" autocomplete="off" />
            <div class="form-group">
                <perch:input type="text" id="Organization" class="form-control" placeholder="Organization" required="required" maxlength="100" autocomplete="off" />
            <div class="form-group">
                <perch:input type="tel" id="Telephone_number" class="form-control" placeholder="Telephone" required="required" maxlength="25" autocomplete="off" />
            <div class="form-group2">
                <perch:input type="textarea" name="message" id="message" required class="form-control myTxtAreHite" rows="8" placeholder="Message" maxlength="1000">
        <div class="form-groupSubmit">
            <perch:input type="submit" id="submit" value="Submit" class="btn btn-primary MYsales-submit-btn center-block" />
            <div id="msg2" class="alert success myMsgRspnsSale"></div>
                <div class="alert success myMsgRspnsSale">
                    <perch:content id="success" type="textarea" label="Post form submit message" html="true" />

But i am getting following error on submitting form please help.

Fatal error occurred Message: Uncaught Error: Call to a member function label() on null in ...\perch\addons\apps\perch_forms\runtime.php:25

Stack trace:

0 ...\perch\core\lib\Perch.class.php(127): perch_forms_form_handler(Object(PerchAPI_SubmittedForm))

1 ...\perch\core\inc\forms.php(9): Perch->dispatch_form('rail-technologi...', Array, Array)

2 ...\perch\core\inc\forms.php(23): perch_find_posted_forms()

3 ...\perch\core\lib\Perch.class.php(228): {closure}(Object(PerchSystemEvent))

4 ...\perch\core\runway\start.php(28): Perch->event('page.loaded')

5 {main} thrown

Neha Tare

Neha Tare 0 points

  • 1 year ago
Drew McLellan

Drew McLellan 2637 points
Perch Support

So i am trying to use dynamic Id passing through variable in perch template.

You cannot do that. Form IDs need to be static.

Thanks Drew McLellan for your reply.

Is there any other way of using same perch form template in different pages and get their response in different email addresses.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

I wonder if you could use template includes so you can reuse the file

So you have a template for each form like so:

<perch:form id="contact_form" method="post" app="perch_forms" role="form">
<perch:template path="content/_form_fields" />

And you'd just change the form ID when creating another form:

<perch:form id="sales_form" method="post" app="perch_forms" role="form">
<perch:template path="content/_form_fields" />

And in _form_fields.html you can have your form input fields.

Though, I think I tried using template includes in a form before and the form didn't pick up the responses even though the tags seemed to render correctly. Drew may be able to confirm whether this approach should work.

Thanks Hussein, But that doesn't solve my problem.

I have one contact page template (One <perch:form>) which is used under different department. Let's say

Department A -> Contact US

Department B -> Contact US

Department C -> Contact Us

Number of department is not fixed. and I think creating different contact form for different department is not possible.

The problem is that I want the response from different contact pages in different contact person.

Department A -> Contact US -> Email to contact person for department A

Department B -> Contact US -> Email to contact person for department B

Department C -> Contact Us -> Email to contact person for department C

Drew McLellan

Drew McLellan 2637 points
Perch Support

The Forms app is just a basic form-to-email example using the API. It doesn't have functionality like that. Someone could build it and even charge money for it, but for some reason no one has.