So, in short, here's what we're trying to do:
We've got a page where the user can specify what fields or attributes they want on a table. This is accomplished via MySQL. After submitting, the user is presented with another page that has their newly entered table attribute information displayed. They have the option to include all or some of the attributes to a dynamic form, which they will then be able to use. The attributes they put in the table have now become fields of the dynamic form. After this, the user takes the html of the new, dynamic form and places it on his or her website. From here, the user's customers can fill the form out and submit it back to the user, with the customer input data stored in another table, which is created dynamically depending on what the user has included on his or her dynamic form.
The problem is this: since the form is being created dynamically, the forms names are dynamic as well. this makes it hard when populating a table, since the name on a form hold the value attributed with it. is there some way i can specify the name of a field on a form and the value of that field seperately? like two different variables?
This is as far as I got before I gave up...
...random dynamically created form...html
<form method=post action=subscribe.php>
<table>
<tr><td width="70">lastname :</td><td align="left"><input type="textbox" name="form_variable[]" value=""></td></tr>
<tr><td width="70">firstname :</td><td align="left"><input type="textbox" name="form_variable[]" value=""></td></tr>
<tr><td>Email:</td><td><input type="textbox" name="emailaddress"></td></tr>
<tr><td>Device Type:</td><td><select name="devicetype">
<option value="default" selected></option> <option value="Handheld">Handheld</option> <option value="Palmpilot">Palmpilot</option> <option value="BetaTester">BetaTester</option> <option value="SideKick">SideKick</option> </select></td></tr>
<tr><td colspan="2">
<input type="submit" name="subscribe" value="Subscribe/Update"><input type="submit" name="remove" value="Remove"></td></tr>
</table>
</form>
subscribe.php
<?
$form_variable = $HTTP_POST_VARS['form_variable'];
# pull fields from table VARIABLE. use these as the forms names + one space...(?)
#---i have no idea how to do this.
#---the problem is that the new forms names are dynamic. so how do you check for something that
#----you are not sure is even there. i.e., the not existing thing. (maybe a default value.)
$connection = mysql_connect("localhost");
$db = "westhill";
mysql_select_db($db, $connection) or die( "Could not open $ db");
$sql = "SELECT * FROM container";
$rest = mysql_query($sql, $connection) or die( "Could not execute sql: $sql");
$num_rest = mysql_num_rows($rest);
for ($a=0; $a<$num_rest; $a++)
{
$row = mysql_fetch_array($rest);
$container_values[] = $row["c_field_name"];
}
$sql = "DESC";
$ressa = mysql_query($sql, $connection) or die( "Could not execute sql: $sql");
$num_ressa = mysql_num_rows($ressa);
$count = count($form_variable);
for ($b=0; $b<$count; $b++) //for loop to loop through arrays.
{
#echo($form_variable[$a]);
$row = mysql_fetch_array($ressa);
#---whereever the one field is whatever, set that to the same name of whatever it was.
#----i.e. cat was field name. pass cat and save as cat. but, i wouldn't know that...;)
if ($form_variable[$b] == $row["c_field_name"]) {
$sql = "INSERT INTO variable ($row["c_field_type"])
VALUES ($form_variable[$b]
}
echo"Thank you for your submission.";
?>
I was trying some things with an array of names, but then there was NO way of knowing which field was which. I would appreciate any help or ideas. Thanks.