Forum

Thread tagged as: Question, Problem, Events

Adding a form and passing string to hidden field on events page

Hi,

I have an events detail page that uses the event app. I've customised the html templates to suit my needs but one thing I want to do is include a form template and then pass in the event title as a hidden field of the form. I'm trying to make a sign up form for the event so want to pass it in the submission.

I'm a bit confused on the best way to add the form and the variable as the event.php has an event-detail.html template and I want to pass another template to that page.

Thanks

Andrew Cetnarskyj

Andrew Cetnarskyj 0 points

  • 5 years ago
Simon Clay

Simon Clay 127 points

Hi Andrew, I do a similar thing with a job application form where a hidden field shows the Job ID Number.

I think you can do it by adding the form to your event.html template, like this:

<!--The standard event template-->
<div class="vevent">
    <h2 class="summary"><perch:events id="eventTitle" /></h2>

    <p class="dtstart"><span class="value-title" title="<perch:events id="eventDateTime" format="c" />"><perch:events id="eventDateTime" format="%c" /></span></p>

    <div class="description"><perch:events id="eventDescHTML" type="textarea" textile="true" editor="markitup" encode="false" /></div>

    <p class="category"><perch:events id="category_names" encode="false" /></p>

    <perch:if exists="image">
        <img src="<perch:events id="image" type="image" label="Image" width="640" crop="true" />" alt="<perch:events id="eventTitle" />" />
    </perch:if>
</div>

<!--The form-->
<perch:form id="event_application" method="post" app="perch_forms">

        <!--The hidden field for the Event Title-->
        <perch:input type="hidden" id="ref" label="Event Title" value="<perch:events id="eventTitle" />" />

        <!--The rest of the form-->
        <div>
            <perch:input type="text" id="name" required="true" label="Name" placeholder="First name..." />
            <perch:error for="name" type="required">Please add your name</perch:error>
        </div>

        <div>
            <perch:input type="text" id="surname" required="true" label="Surname" placeholder="Surname..." />
            <perch:error for="surname" type="required">Please add your surname</perch:error>
        </div>

        <div>
            <perch:input type="email" id="email" required="true" label="Email" placeholder="Email..." />
            <perch:error for="email" type="required">Please add your email address</perch:error>
            <perch:error for="email" type="format">Please check your email address</perch:error>
        </div>

        <div>
            <perch:input type="submit" id="apply" value="Submit" />
        </div>

        <perch:success>
            <div class="success-message">
                Thank you, your application has been sent. We will be in touch soon.
            </div>
        </perch:success>

</perch:form>

Simon... Nested tags? I had no idea this worked. :)

I am guessing since the form is processed after the event that's how this works. Cause I know you can't nest content tags. But I have never done this before. Thanks.

Simon Clay

Simon Clay 127 points

Hi Robert, yes, I have it working on one of my sites, though with 'Content' rather than Events:

<perch:input type="hidden" id="ref" value="<perch:content id="job_id" type="text" label="Job Number" required="true" />" />

I guess because the content is declared and saved earlier in the template. when the form is submitted, the label and value show in the email notification and the listing in Forms.

Hi Simon,

Thanks your solution worked.

Simon Clay

Simon Clay 127 points

That's great :)

Sorry to revive an old thread but would one be able to do this with still using two seperate content regions? I have a form that comes out at the bottom of a page where I need to pass in the value of a content id from higher up the page. I'm stumped!