Forums

How to store a selected field in a record

cobayecrau 05 Feb, 2009
I built a form with some some text fields and drop down boxes populated via a MySQL request.
I fill my textfields and I select my fields from the listbox, nice
but when I have a look at the records within the chronoforms_form_xxxx table I only find the text fields. The selected fields coming from the dropdown list are not present

With that I retrieve something within the right field of the record

<DIV class=form_item   >
<DIV class="form_element cf_textbox" >
<LABEL class=cf_label >Palanquée n° :</LABEL>
<INPUT class="cf_inputbox required validate-digits" id=text_5  maxLength=2 size=2 name=text_5 >
<A class=tooltiplink onclick="return false;"  ><IMG class=tooltipimg  height=16 src="components/com_chronocontact/css/images/tooltip.png" width=16 border=0 ></A>
<DIV class=tooltipdiv  >Palanquée n° : :: Numéro d'ordre de la palanquée</DIV>
</DIV>
<DIV class=clear > </DIV></DIV>


And with that the select field of the record is empty
DIV class=form_item   >
<DIV class="form_element cf_dropdown" >
<LABEL class=cf_label >Sélectionner le guide :</LABEL>
<?php
    $db =& JFactory::getDBO();
    $query = " SELECT name
FROM jos_users
INNER JOIN jos_comprofiler ON ( jos_users.id = jos_comprofiler.id ) 
WHERE (
cb_niveauencadrement <> ' '
)
OR (
cb_niveauplongeur = 'Niveau 4'
) ";
    $db->setQuery($query);
    $rows = $db->loadResultArray();
    ?>
    
    <SELECT class="cf_inputbox validate-selection" id=select_5 size=3 name=select_5 >
    <?php
    foreach ($rows as $current) {
      echo "<option value='$row'>$current</option>";
    }
    ?>
    </select>
<A class=tooltiplink onclick="return false;"  ><IMG class=tooltipimg  height=16 src="components/com_chronocontact/css/images/tooltip.png" width=16 border=0 ></A>
<DIV class=tooltipdiv  >Sélectionner le guide : :: Guide ou moniteur</DIV>
</DIV>
<DIV class=clear > </DIV></DIV>


and here the print of the record

cf_id uid recordtime ipaddress cf_user_id text_5 text_8 text_9 text_10 text_11 select_3 select_4 select_5 select_6 text_12
2 IOTJjYWQ4ZTA1Y2E3 2009-02-05 - 15:05:52 127.0.0.1 0 A 10:10 11:11 5 0 xcvxvwxvxcxcvwxcvv


I'm lost
GreyHead 05 Feb, 2009
Hi cobayecrau,

It won't surprise you that I don't think $row has a value. If so, then option doesn't have a value, and there will be nothing in the $_POST array and nothing to save in the database.

Bob
cobayecrau 05 Feb, 2009
Yes, you were right, it's OK by now.

Two questions remain :
1) The dropdown box shows the field you write in loadresultArray () ie loadresultArray(4) (starting from zero), it's OK but I need to store the id of the record, how can I do that ?

2) I have a dropdown bix with multiple field to select how to store them, I tried to declare an array but... this is my code and I can't store anything, select_6[] is not a good choice


<DIV class=form_item   >
<DIV class="form_element cf_dropdown" >
<LABEL class=cf_label >Sélectionner les plongeurs</LABEL>
<?php
    $db =& JFactory::getDBO();
    $query = "
      SELECT id, name
        FROM #__users ";
    $db->setQuery($query);
    $rows = $db->loadResultArray(1);
    ?>
    
    <SELECT class="cf_inputbox validate-selection" id=select_6 multiple size=4 name=select_6[]  >
    <?php
    foreach ($rows as $row) {
      echo "<option value='$row' >$row</option>";
    }
    ?>
    </select>
<A class=tooltiplink onclick="return false;"  ><IMG class=tooltipimg  height=16 src="components/com_chronocontact/css/images/tooltip.png" width=16 border=0 ></A>
<DIV class=tooltipdiv  >Sélectionner les plongeurs :: Sélectionner au plus 4 plongeurs utilisez les touches <CTRL><C></DIV></DIV>
<DIV class=clear > </DIV></DIV>
GreyHead 05 Feb, 2009
Hi cobayecrau,

