Forums

Can't figure out error.

gunblaze 06 Mar, 2012
Hi, I'm trying to set up a textbox using chronoforms and have default values [vid] in it.

I'm getting the values [aid] from [admins] and [vid] from [vendor] and after that add them to the textbox as default values. I would like to have value later to be inputted into [product_id] of my database.

But, I just can't seem to get it worked out. The values doesn't show but the text box appears. The following is the code.

<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>

<div class="form_item">
  <div class="form_element cf_textbox">

<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
  SELECT aid, vid
    FROM admins, vendor
    WHERE user_id = $user->id
     AND vid = aid;
";
$db->setQuery($query);
$vendorID = $db->loadAssocList(); 
?>

<input type="text" class="cf_inputbox required" name="product_id" id="" value="<?php echo $vendorID->vid; ?>"; />
  </div>
  <div class="cfclear"> </div>
</div>


I'm not sure what has gone wrong. But have been trying for the whole day without much avail.
GreyHead 06 Mar, 2012
Hi gunblaze ,

I think you need to use loadAssoc(), not loadAssocList(). The List version will give you an array of results rather than a single result. It may only be an array with one entry but your PHP for the values won't read it correctly.

Bob
gunblaze 07 Mar, 2012
Hi. Bob, thanks for the reply. I tried the method but it still doesn't work.

Anyways, I set it up so that it shows a selectbox with the value of the user's ID and a textbox by the side for the user to enter their own code. View attachment for clearer view.

The following is the code:

<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <select class="cf_inputbox validate-selection"
        id="" size="1" name="vendorid">
<?php
if (!$mainframe->isSite() ) {return;}
$db =& JFactory::getDBO();
$query = "
  SELECT aid, vid, company
    FROM admins, vendor
    WHERE user_id = $user->id
     AND vid = aid;
";
$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
  echo "<option value='V".$o[vid]."-'>V".$o[vid]."-</option>";
}
?>
    </select>
<input type="text" class="cf_inputbox required" name="product_id" id="" value=""; />
  </div>
  <div class="cfclear"> </div>
</div>


but filling up the form only records the value of the inputted value in the textbox. What i want is for the whole value including the value[ie: V5] in my select box to go into my database column.

Is it possible to be done?
This topic is locked and no more replies can be posted.