Issue
I am working on redesigning a somewhat poorly designed system and have run across the following issue. I have a time field where the user can select the hour, minute, and time zone for an event. These are done with an HTML select drop down menu with several different options. My predecessor felt it necessary to enable people to select an exact minute whereas in my particular application 15 minute increments will suffice, (not to mention make the list about a million times easier to navigate through for the users).
The issue I have is this, if an event was created to occur at say 1:17 PM previously but 17 is no longer in my minute drop down menu It will display the default --select-- option. But I would prefer that in these cases the 17 appear in the menu and be selected as the default. My issue is I don't know how exactly to check if my minute value already exists in the list, and then add it if it isn't. I suppose I could be creating a PHP array in parallel with my drop down options, but I would prefer to be able to look directly at the list of options and determine if the value is already there, if so move on, if not add it to the end. Is there a way to get this kind of information from an HTML object in PHP?
Solution
No you can't access this information from PHP. Only thing you could do is to buffer the html you are sending and then use DOM to access the drop down. But I suggest you use a php array, just as you mentioned, and create the drop down from it.
$values = array(0,15,30,45);
if(!in_array($values, $minute)) {
$values[] = $minute;
}
// Generate select box..
[...]
Answered By - halfdan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.