title: Auto submit php form
body: <p>I want to submit a form after some interval periodically. 
  I have tried as follows.</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;  
  
  function fncAutoSubmitForm()
  {
      //alert('test alert');
      alert("B : "+document.getElementById('myform').id);     
      document.getElementById('myform').submit();     
      alert("A : "+document.getElementById('myform').id);
      setTimeout("fncAutoSubmitForm();",5000);}
  </code></pre>
  
  <p><code>&lt;/script&gt;</code></p>
  
  <p>displayPage.php code as follows</p>
  
  <pre><code>&lt;body onload="fncAutoSubmitForm();"&gt;
  </code></pre>
  
  <p><code>&lt;form id="myform" name="myform" action="code.php" method="post"&gt;</code>
  <code>some controls</code>
  <code>&lt;/form&gt;</code>
  <code>&lt;/body&gt;</code></p>
  
  <p>here, <br/>"displayPage.php" submits the page to "code.php"
  <br/> "code.php" performs required action and redirects to "displayPage.php"</p>
  
  <p>It works fine when I dont use autosubmit. i.e. fncAutoSubmitForm() function
  <br/>but when I use fncAutoSubmitForm() "displayPage.php" disappears</p>
  
  <p>here is the actual code</p>
  
  <pre><code>&lt;form action="code.php" method="post" id="myform" name="myform" onload='setGenLeadId();'&gt;                                   
  </code></pre>
  
  <p>
              
              </p>
  
  <pre><code>        &lt;tr&gt;&lt;td colspan="2"&gt;&lt;?php if($row1['lead_call_type']=="C"){echo"&lt;font color=red&gt;CALLBACK Lead&lt;/font&gt;";}?&gt;&lt;/td&gt;
           &lt;td  align = "right"&gt;&lt;strong&gt;Lead Id :&lt;/strong&gt; &lt;/td&gt;
          &lt;!--&lt;td&gt;&lt;b&gt;&lt;font color="red"&gt;&lt;/font&gt;Reference Number&lt;/b&gt;&lt;/td&gt;--&gt;
  
          &lt;td  align="left"&gt;&lt;?php echo "" . $row1['lead_id'] ."";?&gt;&lt;/td&gt;          
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td align="right" &gt;&lt;b&gt;Name :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;&lt;input name="custname" id="custname" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="&lt;?php echo htmlspecialchars($row1['lead_fname'])?&gt;"&gt;&lt;/td&gt;                
              &lt;td  align="right"&gt;&lt;b&gt;Phone :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;&lt;input name="phone" id="phone"  style="width: 100%;height: 25%;" maxlength="10" type="text"  value = "&lt;?php echo "" . $row1['lead_phone1'] ."";?&gt;" &gt;&lt;/td&gt;
  
          &lt;/tr&gt;
  
          &lt;tr&gt;                
              &lt;td align="right"&gt;&lt;b&gt;City :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;
              &lt;input name="city" id="city" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="&lt;?php echo "" . $row1['lead_city'] ."";?&gt;"&gt;
  
              &lt;/td&gt;
              &lt;td align="right"&gt;&lt;b&gt;State :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left" &gt;
              &lt;input name="state" id="state" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="&lt;?php echo "" . $row1['lead_state'] ."";?&gt;"&gt;             
  
  
              &lt;/td&gt;   
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td align="right"&gt;&lt;b&gt;Email-ID :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left" &gt;&lt;input name="email" id="email" style="width: 100%;height: 25%;" class="textbox" type="text"   value = "&lt;?php echo "" . $row1['lead_email'] ."";?&gt;"&gt;&lt;/td&gt; 
              &lt;td  align="right"&gt;&lt;b&gt;Source &lt;/b&gt;&lt;/td&gt;
              &lt;td &gt;&lt;input type="text" name="source" id = "source"  style ="width:100%;resize: none;" maxlength="900" value="&lt;?php echo "". $row1['lead_source'] ."";?&gt;"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
          &lt;td align="right"&gt;&lt;b&gt;Address : &lt;/b&gt;&lt;/td&gt;
              &lt;td&gt;
              &lt;textarea type="text" name="address" id = "address"  style ="width:100%;resize: none;" maxlength="900" &gt;&lt;?php echo "". $row1['lead_address1'] ."";?&gt;&lt;/textarea&gt; 
              &lt;/td&gt;
              &lt;td align="right"&gt;&lt;b&gt;Zip Code :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;&lt;input name="zip" id="zip" class="textbox" style="width: 100%;height: 25%;" maxlength="140" type="text" value="&lt;?php echo htmlspecialchars($row1['lead_zip'])?&gt;"&gt;&lt;/td&gt;
              &lt;!--&lt;td  align="right"&gt;&lt;b&gt;Phone :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;&lt;input name="phone" id="phone"  style="width: 100%;height: 25%;" maxlength="10" type="text"  value = "&lt;?php //echo "" . $row1['lead_phone1'] ."";?&gt;" &gt;&lt;/td&gt;--&gt;                
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td align="right"&gt;&lt;b&gt;Rounds :&lt;/b&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;?php
  
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='rounds'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='rounds' name ='rounds'&gt;";
                  echo "&lt;option value=".$row1['lead_rounds']." selected&gt;".$row1['lead_rounds']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }                   
                  echo "&lt;/select&gt;";
                  ?&gt;  
              &lt;/td&gt;   
              &lt;td  align="right"&gt;&lt;b&gt;Preparing For IIT-JEE :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;
              &lt;?php
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='IIT-JEE'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='PrepIIT' name ='PrepIIT'&gt;";
                  echo "&lt;option value=".$row1['lead_prep_iit']." selected&gt;".$row1['lead_prep_iit']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }
  
                  echo "&lt;/select&gt;";
                  ?&gt;  
              &lt;/td&gt;               
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td align="right"&gt;&lt;b&gt;Which Standard :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left" &gt;
              &lt;?php
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='standered'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='standared' name ='standared'&gt;";
                  echo "&lt;option value=".$row1['lead_standared']." selected&gt;".$row1['lead_standared']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }
  
                  echo "&lt;/select&gt;";
                  ?&gt;  
              &lt;/td&gt;   
              &lt;td  align="right"&gt;&lt;b&gt;Promo DVD :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;
              &lt;?php
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='PromoDVD'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='dvd' name ='dvd'&gt;";
                  echo "&lt;option value=".$row1['lead_dvd']." selected&gt;".$row1['lead_dvd']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }
  
                  echo "&lt;/select&gt;";
                  ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  
  
  
          &lt;tr&gt;
              &lt;td align="right"&gt;&lt;b&gt;Percentage in 10th :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left" &gt;&lt;input name="tenth" id="tenth" maxlength="5"  style="width: 100%;height: 25%;" class="textbox" type="text"   value = "&lt;?php echo "" . $row1['lead_tenth'] ."";?&gt;"&gt;&lt;/td&gt;  
              &lt;td align="right"&gt;&lt;b&gt;Percentage in 12th :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"  &gt;&lt;input name="twelth" id="twelth" maxlength="5" style="width: 100%;height: 25%;" class="textbox" type="text"  value = "&lt;?php echo "" . $row1['lead_twelth'] ."";?&gt;"&gt; &lt;/td&gt;   
              &lt;!--&lt;td align="right"&gt;&lt;b&gt;Time of Call&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"  &gt;&lt;input name="calltime" id="calltime" style="width: 100%;height: 25%;" class="textbox" type="text"  value = "&lt;?php// echo "" . $row1['lead_import_batch_start_date'] ."";?&gt;" readonly&gt;   &lt;/td&gt;   --&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td align="right"&gt;&lt;b&gt;JEE appearing year :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left" &gt;
              &lt;?php
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='JeeYear'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='jeeyear' name ='jeeyear'&gt;";
                  echo "&lt;option value=".$row1['lead_jee_year']." selected&gt;".$row1['lead_jee_year']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }
  
                  echo "&lt;/select&gt;";
                  ?&gt;  
              &lt;/td&gt;   
              &lt;td  align="right"&gt;&lt;b&gt;Joined any classes :&lt;/b&gt;&lt;/td&gt;
              &lt;td  align="left"&gt;
              &lt;?php
                  $query = mysql_query("SELECT param_field_value,param_field_itemdata FROM cti_service_parameters where param_service_id=$service_id and param_field_name='JoinedClasses'");
                  $k=0;
                  echo "&lt;select  style='width: 100%;' id='classes' name ='classes'&gt;";
                  echo "&lt;option value=".$row1['lead_classes']." selected&gt;".$row1['lead_classes']."&lt;/option&gt;";
                  while($row = mysql_fetch_array($query))
                  {
                      $value[$k] = $row['param_field_value'];
                      $item[$k] = $row['param_field_itemdata'];
  
                      if($field_val == $item[$k])
  
                          echo "&lt;option value='$value[$k]' selected&gt;$value[$k]&lt;/option&gt;";
                      else
  
                          echo "&lt;option value='$value[$k]'&gt;$value[$k]&lt;/option&gt;";
  
                      $k = $k + 1;
                  }
  
                  echo "&lt;/select&gt;";
                  ?&gt;
              &lt;/td&gt;               
          &lt;/tr&gt;           
  
          &lt;tr&gt;
              &lt;td  align="right"&gt;&lt;b&gt;Remarks :&lt;/b&gt;&lt;/td&gt;
              &lt;td colspan="3"&gt;&lt;textarea type="text" name="remarks" id = "remarks"  style ="width:100%;resize: none;" maxlength="900" &gt;&lt;?php echo "". $row1['lead_remarks'] ."";?&gt;&lt;/textarea&gt; &lt;/td&gt;
          &lt;/tr&gt;           
  
          &lt;tr&gt;
              &lt;td colspan=4 class="tableHeading"&gt;
                  &lt;!--&lt;b&gt;&lt;font color="red"&gt;Note : Fields with * are Mandatory&lt;/font&gt;&lt;/b&gt;--&gt;
              &lt;/td&gt;                           
          &lt;/tr&gt;
          &lt;!--&lt;input type="hidden" id="clinicFlag" name="clinicFlag" value="&lt;?php// echo $_GET["clinicFlag"]?&gt;"&gt;--&gt;
          &lt;tr&gt;
          &lt;tr&gt;
              &lt;td  colspan=4 style="padding:0px"&gt;
              &lt;div align="center"&gt;
                      &lt;input title="Save [Alt+S]" accessKey="S" class="crmbutton small save"  type="button" name="save" value="  Save  " style="width:100px;height:30px" &gt;    
              &lt;/td&gt;
              &lt;/div&gt;
          &lt;/tr&gt;
          &lt;/table&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>and Code.php code is as follows</p>
  
  <pre><code>&lt;?php
  //session_start();
  //echo $_SESSION['user'];
  include("connection.php");
  $lead = $_POST['lead'];
  $callnumber = $_POST['callnumber'];
  $service = $_POST['service'];
  $lead_fname = $_POST['custname'];
  $lead_phone1 = $_POST['phone'];     
  $lead_city = $_POST['city'];
  $lead_email = $_POST['email'];          
  $lead_state = $_POST['state'];
  $lead_address1 = $_POST['address'];
  $lead_zip = $_POST['zip'];
  $lead_rounds = $_POST['rounds'];
  $lead_IIT = $_POST['PrepIIT'];
  $lead_standared = $_POST['standared'];
  $lead_dvd = $_POST['dvd'];
  $lead_tenth = $_POST['tenth'];
  $lead_twelth = $_POST['twelth'];
  $lead_jee_year = $_POST['jeeyear'];
  $lead_classes = $_POST['classes'];
  $lead_remarks  = $_POST['remarks'];
  $lead_source = $_POST['source'];    
  
  
  if($GLOBALS['database_type'] == "MySql")
  {
      $con=mysql_connect($GLOBALS['database_ip'],$GLOBALS['database_username'],$GLOBALS['database_password']);
      if (!$con)
      {
          die('Could not connect: ' . mysql_error());
      }
      mysql_select_db($GLOBALS['database_name'],$con);    
  
      $sql1 = mysql_query("SELECT service_outbound_lead_dsn_string,
                              service_outbound_lead_db_user,
                              service_outbound_lead_db_password,
                              service_leadstructure_master_tablename,
                              service_outbound_lead_db_name 
                              FROM cti_services WHERE service_id = $service");
  
  
          while($row = mysql_fetch_array($sql1))
          {
              $lead_dsn = $row['service_outbound_lead_dsn_string'];
              $lead_user = $row['service_outbound_lead_db_user'];
              $lead_pwd = $row['service_outbound_lead_db_password'];
              $lead_table = $row['service_leadstructure_master_tablename'];
              $lead_db = $row['service_outbound_lead_db_name'];
          }
  
      if($_POST['save'])
      {   
      //input_app_datetime = '$lead_appointment', 
      //input_app_reschedule = '$lead_reschedule',
  
  
      mysql_select_db($GLOBALS['database_name'],$con);    
  
  
      $sqlquery = ("UPDATE $lead_db.$lead_table set lead_fname = '$lead_fname', lead_phone1 = '$lead_phone1', lead_email = '$lead_email', lead_remarks = '$lead_remarks', lead_address1 = '$lead_address1', lead_state = '$lead_state', lead_city = '$lead_city', lead_zip = '$lead_zip', lead_rounds ='$lead_rounds', lead_prep_iit ='$lead_IIT', lead_standared ='$lead_standared', lead_dvd ='$lead_dvd', lead_tenth ='$lead_tenth', lead_twelth ='$lead_twelth', lead_jee_year ='$lead_jee_year', lead_classes ='$lead_classes', lead_source ='$lead_source' WHERE lead_id=$lead");
  
  
  
          $dbSql = mysql_query($sqlquery) or die("Error : " . mysql_error()); 
          $sql="update cti_call_master set crm_remarks='$lead_remarks' where call_number=$callnumber";
          $dbSql1 = mysql_query($sql);
          //$flag = "saved";
          $message = "Lead Id-".$lead." Data Saved .....";
          //$message = $sqlquery;
          //header("location:vision.php?LEADID=$lead&amp;SERVICEID=$service&amp;CALLNUMBER=$callnumber&amp;MESSAGE=$message&amp;FLAG=$flag&amp;CLI=$lead_phone1&amp;clinicFlag=$clinicFlag&amp;alterno=$alter_no");                       
          header("location:displayPage.php?LEADID=$lead&amp;SERVICEID=$service&amp;CALLNUMBER=$callnumber&amp;MESSAGE=$message&amp;FLAG=$flag&amp;CLI=$lead_phone1");
      }
  }
  </code></pre>
  
  <p>?></p>