Forums

select list issue

?
Guest 18 Apr, 2013
hi all,

I have set up a select list as custom code (options are dynamically filled from table) after checking code using a drop down element and checking its code in the code tab.

this one works:
<?php $database =& JFactory::getDBO(); ?>
<select size="1" class=" validate['required']" title="" name="custodian_id">
   <option value="">- Please Select -</option>
   <?php $database->setQuery("SELECT * FROM #__chronoforms_data_custodians ORDER BY `custodian_name`, `country`");
   $custodians = $database->loadObjectList();
   foreach ( $custodians AS $custodian) {
      $option  = $custodian->custodian_name.', '. $custodian->country;
      echo "<option value='" . $custodian->cf_id . "'>" . $option . "</option>";
   } ?>
</select>


this one shows up but does not work properly. if I select the first client in the list I get the 'Pls choose a value' error. only when selecting any other client can I submit.

<?php $database =& JFactory::getDBO(); ?>
<select size="5" class=" validate['required']" title="" name="client_id">
   <?php 
   $user = JFactory::getUser();
   $database->setQuery("SELECT * FROM #__chronoforms_data_clients WHERE `im_uid` =". $user->id ." ORDER BY `client_name`, `country`");
   $clients = $database->loadObjectList();
   foreach ( $clients AS $client) {
      $option  = $client->client_name.', '. $client->country;
      echo "<option value='" . $client->cf_id . "'>" . $option . "</option>";
   } ?>
</select>


do u have any idea whats wrong?

J!2.5.9; CF4.0 RC3.5.2
gabedaly 19 Apr, 2013
Try placing a "Please Select" as the very first option. You can place it in the option list before the dynamic ones. I too don't know why the first option never works when selected.
GreyHead 19 Apr, 2013
Hi GabrielaH,

I suspect that the cf_id for your first record may be 0 and the validation isn't recognising this. What do you actually see in the form HTML in the page source?

Bob
?
Guest 19 Apr, 2013
hi Bob,

thats the html for that field:
<div id="input_id_11_container_div" class="ccms_form_element cfdiv_custom" style="">
<label for="input_id_11"></label>
<select class=" validate['required']" name="client_id" title="" size="5">
    <option value="1">
      Client01, Country01
    </option>
    <option value="8">
      Client03, Country01
    </option>
</select>
<div class="clear"></div><div id="error-message-client_id"></div></div>


logging in as my test user I get this:
<div id="input_id_11_container_div" class="ccms_form_element cfdiv_custom" style="">
<label for="input_id_11"></label>
<select class=" validate['required']" name="client_id" title="" size="5">
    <option value="4">
      Client02, Country01
    </option>
</select>
<div class="clear"></div><div id="error-message-client_id"></div></div>


its the same prob with both users
GreyHead 20 Apr, 2013
Hi GabrielaH,

I'm not sure, that looks OK, I suggest that you do as gabedaly suggests and add a 'Please Check' entry as the first option so that the user has to make a selection.

Bob
This topic is locked and no more replies can be posted.