Forum

Thread tagged as: Question

Dataselect question.

Afternoon,

Got a quick question.

I'm currently making a holiday cottage website. Each cottage will have a tariff page which will contain a table of weeks and wether they're available or booked. Can I pass just the available dates into a select list on a Perch form on a different page?

I haven't tried anything yet (...being lazy...) but would I need a dataselect to achieve this?

Cheers, John.

John Robinson

John Robinson 7 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

An edit form within Perch, or a public-facing form on your page?

Public facing. I just want the user to be able to provisionally book a cottage that's available.

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you use perch_content_custom() to display the form you can use a <perch:content /> tag within the options attribute of a <perch:input type="select" /> tag.

Great, I'll give that a try. Thanks Drew.

I'm struggling a little trying to get the logic right for the perch_content_custom.

Essentially I've got two fields in the tariff template on a dedicated tariff page. I've got a bit of logic in that template so that if price is left blank it adds booked to a column and turns the table row red.

<perch:content id="date" type="date" label="Date" format="d F Y" native="true" required="true" />
<perch:content id="price" type="text" label="Price" title="true" />

Now I've got this in the booking form template on a dedicated booking form page.

<perch:input type="select" options="<perch:content id="date" type="date" label="Date" format="d F Y" native="true" required="true" />" />

Sorry, I'm just struggling to figure out how to knit the two together with the perch_content_custom. Think I just need a little code example and I'll be away.

Drew McLellan

Drew McLellan 2638 points
Perch Support

The value you return to the options="" attribute needs to be a list of comma delimited options. It doesn't look like that's what you have.

Ah, ok.

It's just a regular date field. Is there another/better way to achieve this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

There are two parts.

  1. Generate the comma-delimited list

  2. Pass it into the template to use in the options attribute.

Which part are you stuck on?

I think if I can generate the comma-delimited list then I'll be ok from there as I've passed variables into forms before, I just can't visualise building the list itself.

Bit of progress. I've got this filtering all the price fields that have content in. Dates that are booked have an empty price field.

<?php $fields = perch_content_custom('Cottage Tariff',  array(
    'page' => '/*',
    'skip-template'=>'true',
    'filter'=>'price',
    'match'=>'neq',
    'value'=>'',
    ));
?>

And I'm passing the variables into the booking form like this

<?php PerchSystem::set_vars($fields);
    perch_content_custom('Booking Form', array(
        'template'=>'booking_form.html'
    )); 
?>

Perch showall is showing that the array has been passed into the booking form.

So I think I now need to create a comma delimited list of the dates from that array to pass into the options field. Just putting the date field in isn't working. Gulp. Any pointers?

<perch:input type="select" id="dateselect" options="<perch:content id="date" type="text" label="Price" title="true" />" required="true" label="Dates required" tabindex="5" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the output from showall?

You need to be passing in a comma delimited string.

There are some flaws in what I'm trying to achieve so I'm going to leave it for the time being and rethink it.

Thanks for your help though Drew. Appreciated, as always.