This topic is locked

multiple dropdown on single field

12/2/2012 5:03:58 AM
PHPRunner General questions
S
stiven author

Hello,
I am wondering if it is possible to have two dropdown boxes in one single field? e.g. I have a time_in_club field, I would like to have two dropdowns on that field one with 1 year, 2 years, 3 years, etc... and the other dropdown 1 month, 2 months, 3 months, etc... and then when the user saves the record have them both stored in the single field time_in_club as lets say, 1 year 2 months.
I don't know if its possible in phprunner but if it is not, is there any other way to do this? could someone point me in the right direction how to achieve this?
Thanks for your help.

W
wildwally 12/2/2012



Hello,
I am wondering if it is possible to have two dropdown boxes in one single field? e.g. I have a time_in_club field, I would like to have two dropdowns on that field one with 1 year, 2 years, 3 years, etc... and the other dropdown 1 month, 2 months, 3 months, etc... and then when the user saves the record have them both stored in the single field time_in_club as lets say, 1 year 2 months.
I don't know if its possible in phprunner but if it is not, is there any other way to do this? could someone point me in the right direction how to achieve this?
Thanks for your help.


Do you mean two seperate fields side by side? If so, yes it is and there are a few different ways to go about doing this. Not knowing your db structure the simplist way to achieve this in my opinion would be to create two alias from the single field you want them both stored. Name the first aliased field something like 'Years' and the second one 'Months'

From the visual editor drag the field side by side as you want. Now note that you should also go into the html view or do it from the start and cut/copy and paste all the associated code - just dragging and dropping doesn't bring all the other tags PHPRunner uses, such as the DIV's and BEGIN and END tags. From the visual editor you set up your fields and source as you normally would.
Then from the events before recorded added combine the two values and set them to the orginal fields value and be sure to unset the aliased fields.
Like I said before there is a few different ways to go about doing this, if you already have the wtwo fields in the db and you want the data stored where you can search on both then concat the two fields in the list and view pages before display to make it appear as if there is only one field in the db.
Good luck.

S
stiven author 12/2/2012

Thanks so much!
this is exactly what I was looking for I only used one field on the database, but I have one little problem.
I can't separate the field in two pieces to display it on the edit page in the two dropdown boxes here is the code to display it but it's not working the drop down is still set to please select
this code is on the before display events page



$total = $values['years'];// this contains the whole value 1 year 2 months
$arr = explode(" ",$total);

$years = $arr[0]. " " .$arr[1];

$months = $arr[2]." " . $arr[3];

//echo $years . " years ";

//echo $months . " months ";

$values['years'] = $years;

$values['months'] = $months;