Jump to content

Prefilling Forms


Accurax

Recommended Posts

Simple question here guys...

I have a form that allows a user to input information about themselves, now the first time they use this form all the firleds will be blank.... but id like them to be able to come back and update the information.

Is there anyway of making the form show the info that is held in the database for a given field?

Thanks chaps
Link to comment
https://forums.phpfreaks.com/topic/33581-prefilling-forms/
Share on other sites

radio:

[code]
<?php function check($a,$b){if($a == $b){echo "checked=\"yes\"";}}?>
eg form:
<input type="radio" name="test" value="a" <?php check("a",$b)?>>

drop down:
<select name="birthday" size="1">
<?php
$bdays = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',);
$bday_select = "";
foreach ($bdays as $bdays)
{$bday_select .= '<option value="' . $bdays . '"';
if ($bdays == $birthday) {$bday_select .= ' selected';}
$bday_select .= '>' . $bdays . '</option>';}
echo"$bday_select";?>
</select>
[/code]

where as $birthday is your stored variable.
Ted

Link to comment
https://forums.phpfreaks.com/topic/33581-prefilling-forms/#findComment-157294
Share on other sites

If this is easier for you to understand:
<?php function check($a,$b){if($a == $b){echo " selected=\"selected\"";}}?>
<select name="test">
<option value="1" <?php check("1",$b)?>>Test1</option>
<option value="2" <?php check("2",$b)?>>Test2</option>
<option value="3" <?php check("3",$b)?>>Test3</option>
<option value="4" <?php check("4",$b)?>>Test4</option>
</select>
Link to comment
https://forums.phpfreaks.com/topic/33581-prefilling-forms/#findComment-157298
Share on other sites

yup... you can do it that way too if you want... but it if you were wanting your page more automated... you'd prolly want somin like this....

[code]
<?
function form_autodropbox($to=array(),$selected="",$name=""){
if(!is_array($to)) return FALSE;
$return .= '<select name="'.$name.'">';
foreach($to as $k => $v){
  if($k==$selected) $return .= '<option selected value="'.$v.'">'.ucwords($k).'</option>';
  else $return .= '<option value="'.$v.'">'.ucwords($k).'</option>';
}
$return .= '</select>';
return $return;
}

$to[test]="asdf";
$to[test2]="asdf";
$to[test3]="asdf";
$to[test4]="asdf";
echo form_autodropbox($to,"test3",'test')
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/33581-prefilling-forms/#findComment-157301
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.