Hey there guys,
I'm having bit of trouble getting a solution to my problem.
So I am going to have user profiles that they can edit themselves. So there are forms that will be editable lets say name and location.
This is for a client, and he wants to be able to change the information in the profiles by adding a new form like lets say age.
So now if the user edits his profile there is an age text field he can edit as well.
So how can I be able to add and remove forms that appear in the users profile dynamically?
Thanks so much!
PHP Dynamic form generation
Moderator: General Moderators
Re: PHP Dynamic form generation
You would run this page off of a table in a database, or some text file you suck in. For the sake of this example, I'll use a db.
create your table
table {
field
label
type
init_value
}
then...
$res = $db->query('SELECT * FROM table);
while($obj = $res->fetch_array()){
switch( $obj['type'] ){
case 'text' : echo "<input type='text' name='{$obj['field']}' value='{$obj['init_value']}'>";
break;
etc...
}
}
Now, that's a very simple (SIMPLE) design, but you can get the idea. You might want to do something like setting up groupings for the inputs.
create your table
table {
field
label
type
init_value
}
then...
$res = $db->query('SELECT * FROM table);
while($obj = $res->fetch_array()){
switch( $obj['type'] ){
case 'text' : echo "<input type='text' name='{$obj['field']}' value='{$obj['init_value']}'>";
break;
etc...
}
}
Now, that's a very simple (SIMPLE) design, but you can get the idea. You might want to do something like setting up groupings for the inputs.