You are now using more than one field from the table so loadResultArray() will no longer work. Here's your code cleaned up a bit:
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT id, name
    FROM #__users ";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
<div class='form_item' >
  <div class="form_element cf_dropdown" >
    <label class='cf_label' >Sélectionner les plongeurs</label>
    <select class="cf_inputbox validate-selection" id='select_6' multiple='multiple' size='4' name='select_6[]'  >
<?php
    foreach ( $rows as $row ) {
      echo "<option value='$row['id']' >$row['name']</option>";
    }
?>
    </select>
    <a class='tooltiplink' onclick="return false;"  >
      <img class='tooltipimg'  height='16' src="components/com_chronocontact/css/images/tooltip.png" width='16' border='0' >
    </a>
    <div class='tooltipdiv' >Sélectionner les plongeurs :: Sélectionner au plus 4 plongeurs utilisez les touches <CTRL><C></div>
  </div>
  <div class='clear' > </div>
</div>
This should show the names of the divers in the select box but will return an array of ids.

Bob
cobayecrau 06 Feb, 2009
Hello,
You're great, thanks a lot.

I tried your code and I get this error
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in F:\xampp\htdocs\cap2009\components\com_chronocontact\chronocontact.html.php(320) : eval()'d code on line 15

I have checked everything, tired many matches with ' " and so on, I can't escape the typos
GreyHead 06 Feb, 2009
Hi cobayecrau,

