All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Use Low Reorder in database query?

Damien 10 Aug 2012 07:10 question, complete

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

  1. 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:

    <?php 

    $recipients = '';

    {exp:low_reorder:entries set="1"}
    $recipients .= 'recipient{count}="{region}|{email}" ';
    {/exp:low_reorder:entries}

    ?>

    {embed='contact/form' recipients='<?=$recipients?>'}


    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:

    {exp:freeform:form {embed:recipients} recipients="yes"} 
    ...
    {/exp:freeform:form}


    Untested, but this might work and steers away from complicated queries, keeping it more transparent for you.