Use Low Reorder in database query?
I know this is probably beyond the boundaries of support but hoping for some help all the same. I have a channel with a company's office locations - using low reorder this works fine.
But, using Freeform I a have a drop-down of the offices so users can select the recipient office. I'm currently doing that with the following query that I found on a solspace forum post but I have no idea how I can incorporate a low reorder set to set the display order or if its even possible???
<?php
$recipients = "";
$num = 0;
$query = $this->EE->db->query("SELECT cd.field_id_34 as email,cd.field_id_41 as region, ct.title FROM exp_channel_data as cd INNER JOIN exp_channel_titles as ct ON cd.entry_id = ct.entry_id WHERE cd.channel_id = 10");
foreach($query->result_array() as $row)
{
$recipients .= 'recipient'.++$num.'="'.$row["region"].'|'.$row["email"].'"';
}
echo '{exp:freeform:form
form:id="contactform"
required="recipient_email|name|phone1|email|message|subject"
'.$recipients.'
recipients="yes"
return="thankyou/contact_thanks"
notify="sales@bisley.biz"
template="contactform"
recipient_limit="1"
recipient_template="contactregion"
}';
?>
This then goes into the form like this:
<select name="recipient_email[]" id="recipient_email" tabindex="5" aria-required="true" required />
{recipients}
<option value="{recipient_value}">{recipient_name}</option>
{/recipients}
<option value="{recipient_value1}">All Other Countries</option>
</select>
Any ideas? Sorry, PHP isnt my strong suit.
Replies
Low 10 Aug 2012 08:31
I'd split it in two templates and use an embed in this case. That makes things a bit clearer. In the first template (the main one), enable PHP on Output. Then use the low_reorder:entries tag to get the region/email combinations. Something like this:
Note the use of double and single quotes, that's important. You can change the {region} and {email} vars to whatever you've named them.
Then call an embed which only contains the contact form (the freeform:form tag). No need for PHP in that template. Just use something like this:
Untested, but this might work and steers away from complicated queries, keeping it more transparent for you.