Re: Fw: Help on Select
| From: | Justin Patrin | Date: | Tue, 26 Oct 2004 20:38:15 +0000 |
| Subject: | Re: Fw: Help on Select | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15137@lists.php.net to get a copy of this message | ||
On Tue, 26 Oct 2004 13:52:42 -0500, pitesaj@peteramayer.com
<pitesaj@peteramayer.com> wrote:
> I apologize in advance for emailing you directly but I have emailed the
> group at least twice with no replies. I see that you answer all questions
> promply and now I wonder if my emails are being received. I will add some
> code below for clairification.
>
Thanks, but I read stuff from the lists. It's always best to post
there. The reason I didn't respond (and probably others) is because we
couldn't understand your question. You need to explain more. You
should have included some code in your first post. I still don't
really understand what you're asking, but I have some comments.
> Using QF with a Select Element (the array is built from a table) and need
> to run addFormRule on the selection but am unable to pull the $value only
> the $key. Can post to table (if I do not use 'function
> process_data($values)') by using
> $service=$service_data[$_POST['service']]. But this does not work in a
> function. Have tried setSelected and getSelected but cannot get syntax
> correct, not even sure if that is correct approach. All examples retrieve
> only the $key.
>
> Any help greatly appreciated.
>
> $sql = "SELECT *
> FROM $table_name
> WHERE empl_id = $empl_id
> ORDER BY empl_serv
> ";
>
> $result = @mysql_query($sql,$connection) or die("Couldn't execute employee
> service query.");
> while ($row = mysql_fetch_array($result)) {
> $service_data[ ] = $row['empl_serv'];
> }
> .
> .
> $select=&$form->addElement('select', 'empl_serv', 'Select
> Function :',
> $service_data, array('size' => 1));
>
> $form->addFormRule('_validate_empl_serv') ;
>
> function _validate_empl_serv($values) {
> $errors = array() ;
> $empl_serv = $_POST['empl_serv'] ; //array would be, for example
> 0 => General Office 1 => Design, etc
*WHY* are you doing this? The posted value is in the $values array, as
it should be: $values['empl_serv']
> echo $empl_serv ; // return '0' , or '1' etc from which I need
> the value of General Office for example
> $empl_serv = $service_data[$_POST['empl_serv']];
> echo $empl_serv; // returns empty string
So you're trying to get the string associated with the index? Why not
make the values of the select the strings instead of the indexes then?
Put this instead of the while loop above.
while ($row = mysql_fetch_array($result)) {
$service_data[$row['empl_serv']] = $row['empl_serv'];
}
> .
> .
> }
>
>
--
paperCrane --Justin Patrin--