If I press the refresh button on my web form it submits the form and add the default values or whatever values that were there to the database.could anyone help me by giving me some sort of solution to this problem
why does my form submit when i press the refresh button
Collapse
X
-
It should only submit if the user has pressed return or selected the 'submit' button.
But, if this, for some (strange) reason, isn't the case, you can counter it with PHP.
I'm sure you could with JavaScript but i'm not sure how you would do that...
assuming you're submitting to the same page:
[code=php]
<?php
$submitButton = $_POST['submit']; //name of submit button from form!
if(isset($submi tButton)){
//code to execute if submit button has been clicked
} else {
//otherwise just show the form
}
?>
[/code]
Hope this helped. -
hi markusn00b,
Thank you for your reply,
Sorry for not posting my code.
I did as you said and it is still not working.
This is what savedata.php looks like
[PHP]<?php
if(isset($_POST['save'])){
//save the form values to database
}
include form.php;
?>
[/PHP]
And form.php is the code that actually creates my form with the submit button named save.
Can someone please help me.Comment
-
Hi,
No i didnt get a browser confirmation alert.
the form.php script is pretty complicated where it includes a table for formatting ,php to get data from db to populate drop down boxes and stuff. I am going to TRY and highlight what i think might be applicable for you to help me.
[code=php]
<form id="form_body" name="form_body " method="post" action="">
<table //and all its attributes>
<tr>//table rows that creates and populates the numerous text boxes and dropdown boxes
</tr>
<input name="save" type="submit" id="save" value="SAVE CALL DATA" onclick="return validateform()" tabindex="-1" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;"/>//actual code for my submit button
</table>
</form>
[/code]Comment
-
Hi acoder,
sorry about that. I meant web browser not web form, my fault.
This is what the form.php looks like
Code: (php)
[CODE=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FORM</title>
<!-- InstanceEndEdit able -->
<style type="text/css">
<!--[/code][code=css]
.style1 {
color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-style: normal;
font-weight: lighter;
font-size: 20px;
}
body {
background-color: #FFFFFF;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style2 {
font-size: 20px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style3 {
font-size: 18px;
font-weight: bold;
color:#0000CC
}[/code]
[code=html]-->
</style>
<!-- InstanceBeginEd itable name="head" -->
<style type="text/css">
<!--[/code][code=css]
.style7 {
font-size: 16px;
font-weight: bold;
}
.style8 {color: #0000FF}
.style11 {color: #000000}
.style14 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style15 {
color: #000000;
font-size: 20px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style16 {color: #FF0000}[/code][code=html]
-->
</style>
<!-- InstanceEndEdit able -->
</head>
<body>
<table width="700" height="244" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#F FFFFF">
<tr bordercolor="#F F0000">
<th width="794" height="136" bordercolor="#F FFFFF" scope="col"><im g src="/Pictures/Operator_Banner .jpg" alt="Web page banner" width="791" height="136" longdesc="/Pictures/Operator_Banner .jpg" /></th>
</tr>
<tr bordercolor="#0 000FF" bgcolor="#0000F F">
<td height="107" bordercolor="#F FFFFF" bgcolor="#FFFFF F"><div align="center">
<table width="775" border="0">
<tr bordercolor="#9 9CCFF">
<td><div align="center"> <img src="/Pictures/menu.jpg" alt="menu" width="775" height="30" border="0" usemap="#Map" /></div></td>
</tr>
<!-- InstanceBeginEd itable name="body" -->
<script src="functions. js" type="text/javascript" language="javas cript">
</script>
[/code][code=php]
<?php
error_reporting (E_ALL);
ini_set('displa y_errors',true) ;
require_once('./connection_vari ables.php');
@mysql_pconnect (SQL_HOST, SQL_USER,SQL_PA SS) OR die('Could not connect to the database. ' . mysql_error());
@mysql_select_d b(SQL_DBOC);
?>[/code][code=html]
<tr>
<td><form id="form_body" name="form_body " method="post" action="">
<table width="784" border="0" align="center" cellpadding="1" cellspacing="0" bordercolor="#F FFFFF" bgcolor="#CCFFF F" id="tbl_bodyCal lLog">
<tr>
<td width="188" rowspan="2" bordercolor="#F FFFFF" bgcolor="#99CCF F"><label class="style2">
<div align="left" class="style7 style14"><span class="style2"> <span class="style7"> DATE:</span></span></div>
</label></td>
<td width="154" bordercolor="#F FFFFF" bgcolor="#FFFFF F"><div align="left"></div>
<div align="left"></div>
<div align="left"></div>
<div align="left"></div>
<div align="left"></div>
<div align="left"></div></td>
<td width="170" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
<td width="2" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
<td width="233" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
<td width="17" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFF F"> </td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFF F"><div align="left">
<label></label>
</div></td>
</tr>
<tr>
<td height="38" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">FI RST NAME:</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left">
<label></label>
<label>
<input name="f_name" type="text" id="f_name" size="15" tabindex="2" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onchange="chang e('f_name')"/>
</label>
</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7">
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left"></div></td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left"></div></td>
<td colspan="3" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">
<p class="style7">
<label>
</label>
</p>
</div></td>
</tr>
<tr>
<td height="21" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">LA ST NAME: </div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<input name="l_name" type="text" size="15" tabindex="4" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onchange="chang e('l_name')"/>
</div>
</label></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> </td>
<td colspan="3" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style16" ></td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td colspan="6" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
</tr>
<tr>
<td colspan="8" bordercolor="#F FFFFF" bgcolor="#99CCF F" class="style15" ><div align="left">EX TENSION DETAILS: </div></td>
</tr>
<tr>
<td height="25" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"><s pan class="style7"> EXTENSION #: </span></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left">
<label> </label>
</div></td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">DE PARTMENT : </div></td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td colspan="3" rowspan="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
[/code][code=php]
<?php
$query = "select Department from Departments";
$result = mysql_query($qu ery);
echo "<select name=\"Petrotri n_departments_e xt\" onchange=\"chan ge('Petrotrin_d epartments_ext' )\">";
echo"<option selected=\"sele cted\">---------------------------------SELECT---------------------------------</option>";
while($row = mysql_fetch_arr ay($result, MYSQL_NUM)){
$department = $row[0];
echo"<option>$d epartment</option>";
}
echo "</select>";
?>[/code][code=html]
</div>
</label></td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<input name="extension _num" maxlength="4" type="text" id="extension# " size="15" tabindex="6" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onchange="chang e('extension_nu m')" onblur="return CheckExt('exten sion#')"/>
</div>
</label></td>
</tr>
<tr>
<td height="50" bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">LO CATION:</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td colspan="3" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<label>
[/code][code=php]
<?php
$query = "select Location from Petrotrin_locat ions";
$result = mysql_query($qu ery);
echo "<select name=\"Petrotri n_locations_ext \" onchange=\"chan ge('Petrotrin_l ocations_ext')\ " >";
echo"<option selected=\"sele cted\">-------------------SELECT-------------</option>";
//echo"<option selected=\"sele cted\">Point-a-Pierre</option>";
while($row = mysql_fetch_arr ay($result, MYSQL_NUM)){
$location = $row[0];
echo"<option>$l ocation</option>";
}
echo "</select>";
?>[/code][code=html]
</label>
</div>
</label></td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">AD DITIONAL INFO:<span class="style16" >*</span> </div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td colspan="3" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<input name="phone_add ress" type="text" id="phone_addre ss" size="40" tabindex="7" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;"/>
</div>
</label></td>
</tr>
<tr bgcolor="#00FFF F">
<td colspan="8" bordercolor="#F FFFFF" bgcolor="#99CCF F" class="style2 style11"><div align="left">CA LL DETAILS: </div></td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">CA LL TYPE:</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<select name="ddl_CallT ype" id="callType_dd l" tabindex="8" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;">
<option>Company </option>
<option>Persona l</option>
</select>
</div>
</label> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"><s pan class="style7"> NAME OF COMPANY: </span></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td width="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left">
<input type="text" name="company_n ame" size="40" onchange="chang e('company_name ')" onblur="return checkname()" tabindex="9" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;"/>
</div></td>
<td width="2" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"> </td>
</tr>
<tr>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left">NU MBER CALLED: </div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left">
<input name="txt_numbe rCalled" type="text" size="15" maxlength="20" tabindex="10" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onchange="chang e('txt_numberCa lled')" onblur="return PhoneCheck('txt _numberCalled') "/>
</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label> </label>
<div align="left"><s pan class="style7"> NAME OF CONTACT: </span> </div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td colspan="4" bordercolor="#F FFFFF" bgcolor="#FFFFC C">
<div align="left">
<input name="txt_conta ct_name" type="text" size="40" tabindex="11" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onchange="chang e('txt_contact_ name')"/>
</div></td></tr>
<tr>
<td height="38" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left" class="style7">
<div align="left">CO NNECTED:</div>
</div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<select name="ddl_conne cted" id="connected_d dl" tabindex="12" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;">
<option>YES</option>
<option>NO</option>
</select>
</div>
</label></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"><s pan class="style7"> OPERATOR:</span></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C"><div align="left"></div></td>
<td bordercolor="#F FFFFF" bgcolor="#FFFFC C" class="style7"> <div align="left"></div></td>
<td colspan="3" bordercolor="#F FFFFF" bgcolor="#FFFFC C"><label>
<div align="left">
<label>[/code][code=php]
<?php
$query = "select CONCAT(LastName , ', ',FirstName) from Operators order by LastName";
$result = mysql_query($qu ery);
echo"<select name=\"operator s\" onchange=\"chan ge('operators') \">";
echo"<option selected=\"sele cted\">-------------------SELECT-------------</option>";
while($row = mysql_fetch_arr ay($result, MYSQL_NUM)){
$name = $row[0];
echo"<option>$n ame</option>";
}
echo "</select>";
?>[/code][code=html]
</label>
</div>
</label> <label>
</label></td>
</tr>
<tr bgcolor="#99ccf f">
<td height="18" colspan="8" bordercolor="#F FFFFF"><label></label> <label></label></td>
</tr>
<tr bgcolor="#ffffc c">
<td height="18" colspan="3" bordercolor="#F FFFFF"><label>
<div align="left">
<input name="save" type="submit" id="save" value="SAVE CALL DATA" onclick="return validateform()" tabindex="-1" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;"/>
<input name="reset" type="reset" id="reset" value="RESET FORM" tabindex="-2" onKeyDown="if(e vent.keyCode==1 3) event.keyCode=9 ;" onclick="toForm ()"/>
</div>
</label></td>
<td bordercolor="#F FFFFF"> </td>
<td bordercolor="#F FFFFF" class="style7"> </td>
<td colspan="3" bordercolor="#F FFFFF"> </td>
</tr>
</table>
</form> </td>
<td> </td>
</tr>
<!-- InstanceEndEdit able -->
</table>
</div></td>
</tr>
</table>
<map name="Map" id="Map">
<area shape="rect" coords="4,1,101 ,19" href="http://corpweb/ittweb04/Default.htm" target="_self" />
<area shape="rect" coords="126,3,3 14,17" href="/login.php" target="_self" />
<area shape="rect" coords="149,3,1 50,10" href="#" /><area shape="rect" coords="132,3,1 33,14" href="#" /><area shape="rect" coords="326,2,5 16,22" href="#" />
<area shape="rect" coords="539,4,6 28,22" href="#" /><area shape="rect" coords="644,4,7 72,16" href="http://corpweb/ittweb04/Policy.htm" target="_blank" />
<area shape="rect" coords="690,4,6 92,9" href="#" /><area shape="rect" coords="3,1,13, 6" href="#" /><area shape="rect" coords="8,9,30, 11" href="#" /></map></body>
<!-- InstanceEnd --></html>
[/CODE]
and well this is savedata.php
[code=php]<?php
if(isset($_POST['save'])){
//connect to the database
//manipulate the elements on the form
}
//Include the form
include "form.php";
?>[/code]
sorry about thatComment
-
I am not sure.
The code was written by someone else and that is how they structured it. Should the action attribute have savedata.php as its parameters..... .action="saveda ta.php"
on the browser when i type http://savedata.php the all the stuff that was created and done in the form.php shows up and the form works fine. savedata also saves the stuff to the db fine too.
I am new to html and php and stuff so i am preety lostComment
-
So you want to submit the data only once and somehow prevent the refreshing of the page causing the data to be insterted again.
Maybe you should compare the data being submitted against what's already in the table, to see if it's already submitted?
mysql_numrows() is what you'd need! :)Comment
Comment