multiple select values not appearing

Minnie Mouse 15 Feb, 2008
hi, i have searched and read through the checkbox examples in the forum and i am confused.

i am using the Joomla 1.5 version of chronoforms and i want to retrieve multiple values from a select form. it only returns the last value.

the examples look like they are older versions of chronoforms...

can someone point me in the right direction for getting this done on this recent version??

thanks, MM
GreyHead 15 Feb, 2008
Hi MM,

You must use an array name for the form like
name="select[]";
that should pick them all up OK. Otherwise you only get one value returned. (The same is true of grouped checkboxes)

Bob
Minnie Mouse 15 Feb, 2008
bob i did that. i have a field examtype and i called it in the form like this
<label for="select">Which Exam</label>
    <select name="examtype[]" size="3" multiple="multiple" id="select">
      <option value="homeopathy">Homeopathy (all)</option>
      <option value="human health services">Human Health Services</option>
      <option value="case analysis">Case Analysis Exam</option>
    </select>
i have this form posting to a second form, where i have this to capture the data:
<p>I am applying for the following exams: 
<?php echo $_POST['examtype[]']; ?>
<input type="hidden" name="examtype[]" value="<?php echo $_POST['examtype[]']; ?>">
</p>
this second form is the one that sends the email, first displaying the data to confirm to the user.

on the second form page nothing appears.

thanks for your help!!!

Edited to add code tags
GreyHead 15 Feb, 2008
Hi MM,

You need some slightly different code to unpack the select result.

If you turn Debug on and submit the first form you'll see that the $_POST results include something like this

[examtype] => Array ( [0] => homeopathy [1] => case analysis )

where the entries in the array are the values selected. To display them you need something like
<p>I am applying for the following exams: 
<?php
foreach ( $_POST['examtype'] as $exam ) {
  echo "$exam ";
}
?>
</p>
<input type="hidden" name="examtype" value="<?php echo $_POST['examtype']; ?>">
I'm not certain that the hidden field will pick up the array like this. If not then a second foreach will do the trick.

Bob

PS Second thoughts, in this particular case implode would do the trick (the foreach is a better general example though).
<p>I am applying for the following exams: 
<?php echo implode(", ", $_POST['examtype']; ?>.</p>
 . . .
Minnie Mouse 16 Feb, 2008
bob, thanks that worked fantastically!
here is the code for the second form in case anyone else is following this:
<p>I am applying for the following exams:
<?php
foreach ( $_POST['examtype'] as $exam ) {
  echo "$exam ";
}
?>
</p>
<input type="hidden" name="examtype" 
value="<?php
foreach ( $_POST['examtype'] as $exam ) {
  echo "$exam ";
}
?>
"></p>
this is with basic formatting. a result then appears like this:

human health services case analysis

thanks! MM
jfreak 23 Feb, 2008
Thx, greyhead, it's working right now.
OCS 26 Mar, 2008
Would it be possible to write this variable with all the arrays in a column in database? Some processing in the autogenerated code?
GreyHead 26 Mar, 2008
Hi OCS,

Sorry, I don't understand your question, please can you give a more specific example.

Bob
OCS 26 Mar, 2008
I have a select box in which you can select multiple values. Now I want to write those values in the database in a dedicated field.

How do I pass the array into string and write it into the database?
The string should be like "value1 value2 value3 value4".
I presume there has to be some processing with $_POST['ala'] -variable in autogenerated code before it writes to database. "ala" is my form array.
GreyHead 26 Mar, 2008
Hi OCS,

Sure. Put
$_POST['field_name'] = implode(" ", $_POST['field_name']);
just after the global $database; line.

Bob
OCS 26 Mar, 2008
Thanks! It works well.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger