Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a Form Once submitted Into Database

Status
Not open for further replies.

otgriffin

Programmer
Jan 21, 2003
8
US
Hello,

I am trying to clear a form after it's information has been submitted into the Database and before it is redirected to a Thank you page. I tried using the onload function to clear the page an it worked but I only want it to clear once it has been submitted not on any other time (such as hitting back button).(Oh I am using php and javascript). I am wanting this so that once submitted the user information is not visible to anyone. I also want to keep the user from entering in a duplicate record by accidently hitting the submit button. I was wondering if the <?php include(&quot;javascript.inc&quot;);?> would be helpful. Can someone please give me some advise concerning these issues.

Thanks to everyone in advance!!!!

 
Use this:

function ClearFields( ) {
var nLoop = 0;
var nListLen = document.TemplateQueryForm.elements.length;

for (nLoop; nLoop < nListLen; nLoop++) {
//If the item is in our checked list then check it for display!
if (document.TemplateQueryForm.elements[nLoop].type == &quot;text&quot;) {
document.TemplateQueryForm.elements[nLoop].value = &quot;&quot;
} else if (document.TemplateQueryForm.elements[nLoop].type == &quot;checkbox&quot;) {
document.TemplateQueryForm.elements[nLoop].checked = false;
}
}
}
 
Placido,

I have tried inserting the code you gave me. For some reason it is not working for me. Here is a copy of the code that I have. Everything should work except for the clearfield function and the onClick=clearfield function.

Code:
Code:
<?php require_once('../Connections/connGis.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = &quot;&quot;, $theNotDefinedValue = &quot;&quot;) 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case &quot;text&quot;:
      $theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . $theValue . &quot;'&quot; : &quot;NULL&quot;;
      break;    
    case &quot;long&quot;:
    case &quot;int&quot;:
      $theValue = ($theValue != &quot;&quot;) ? intval($theValue) : &quot;NULL&quot;;
      break;
    case &quot;double&quot;:
      $theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . doubleval($theValue) . &quot;'&quot; : &quot;NULL&quot;;
      break;
    case &quot;date&quot;:
      $theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . $theValue . &quot;'&quot; : &quot;NULL&quot;;
      break;
    case &quot;defined&quot;:
      $theValue = ($theValue != &quot;&quot;) ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
//function ControlCache()
//{
 // header (&quot;Expires: &quot;.gmdate(&quot;D, d M Y H:i:s&quot;, time()).&quot; GMT&quot;); 
 // header (&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;); 
//  header (&quot;Cache-Control: no-cache, must-revalidate&quot;); 
 // header(&quot;Cache-Control: post-check=0, pre-check=0, false&quot;);
//  header (&quot;Pragma: no-cache&quot;); 
//}
//ControlCache();
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= &quot;?&quot; . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS[&quot;MM_insert&quot;])) && ($HTTP_POST_VARS[&quot;MM_insert&quot;] == &quot;form1&quot;)) {
  $insertSQL = sprintf(&quot;INSERT INTO Test (Firstname, Lastname, Password) VALUES (%s, %s, %s)&quot;,
                       GetSQLValueString($HTTP_POST_VARS['Firstname'], &quot;text&quot;),
                       GetSQLValueString($HTTP_POST_VARS['Lastname'], &quot;text&quot;),
                       GetSQLValueString($HTTP_POST_VARS['Password'], &quot;text&quot;));

  mysql_select_db($database_connGis, $connGis);
  $Result1 = mysql_query($insertSQL, $connGis) or die(mysql_error());

  $insertGoTo = &quot;/Gis_Survey/ThankYou2.htm&quot;;
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? &quot;&&quot; : &quot;?&quot;;
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }

 header(sprintf(&quot;Location: %s&quot;, $insertGoTo));
 //if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {

}
?>
<html>
<head>
<title>This is Only a Test</title>
<script language=&quot;JavaScript&quot;>
<!--
function ClearFields(){
    var nLoop = 0;
    var nListLen = document.TemplateQueryForm.elements.length;

    for (nLoop; nLoop < nListLen; nLoop++) {
    //If the item is in our checked list then check it for display!
    if (document.TemplateQueryForm.elements[nLoop].type == &quot;text&quot;) {
                        document.TemplateQueryForm.elements[nLoop].value = &quot;&quot;
                    } else if (document.TemplateQueryForm.elements[nLoop].type == &quot;checkbox&quot;) {
                        document.TemplateQueryForm.elements[nLoop].checked = false;
}
}

//-->
</script> 
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot; onclick=&quot;MM_validateForm('Firstname','','R','Lastname','','R','Password','','R');return document.MM_returnValue; ClearFields&quot; >
<form action=&quot;<?php echo $editFormAction; ?>&quot;  method=&quot;POST&quot; name=&quot;form1&quot;>
  <table border=0 cellpadding=2 cellspacing=0 align=&quot;center&quot;>
    <tr valign=&quot;baseline&quot;> 
      <td nowrap align=&quot;right&quot;>Firstname:</td>
      <td> <input name=&quot;Firstname&quot; type=&quot;text&quot; size=&quot;32&quot;></td>
    </tr>
    <tr valign=&quot;baseline&quot;> 
      <td nowrap align=&quot;right&quot;>Lastname:</td>
      <td> <input name=&quot;Lastname&quot; type=&quot;text&quot; size=&quot;32&quot;></td>
    </tr>
    <tr valign=&quot;baseline&quot;> 
      <td nowrap align=&quot;right&quot;>Password:</td>
      <td> <input name=&quot;Password&quot; type=&quot;password&quot; value=&quot;Enter in a Password&quot; size=&quot;32&quot;></td>
    </tr>
    <tr valign=&quot;baseline&quot;> 
      <td nowrap align=&quot;right&quot;> </td>
      <td> <input name=&quot;Submit&quot; type=&quot;submit&quot;  value=&quot;Insert Record&quot;></td>
    </tr>
  </table>
  <input type=&quot;hidden&quot; name=&quot;MM_insert&quot; value=&quot;form1&quot;>
</form>
<p><a href=&quot;/login1.php&quot;>administration use only</a></p>
</body>

</html>
Thank you for your help.
 
I think you're going to have to change &quot;TemplateQueryForm&quot; to the name of the form you're using (form1?), or reference the forms collective (document.forms[x].elements[nLoop].value=, where &quot;x&quot; is the number of the form on the page) if you haven't actually given your form a name attribute.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top