Forum

Thread tagged as: Events, Forms

Populate Form Select Box with Events Title

Hey Guys

I am wanting to get pass my event title from an events template called event-data.html into my form template to use as select boxes. I can get a title to display on my page but I can't work out how to set the title as a variable to pass into the form template.

There might be a better way to do this...

Thanks

<?php 

$opts = array(
    'filter'=>'eventTitle',
    'match'=>'eq',
    'template'=>'events/listing/event-data.html',
    'count'=> '1' 
);                              

$eventData = perch_events_custom($opts);

perchSystem::set_var('event1', $eventData);

perch_content_custom('Form', array(
    'template'=>'form.html'
));
?>
Kel Nathan

Kel Nathan 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

A filter doesn't do what you think it does. It filters the region by the given field. It doesn't reduce it to the given filed.

I think you want this;

<?php                   

$eventData = perch_events_custom(array(
    'skip-template' => true,
    'count' =>  1, 
));

PerchSystem::set_vars('event1', $eventData[0]);

perch_content_custom('Form', array(
    'template'=>'form.html'
));

?>

Hi Drew

Thanks for the reply. Nothing is displaying with that code you gave me. Not sure why?

However I have got exactly what I want to pass to the form displaying on my page using the below code, my question is why can't I declare perch_events_custom as a variable? Currently it's just displaying the output above the form but will not pass into the form itself using perchSystem::set_vars

Thanks


<?php $opts = array( 'template'=>'events/listing/event-data.html', 'count'=> '1' ); $eventData = perch_events_custom($opts); perchSystem::set_var('event1', $eventData); perch_content_custom('Form', array( 'template'=>'form.html' )); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does the code I gave you output? You need to use skip-template as shown.

It didn't output anything at all. What do I need to change?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Change:

PerchSystem::set_vars('event1', $eventData[0]);

to:

PerchSystem::set_vars($eventData[0]);

I'm still not getting anything to output at all. Any other ideas?


$eventData = perch_events_custom(array( 'skip-template' => true, 'count' => 1, )); PerchSystem::set_vars($eventData[0]); perch_content_custom('Form', array( 'template'=>'form.html' ));
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's in your form template?


