Forum Moderators: coopster
Would there be an easy way to loop through all the fields and write each one in it's respective place, I mean, how can I traverse through the page DOM with php and fill such data?
Best Regards
NooK
The problem is how to put the right data into the right fields without having to do a check in every field for the fieldname and having to hardcode the fieldname in the check.
For example:
<INPUT type="checkbox" name="somename" <?php if("somename" is included in array) echo 'checked'?>>
I am wondering if there is a nicer solution to traverse through certain INPUT fields with a loop, check for their type and do something with them such as checking them or something of the sort.
Best Regards
NooK
[edited by: NooK at 5:07 pm (utc) on Nov. 1, 2007]
// assuming $op is the output from the database
$form = '<form action=".." method="...">';
foreach ($op as $k => $v) {
if (is_string($v) === true) {
// assuming all strings are going to be text inputs
$form = '<input type="text" name="'.$k.'" id="'.$k.'" value="'.$v.'" />';
}
elseif (is_bool($v) === true) {
// something with radio/checkboxes
}
...
You may be able to use a script to do it all for you. It depends on how complex as to how easy that would be.
I am trying to come up with a way to turn it into a script to minimize code and make readability easier but it just does not seem possible.
Thanks for the input.
Best Regards
NooK
pull data from db into vars
echo vars in form elements
if the vars are blank then your element will be blank, no need for an if on every field
for radios, checkboxes and selects you need ifs anyway to make them select the proper one. Again you don't need to check whether they are blank or not, it will default to nothing selected/checked if the values aren't set.