tags:

views:

98

answers:

3

how can i create a drop down list with action which allow me link to other page?

i using cakephp to doing a system, which i wanna have a drop down list to let user select. when user selected the value, i wanted to call a function in controller.. izit available that i can using a $form->input to perform this??

how can i call a function in a controller in this situation? can i call a function while user selected a data and i send the data to controller??

any 1 can help? thanks..

A: 

This is solvable on the client with Javascript. PHP isn't directly useful for that, nor is CSS.

wallyk
but my system is using cakephp to build it, everything i get and post is need to get over php code. i am confusing of how the data run around on my cakephp. cause i am still new in cakephp.
vincent low
A: 

You're thinking about the select element

Gab Royer
+2  A: 

As mentioned you will need to do this via javascript. I will give you a quick example and hopefully it will help. The key is the form that the select box is in, that form's action and other inputs will help direct your script. For example:

<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
  <select name="selectbox" size=1 onchange="this.form.submit();">
    <option value="">Please choose your page</option>
    <option value="1">Page option 1</option>
    <option value="2">Page Option 2</option>
  </select>
</form>

In the example above whenever the select box is changed it will call the form submit action, which will submit the form via post to the action, in this case itself. Once the page reloads to your PHP script you can look at the $_POST variable and see which page they choose and then redirect them.

switch( $_POST['selectbox'] ) {
  case 1:
     //Redirect or include page 1
     break;
  case 2:
     //Redirect or include page 2
     break;
}

I hope that helps.

Jimmy
great !!! it's help me alot and get to perform that action.. THANKS !!!
vincent low