Jump to content
Larry Ullman's Book Forums

Form_Functions.Inc.Php


Recommended Posts

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

Well, the goal is, for a previously selected menu option, to create HTML like

 

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

 Share

×
×
  • Create New...