ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Populate input checkbox list from entries

May 31, 2012 6:52pm

Subscribe [2]
  • #1 / May 31, 2012 6:52pm

    niallthompson

    17 posts

    Hello,

    I am trying to populate a unique list of input type=“checkbox” on a form from a custom field from channel entries.

    They should return a list of {town}.

    I am currently using a SQL query but with no luck.

    Any advice?

    {exp:email:contact_form user_recipients="no" recipients="[email protected]" charset="utf-8" channel="lettings|sales"}
            <h2>Tenant Registration Form</h2>
    <p>        <br />
                    <label for="name">Your Name:</label></p>
    
    <p>                <input type="text" id="name" name="name" size="40" maxlength="35" value="" required autofocus="autofocus" autocomplete="yes" /><br />
            </p>
    
    <p>        <br />
                    <label for="from">Your Email:</label></p>
    
    <p>                <input type="email" id="from" name="from" size="40" maxlength="35" value="" required autocomplete="yes" /><br />
            <br />
            <br />
                    <label for="from">Your Contact Number:</label></p>
    
    <p>                <input type="tel" id="number" name="number" size="40" maxlength="35" value="" autocomplete="yes" /><br />
            <br />
            <br />
                      <br />
              <label for="bedrooms">Bedrooms:</label><br />
              <input id="bedrooms-lettings" name="bedrooms" type="number" class="input-small" min="1" max="9" pattern="[0-9]*"><br />
              <br />
               <br />
              <label for="locations">Locations</label><br />
              {exp:query<br />
           backspace="0"<br />
           sql="<br />
              SELECT DISTINCT<br />
                 d.field_id_3 AS town<br />
                FROM<br />
                 exp_channel_data d,<br />
                 exp_channel_titles t,<br />
                 exp_channels c<br />
                WHERE<br />
                 c.channel_name IN ('lettings', 'sales')<br />
                 AND<br />
                 c.channel_id = t.channel_id<br />
                 AND<br />
                 t.entry_id = d.entry_id<br />
                 AND<br />
                 t.status != 'closed'<br />
                 AND<br />
                 d.field_id_3 != ''<br />
                 ORDER BY town ASC<br />
                 "}<input type="checkbox" id="locations" name="location[]" value="{town}">{town}{/exp:query}<br />
               <br />
              <br />
     <br />
            <br />
              <br />
            <br />
                    <input name="submit" type='submit' value='Submit Form' class="btn" /><br />
            <br />
    {/exp:email:contact_form}

     

  • #2 / Jun 04, 2012 10:33pm

    eevolution

    30 posts

    Consider using exp:channel:entries even on an embed if necessary and then the appropriate {if cond1 = val2}checked{/if} inside the input HTML code. In SQL it would be “CASE WHEN cond1=val2 THEN ‘checked’ END AS checked” ... and put {checked} inside the input HTML

    Tim
    http://www.eevolution.co.uk

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases