Groan - I am back on this and I
still can't work it out. I must have missed a key something.
I want to set the default <option> in a <select> list.
So:-
<select style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
echo "<option Title='".$aRow->Scientific_Name."' value='$aRow->Scientific_Name'>$aRow->Scientific_Name</option>";
}
?>
</select>
That list is loaded successfully from a database read.
I now want to compare each of those option values with the value passed to the form so that I can set the <option selected> tag. To do that as I have read Bob's explanation I should be able to compare $aRow->Scientific_Name with $form->data['Scientific_Name']. But I cannot get a value in $form->data['Scientific_Name']!
This code produces nowt!
<?php
echo '<h2>Try '.$form->data['DateCollected'].'this</h2>';
?>
The data is there according to the debug control
Data Array:
Array
(
[chronoform] => edStock
[tokenStock] => 2
[Itemid] => 130
[option] => com_chronoforms
[view] => form
[Collection_ID] => 2
[idSpecies] => 4
[DateCollected] => 2010-03-13
[Source] => Collected
[idLocation] => 22
[GPSSouth] => -26.306550
[GPSEast] => 152.855983
[Qty] => 40
[Remaining_Qty] => 0
[Treatment] => Nil
[Comment] => Fruit and seeds mature on tree. Fruit open.
)
Debug Data
db_record_loader
SELECT * FROM `BVu_RV_Stock` AS `BVuRVStock` WHERE `Collection_ID` = '2'
but I can't see $form with dump or print_r.
I just have to be missing a key something.
In desperation I have included the form code.
Help!
Nick😢
<div class="ccms_form_element cfdiv_select" id="species_container_div">
<h1>Hello</h1>
<?php
echo '<h2>Try '.$form->data['DateCollected'].'this</h2>';
?>
<label for="idSpecies">Species</label>
<select style="width:400px;" size="1" label_over="0" hide_label="0" id="idSpecies" class="" title="" type="select" name="idSpecies">
<!--
Code to slect the species and current value from the database
-->
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT `Scientific_Name`,`Common_Name` ".$f."`#__RV_Species` ORDER BY `Scientific_Name` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
echo "<option Title='".$aRow->Scientific_Name."' value='$aRow->Scientific_Name'>$aRow->Scientific_Name</option>";
}
?>
</select>
<h1>Goodbye</h1>
<div class="clear"></div><div id="error-message-idSpecies"></div></div><div class="ccms_form_element cfdiv_datetime" id="date_collected_container_div"><label for="idDateCollected">Date Collected</label><input id="idDateCollected" maxlength="150" size="16" class="cf_date_picker" title="" label_over="0" hide_label="0" type="text" value="" name="DateCollected" />
<div class="clear"></div>
<div id="error-message-DateCollected"></div></div>
<!--
add code here to pick the current radio values form the databse
-->
<div class="ccms_form_element cfdiv_radio" id="source_container_div">
<label for="idSource">Source</label><input type="hidden" name="Source" value="" alt="ghost" />
<input type="radio" name="Source" id="source_no" title="" value="Collected" class="">
<label for="source_no">Collected</label>
<input type="radio" name="Source" id="source_yes" title="" value="Acquired" class="">
<label for="source_yes">Acquired</label>
<div id="error-message-Source"></div></div>
<div class="ccms_form_element cfdiv_select" id="location_container_div">
<label for="idLocation">Location</label>
<select style="width:400px;" size="1" label_over="0" hide_label="0" id="idLocation" class="" title="" type="select" name="Location">
<!--
Code to slect the species and current value from the database
-->
<?php
$db =& JFactory::getDBO();
$f=' FROM ';
$dbQuery ="SELECT * ".$f."`#__RV_lupLocations` ORDER BY `Location` ";
$db->setQuery($dbQuery);
$rows=$db->loadObjectList();
//print_r($rows);
foreach ($rows as $aRow) {
echo "<option value='$aRow->id'>$aRow->Location</option>";
}
?>
</select>
<div class="clear"></div><div id="error-message-Location"></div></div><div class="ccms_form_element cfdiv_text" id="gps_south_container_div"><label for="idGPSSouth">GPS South</label><input id="idGPSSouth" maxlength="10" size="12" class="" title="" label_over="0" hide_label="0" type="text" value="" name="GPSSouth" />
<div class="clear"></div><div id="error-message-GPSSouth"></div></div><div class="ccms_form_element cfdiv_text" id="gps_east_container_div"><label for="idGPSEast">GPS East</label><input id="idGPSEast" maxlength="10" size="20" class="" title="" label_over="0" hide_label="0" type="text" value="" name="GPSEast" />
<div class="clear"></div><div id="error-message-GPSEast"></div></div><div class="ccms_form_element cfdiv_text" id="quantity_container_div"><label for="idGPSEast">Quantity</label><input id="idGPSEast" maxlength="50" size="30" class="" title="" label_over="0" hide_label="0" type="text" value="" name="Qty" />
<div class="clear"></div><div id="error-message-Qty"></div></div><div class="ccms_form_element cfdiv_text" id="remaining_quantity_container_div"><label for="idRemaining_Qty">Remaining Quantity</label><input id="idRemaining_Qty" maxlength="50" size="30" class="" title="" label_over="0" hide_label="0" type="text" value="" name="Remaining_Qty" />
<div class="clear"></div><div id="error-message-Remaining_Qty"></div></div><div class="ccms_form_element cfdiv_textarea" id="treatment_container_div"><label for="idTreatment">Treatment</label><textarea id="idTreatment" cols="40" rows="6" class="" title="" label_over="0" hide_label="0" type="textarea" name="Treatment"></textarea>
<div class="clear"></div><div id="error-message-Treatment"></div></div><div class="ccms_form_element cfdiv_textarea" id="comment_container_div"><label for="idComment">Comment</label><textarea id="idComment" cols="40" rows="6" class="" title="" label_over="0" hide_label="0" type="textarea" name="Comment"></textarea>
<div class="clear"></div><div id="error-message-Comment"></div></div><div class="ccms_form_element cfdiv_submit" id="input_submit_15_container_div"><input name="input_submit_15" class="" value="Submit" type="submit" />
<div class="clear"></div><div id="error-message-input_submit_15"></div></div>