Ryan R Posted August 18, 2011 Share Posted August 18, 2011 Hi All, I have been looking at the form function php file. There are a few things I don't quite get. It would be appreciated if you can help me understand better. If you look at the input form like below, you will notice the value = $value. echo '<input type="'.$type.'" name="'.$name.'" id="'.$name.'"'; if($value) echo 'value="'.htmlspecialchars($value).'"'; if(!empty($extras)) echo "$extras"; if(array_key_exists($name, $errors)) { echo 'class="error" /><br/><span class="error">'.$errors[$name].'</span>'; }else{ echo '/>'; } However, if you look the select form like below, value = $k instead of value = $value. I was thinking that it was supposed to be like: echo " $value = $k"; echo "<option value=\"$k\"....>" instead of what the example below is showing. Also, One thing I don't get is that if you put condition like: if($value == $k) where is the values of $value? It should have values to compare with $k to know whether it's matching or not. foreach($data as $k => $v) { echo "<option value=\"$k\""; if($value == $k) echo 'selected="selected"'; echo ">$v</option>\n"; }//end of foreach //complete the tag echo '</select>'; Thank you very much for your help. and look forward to hearing from you soon. Link to comment Share on other sites More sharing options...
Larry Posted August 19, 2011 Share Posted August 19, 2011 Well, the goal is, for a previously selected menu option, to create HTML like YY So the first part of code that you highlight in bold creates the first part of that. The $k comes from the appropriate array: states, months, or years. So $k will have a value like 'AL', 'January', or 2011. The next step is to see if the item currently being added to the the menu was previously selected by the user. That's why $k is compared to $value, $value always being the user's selection or entry for the given input. Does that make sense? Link to comment Share on other sites More sharing options...
Ryan R Posted August 22, 2011 Author Share Posted August 22, 2011 Thank, Larry. It was helpful. Link to comment Share on other sites More sharing options...
Recommended Posts