swap.543 0 Newbie Poster

I want to know how do i post my form values in database.
I am creating widgets dynamically using javascript function and want to store values posted by those dynamically created widgets in database.

here is my code

<script language="javascript">
var inival=0; // Initialise starting element number

// Call this function to add textbox
function text(a)
{
//alert("TextBox Added");
var newArea = add_New_Element(a);
var htcontents = "<input type='text' name='txtbx[]'/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}

function radio(a)
{
//alert("Radio Button Added");
var newArea = add_New_Element(a);
var htcontents = "<input type='radio' name='radio[]'/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}

function checkbox(a)
{
//alert("CheckBox Added");
var newArea = add_New_Element(a);
var htcontents = "<input type='checkbox' name='chkbox[]'/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}

function password(a)
{
//alert("Password Field Added");
var newArea = add_New_Element(a);
var htcontents = "<input type='password' name='pass[]'/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}

function file(a)
{
//alert("File Upload Added");
var newArea = add_New_Element(a);
var htcontents = "<input type='file' name='file_upload[]'/>";
document.getElementById(newArea).innerHTML = htcontents; // You can any other elements in place of 'htcontents'
}


function add_New_Element(a)
 {
inival=inival+1; // Increment element number by 1
var ni = document.getElementById('area'+a);
var newdiv = document.createElement('div'); // Create dynamic element
var divIdName = 'my'+inival+'Div';
newdiv.setAttribute('id',divIdName);
ni.appendChild(newdiv);
return divIdName;
}

function show(param)
{
	//alert("Got Param");
	var frm_mn = param.options[param.selectedIndex].value;
	document.getElementById('hidden').value=frm_mn;	// Empty city select box
	document.form1.submit();
}

</script>
<style type="text/css">
<!--
.style1 {
	font-size: x-large;
	font-weight: bold;
}
.style3 {font-size: large; font-weight: bold; color: #CC0066; }
-->
</style>
</head>

<body>
<p>
<form name="form1" method="post" action="create_widgets.php?process=show_form">
  <p>Edit Your Existing Form</p>
  <p>Choose Form
    <label>
    <select name="search" id="search" onChange="show(this)" >
                <option>--Select--</option>
                <?
						$sql = "SELECT * FROM custom_forms WHERE cid='1'";
							$result = mysql_query($sql) or die(mysql_error());
							while($row = mysql_fetch_array($result))
						{
							$form = stripslashes($row['form_name']);
							echo "<option>$form</option>";
						}
						
				  ?>
    </select>
			  <input type="hidden" name="hidden" id="hidden" >
    </label>
   
</form>

  <?
  if($PROCESS=="show_form")
  {
$SQL_CREATE="SELECT * FROM custom_forms WHERE form_name='$HIDDEN'";
$RES_CREATE=mysql_query($SQL_CREATE) or die(mysql_error());
$ROW=mysql_fetch_array($RES_CREATE);

$STRING=$ROW['string'];
$FORM_NAME=$ROW['form_name'];

//echo "<br>". $STRING;
?>

<form name="custom" id="custom" method="post" action="create_widgets.php?process=add&HID=<?=$HIDDEN;?>">

  <table align="center" width="527" border="1">
    <tr>
      <td><div align="center" class="style1">Table Name </div></td>
      <td width="109"><div align="center">
          <? echo $FORM_NAME; ?>
      </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="159"><div align="center" class="style3">Widget Name </div></td>
      <td width="109"><div align="center" class="style3">Widget Type</div></td>
      <td width="158"><div align="center" class="style3">Widgets </div></td>
    </tr>
	
    <?
$STRING_BREAK=explode(';',$STRING);
$i=0;
		foreach($STRING_BREAK as $string_break)
		{
			if($string_break!="")
			{ 
				$my=explode(':',$string_break);
				$leave=$my[0];
	 			$get=$my[1];
				?>				
    <tr>
      <td><?= $leave; ?></td>
      <td><?= $get; ?></td>
      <td><div id='area<? echo $i;?>'></div>
          <? if($get=="text")
	    	echo"<script language='javascript'> text(".$i."); </script>";
			
			if($get=="radio")
	    	echo"<script language='javascript'> radio(".$i."); </script>";
			
			if($get=="checkbox")
	    	echo"<script language='javascript'> checkbox(".$i."); </script>";
			
			if($get=="file")
	    	echo"<script language='javascript'> file(".$i."); </script>";
			
			if($get=="password")
	    	echo"<script language='javascript'> password(".$i."); </script>";
			
	   ?>      </td>
    </tr>
    
    <?		$i=$i+1;						
			}			
		}
		//echo $get;		
?>  
<tr>
      <td colspan="3"><label>
        <div align="center">
          <input type="submit" name="Submit" value="Submit" />
        </div>
      </label></td>
    </tr> 
  </table>  
  <p>&nbsp;</p>
</form>
<p>
  <? } ?>

in process "add" i want to post values in database

Please help me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.