Jump to content

looping though dropdown list array problem


helloise

Recommended Posts

how come the lines:PHP Code: echo $form['catcher_id']; $catcher_names = $form['catcher_id'] foreach($catcher_names as $val) { echo "testing loop"; } produce nothing?? its not doing the foreach.$form['catcher_id']; is a dropdown list containing catcher namesplease help?thanks

Link to comment
Share on other sites

where are $form['ctacher_id'] is coming? is it your complete code?..if possible show us the html code too

Link to comment
Share on other sites

most likely it doesn't work because you are assuming something of which you aren't testing for. My guess is you don't understand how the form is submitting to your script. If it's the value of a drop down dropdown menu you want, then only the item selected's value will be present in whichever array you are using as the method of your form (GET or POST).If things aren't working, the best way to figure out it to debug. When dealing with forms, the easiest way to check is to put this at the top of your script.

echo var_dump($_GET);

or

echo var_dump($_POST);

depending on the HTML form's method. That should show you exactly what is being sent to the script file and from there you can evaluate better what is or isn't happening.

Link to comment
Share on other sites

var_dump does not return anything..it show up the data itself
var_dump($_GET);

Link to comment
Share on other sites

thank you everybody...the line:echo $form['catcher_id']; //this line produces a dropdown listgets defined in a base class:abstract class BaseLpmServiceForm extends BaseFormPropel{ public function setup() { $this->setWidgets(array( 'id' => new sfWidgetFormInputHidden(), 'name' => new sfWidgetFormInputText(), 'wap_home' => new sfWidgetFormInputText(), 'call_center_number' => new sfWidgetFormInputText(), 'catcher_id' => new sfWidgetFormPropelChoice(array('model' => 'LpmCatcher', 'add_empty' => false)), 'price_description' => new sfWidgetFormInputText(), 'logo' => new sfWidgetFormInputText(), 'invalid_msisdn_text' => new sfWidgetFormInputText(), 'terms_and_conditions' => new sfWidgetFormInputText(), 'service_code' => new sfWidgetFormInputText(), ));and my form is a "post":<form action="<?php echo url_for('adminservice/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>sorry for the trouble but i have just started to learn all thisall i want is that if the user selects another item in the dropdown list i want to be able to display the newley selected item and do a few other minor things...thanks

Link to comment
Share on other sites

i added the following line: echo var_dump($_POST($form['catcher_id']));and get error:Fatal error: Function name must be a string in /home/helloises/svn_wappool/apps/lpmanager/modules/adminservice/templates/_form.php on line 78i also tried: print_r(explode(' ',$form['catcher_id']); and got the whole arrayso how do i access these values now???yikes i dont know any more...please help?thanks

Link to comment
Share on other sites

i added the following line: echo var_dump($_POST($form['catcher_id']));and get error:Fatal error: Function name must be a string in /home/helloises/svn_wappool/apps/lpmanager/modules/adminservice/templates/_form.php on line 78i also tried: print_r(explode(' ',$form['catcher_id']); and got the whole arrayso how do i access these values now???yikes i dont know any more...please help?thanks
i was assuming that you were getting your values via POST, that's why your first echo didn't work.you could have just done
echo var_dump($form['catcher_id']);

can you show us the output of

 print_r(explode(' ',$form['catcher_id']);

have you read about how to traverse arrays and objects in PHP?

Link to comment
Share on other sites

i was assuming that you were getting your values via POST, that's why your first echo didn't work.you could have just done
echo var_dump($form['catcher_id']);

can you show us the output of

 print_r(explode(' ',$form['catcher_id']);

have you read about how to traverse arrays and objects in PHP?

i can loop through it thanks... but it is not picking up the if for when i select "zed-catcher" from the dropdown...from what i know i have to refresh the page with the newley selected value and the check it against the if...and how to go about this i need to use AJAX :):):) i am reading up on it cos i am newbie at all of this...anybody to help me start on this/point me in the right direction/ explain what needs to be done please???many thanks!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...