Oops, I think that this line
echo "<option value='$row['id']' >$row['name']</option>";
should be
echo "<option value='".$row['id']."' >".$row['name']."</option>";
(You can stay in the "..." quotes to do simple variables but you have to come out to do array or object variables or more complex PHP expressions [color=#000080]". . . .".[some expression." . . ."[/color]

Bob
cobayecrau 06 Feb, 2009
Hello,
It's better by the way I have no more parsing error but the dropdown list is empty.
GreyHead 06 Feb, 2009
Hi cobayecrau,

Ahhh - I'm cracking up - must be Friday :-(

I changed to loadObjectList then tried to access the results as arrays instead of objects. Try
echo "<option value='".$row->id."' >".$row->name."</option>";

Bob
cobayecrau 06 Feb, 2009
It's friday for everybody, but the WE is very close :wink: .
With this code the dropdown is well filled with the names but I store nothing in the database nor id nor name.
May be I have to declare in the table an area where to receive the data ? I have kept the default field defined varchar (255)

<?php
$db =& JFactory::getDBO();
$query = "
  SELECT id, name
    FROM #__users ";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
<div class='form_item' >
  <div class="form_element cf_dropdown" >
    <label class='cf_label' >Sélectionner les plongeurs</label>
    <select class="cf_inputbox validate-selection" id='select_6' multiple='multiple' size='4' name=select_6[]  >
<?php
    foreach ( $rows as $row )
 {
     echo "<option value='".$row->id."' >".$row->name."</option>";}
?>
    </select>
    <a class='tooltiplink' onclick="return false;"  >
      <img class='tooltipimg'  height='16' src="components/com_chronocontact/css/images/tooltip.png" width='16' border='0' >
    </a>
    <div class='tooltipdiv' >Sélectionner les plongeurs :: Sélectionner au plus 4 plongeurs utilisez les touches <CTRL><C></div>
  </div>
  <div class='clear' > </div>
</div>
GreyHead 06 Feb, 2009
Hi cobayecrau,

If you turn DeBug on in the General Tab and submit the form you should see what is being returned in the $_POST array - something like . . . select_6 => array(0=>2, 1=>3 . . . ) . . .

Let's make sure that is OK

Bob
cobayecrau 06 Feb, 2009
oops, never forget the debug mode, it's really friday
Here is what I have in _POST
_POST: Array ( [select_3] => Evt1 [select_4] => DEMOSEPT [text_5] => [select_6] => Array ( [0] => 64 [1] => 65 [2] => 66 ) [text_8] => [text_9] => [text_10] => [text_11] => [text_12] => [0847aa55e4acc33696935cec96a5a723] => 1 )

It seems to be filled with the id values selected
GreyHead 06 Feb, 2009
Hi cobayecrau,

If you have a table column called 'select_6' AND you have set 'Let ChronoForms handle arrays for you' to ON in the AutoGenerated Tab this should save a comma separated list to the database. I'm not sure that it will automatically work in the email though - and you probably want a list of names there. I'd probably create that with a second db lookup in the OnSubmit code and drop the result into the email with a search and replace.

Bob
cobayecrau 06 Feb, 2009
For the moment I don't want to send emails, just want to store data in the column table select_6.
I tried both
ChronoForms handle my posted arrays: YES or NO with the same resultless
Max_admin 06 Feb, 2009
Hi, this is unfortunately a known bug, you need to put this in your onSubmit Before email code box :

<?php
JRequest::setVar('select_6', implode(", ", JRequest::getVar('select_6')));
?>


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
cobayecrau 06 Feb, 2009
Yes it works !!!!!

Other question, somewhere else in my form I have the following
<DIV class=form_item   >
<DIV class="form_element cf_dropdown" >
<LABEL class=cf_label >Sélectionner le guide :</LABEL>
<?php
    $db =& JFactory::getDBO();
    $query = " SELECT * FROM #__users
          INNER JOIN #__comprofiler ON ( #__users.id = #__comprofiler.id ) 
WHERE (cb_niveauencadrement <> ' ')
OR    (cb_niveauplongeur = 'Niveau 4') ";
    $db->setQuery($query);
     $rows = $db->loadObjectList();

    ?>
    
    <SELECT class="cf_inputbox validate-selection" id=select_5 size=3 name=select_5 >
    <?php
    foreach ($rows as $row) {
echo "<option value='".$row->id."' >".$row->.name."</option>"; 
    }
    ?>
    </select>
<A class=tooltiplink onclick="return false;"  ><IMG class=tooltipimg  height=16 src="components/com_chronocontact/css/images/tooltip.png" width=16 border=0 ></A>
<DIV class=tooltipdiv  >Sélectionner le guide : :: Guide ou moniteur</DIV>
</DIV>
<DIV class=clear > </DIV></DIV>


It's a jointure between jos_users and jos_comprofiler, I' m surprised to have this error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in F:\xampp\htdocs\cap2009\components\com_chronocontact\chronocontact.html.php(320) : eval()'d code on line 18

I think I have to qualify id and name with a prefix jos_users but how to ?
GreyHead 06 Feb, 2009
Hi cobayecrau,

Try:
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT * 
    FROM ".$db->nameQuote('#__users')." a
    INNER JOIN ".$db->nameQuote('#__comprofiler')." b
      ON ( a.id = b.id )
    WHERE ( b.cb_niveauencadrement != '' )
      OR ( b.cb_niveauplongeur = 'Niveau 4' );";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>

Bob
cobayecrau 06 Feb, 2009
The way you manage the SQL request becomes too tricky form me
but nothing changes

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `'{'' or `'$'' in F:\xampp\htdocs\cap2009\components\com_chronocontact\chronocontact.html.php(320) : eval()'d code on line 20



<DIV class=form_item   >
<DIV class="form_element cf_dropdown" >
<LABEL class=cf_label >Sélectionner le guide :</LABEL>
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT * 
    FROM ".$db->nameQuote('#__users')." a
    INNER JOIN ".$db->nameQuote('#__comprofiler')." b
      ON ( a.id = b.id )
    WHERE ( b.cb_niveauencadrement != '' )
      OR ( b.cb_niveauplongeur = 'Niveau 4' );";
$db->setQuery($query);
$rows = $db->loadObjectList();
?>
    
    <SELECT class="cf_inputbox validate-selection" id=select_5 size=3 name=select_5 >
    <?php
    foreach ($rows as $row) {
echo "<option value='".$row->id."' >".$row->.name."</option>"; 
    }
    ?>
    </select>
<A class=tooltiplink onclick="return false;"  ><IMG class=tooltipimg  height=16 src="components/com_chronocontact/css/images/tooltip.png" width=16 border=0 ></A>
<DIV class=tooltipdiv  >Sélectionner le guide : :: Guide ou moniteur</DIV>
</DIV>
<DIV class=clear > </DIV></DIV>
GreyHead 06 Feb, 2009
Hi

Row 20 is something different - a stray '.' in this line
echo "<option value='".$row->id."' >".$row->.name."</option>"; 
should be
echo "<option value='".$row->id."' >".$row->name."</option>"; 

Bob
cobayecrau 06 Feb, 2009
Thanks really a lot.
You're very helpful and you are improving my PhP level and my english level as well.

I start an other topic.....
This topic is locked and no more replies can be posted.