<perch:form id="Application Form" method="post" app="perch_forms"> <perch:content id="intro" type="textarea" label="Intro" textile="true" editor="markitup" size="m" /> <div class="g-cols"> <div class="one-quarter" style="color: #ffffff;">.</div> <div class="one-half"> <div class="g-cols"> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">First Name *</perch:label></div> <perch:input type="text" id="f-name" required="true" label="First Name" /> <span class="error"><perch:error for="f-name" type="required">*Please add your first name*</perch:error></span> </div> </div> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Last Name *</perch:label></div> <perch:input type="text" id="l-name" required="true" label="Last Name" /> <span class="error"><perch:error for="l-name" type="required">*Please add your last name*</perch:error></span> </div> </div> </div> <div class="g-cols"> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Address *</perch:label></div> <perch:input type="text" id="address" required="true" label="Address" /> <span class="error"><perch:error for="address" type="required">**Please add your address*</perch:error></span> </div> </div> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Suburb *</perch:label></div> <perch:input type="text" id="suburb" required="true" label="Suburb" /> <span class="error"><perch:error for="suburb" type="required">*Please add your suburb*</perch:error></span> </div> </div> </div> <div class="g-cols"> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Post Code *</perch:label></div> <perch:input type="text" id="postcode" required="true" label="Post Code" /> <span class="error"><perch:error for="postcode" type="required">*Please add your Post Code*</perch:error></span> </div> </div> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Home Phone</perch:label></div> <perch:input type="text" id="phone" required="false" label="Home Phone" /> </div> </div> </div> <div class="g-cols"> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Mobile *</perch:label></div> <perch:input type="text" id="mobile" required="true" label="Mobile" /> <span class="error"><perch:error for="mobile" type="required">*Please add your Mobile*</perch:error></span> </div> </div> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="email">Email *</perch:label></div> <perch:input type="email" id="email" required="true" label="Email" placeholder="you@company.com" /> <span class="error"><perch:error for="email" type="required">*Please add your email address*</perch:error></span> <span class="error"><perch:error for="email" type="format">*Please check your email address*</perch:error></span> </div> </div> </div> <div class="g-cols"> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Event Date *</perch:label></div> <perch:input type="select" id="event" label="Event" required="true" options="red,green,blue" /> <span class="error"><perch:error for="event" type="required">*Please Choose your Event Date*</perch:error></span> </div> </div> <div class="one-half"> <div> <div class="g-form-row-label"><perch:label for="name">Approx. Range of Sizes *</perch:label></div> <perch:input type="select" id="sizes" label="Sizes" required="true" options="red,green,blue" /> <span class="error"><perch:error for="sizes" type="required">*Please Choose sizes*</perch:error></span> </div> </div> </div> <div> <div class="g-form-row-label" style="padding-top: 5px;padding-bottom: 7px;line-height: 16px;"><perch:label for="message">Brief description of items for sale eg: clothes, shoes, handbags, accessories (including styles,brands and era) * </perch:label></div> <perch:input type="textarea" id="message" required="true" label="Description" /> <span class="error"><perch:error for="message" type="required">*Please add a description*</perch:error></span> </div> <div class="g-form-row-label"><perch:label for="name">Images</perch:label></div> <div class="g-cols"> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" required="true" id="image1" /> <span class="error"><perch:error for="image1" type="required">*Please add at least 1 image*</perch:error></span> </div> </div> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" id="image2" /> </div> </div> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" id="image3" /> </div> </div> </div> <div class="g-cols" id="image-pad"> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" id="image4" /> </div> </div> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" id="image5" /> </div> </div> <div class="one-third"> <div style="font-size: 12px;"> <perch:input type="image" id="image6" /> </div> </div> </div> <div style="float: left;padding-top: 19px;"><perch:input type="checkbox" id="agree" value="true" required="true" /> </div> <div class="g-form-row-label" style="float: left;padding-top: 10px;margin-left: 10px;"><perch:label for="email">I agree to the attached <a target="_blank" href="<perch:content id="terms" type="file" label="Terms & Conditions" /> ">Terms & Conditions</a></perch:label><span class="error"><perch:error for="agree" type="required"> *Please agree to the terms*</perch:error></span></div> </div> </div> <div style="text-align: center; padding-top: 30px;"> <perch:content id="event1" /> <perch:input type="submit" id="submit" value="Submit" /> </div> <perch:success> <perch:content id="success" type="textarea" label="Thank you message" textile="true" editor="markitup" /> </perch:success> </perch:form>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which of those IDs comes from the event? I'd thought you wanted eventTitle but that's not in use in your template.

Well I was trying to bring it in using <perch:content id="event1" /> which is just above the submit input. I just put it there to test getting the variable to come into the form.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to use the IDs from the event template.

Ok I've tried that and still nothing is outputting.

In the template:


<perch:events id="eventTitle" />

On the page:


<?php $eventData = perch_events_custom(array( 'skip-template' => true, 'count' => 1, )); PerchSystem::set_vars($eventData[0]); perch_content_custom('Form', array( 'template'=>'form.html' )); ?>

Ok I put up a <perch:showall /> and the event is showing up there. How do I get it to show within the form?

Thanks Drew. That's now working.

Is there an easy enough way that I can then populate the select boxes with multiple eventTitles? So a user can select one event out of all events?

Any thoughts on how I can get all of the Event Titles into my Select boxes?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's a content region, not an events region at this point. Change:

<perch:events id="eventTitle" />

to

<perch:content id="eventTitle" />

I have the region showing now. What I want to know is how can I output multiple eventTitle's into my form select box?

Obviously there will be a clash of ID's in the form template. Can I set each individual eventTitle as a variable before it goes to the form template or is there a better way to achieve this? I know the client will only ever have a max of 15 events at one time.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'll need to loop through the events and construct a comma-delimited options string to use for the select options

<perch:input type="select" options="<perch:content id="your_options_string" />" />

Ok thanks for that. Are there any previous posts or examples somewhere of how to go about that?

Drew McLellan

Drew McLellan 2638 points
Perch Support

We don't have any previous examples - this isn't something anyone's asked before.