hi all,
I want to make generator for form fields so that I can add/delete/update tables, and in each table I can add/delete/update fields.
it works fine tell I try to delete the last field in the table it does not responde and I don't know why also I done some tracing it confuse me
now my question is can you please help me to make it work just fine?
thanks in advance
best regards
HG
here is the code:
<?php
/*
echo "<pre>";
print_r ($_REQUEST);
echo "</pre><br />";
*/
if (isset($del_table))
{
$del_table= str_replace("del table","",$del_table);
echo($del_table);
}
if (isset($add_field))
{
$add_field= str_replace("add field","",$add_field);
echo($add_field);
}
if (isset($del_field))
{
$del_field= str_replace("del field","",$del_field);
echo($del_field);
}
?>
<form name="f" method="post" action="load.php">
<input name="add_table" type="submit" value="add table" /> <br />
<?php
$table_name=$_REQUEST['tab
le_name'];
if(isset($del_table))
{
array_splice($table_name,$
del_table,
1);
}
//print_r($table_name);
for($x=0; $x < count($table_name); $x++)
{
?>
table:<input name="table_name[]" type="text"
value="<?php echo $table_name[$x];?>" />
<input name="del_table" type="submit"
value="del table<?php echo $x;?>" />
<input name="add_field" type="submit"
value="add field<?php echo $x;?>" />
<br />
<?php
$fields[$x]= $_REQUEST["field$x"];
if(isset($del_table))
{
array_splice($fields,$del_
table,1);
}
if (isset($add_field))
{
$add_field= str_replace("add field","",$add_field);
$pieces= explode ("_", $add_field);
}
if(isset($fields[$x]))
{
$tmp=$fields[$x];
echo "count of tmp ". count($tmp);
echo "<pre>";
print_r ($fields[$x]);
echo "</pre><br />";
for($y=0; $y < count($tmp); $y++)
{
if(isset($del_field))
{
$pieces= explode ("_", $del_field);
if($pieces[0]==$x and $pieces[1]==$y )
{
if (count($tmp<=1))
{
unset($tmp);
}
else
{
array_splice($tmp,$pieces[
1],1);
}
}
$fields[$x]=$tmp;
}
?>
fi
eld<input name="field<?php echo $x; ?>[]" type="text" value="<?php echo $tmp[$y]?>" />
<input name="del_field" type="submit"
value="del field<?php echo $x."_".$y;?>" />
<br />
<?php
}
}
?>
<?php
if (isset($add_field))
{
if($add_field==$x)
{
?>
fi
eld<input name="field<?php echo $x; ?>[]" type="text" value="" />
<input name="del_field" type="submit"
value="del field<?php echo $x."_".$y;?>" /><br />
<?php
}
}
?>
<?php
}
?>
<?php
if ($_REQUEST['add_table']=="
add table")
{
?>
table:<input name="table_name[]" type="text" />
<br />
<?php
}
?>
</form>
Start Free Trial