Form Submits empty data when page refreshes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Form Submits empty data when page refreshes

Post by facets »

Hi,

When I hit the refresh page tab my application submits an empty form to the DB.
Can someone give me any pointers to stop this happening?

What code would you like to see?
Is this a common problem?

Cheers, Will/
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

Just refreshing the page shouldn't submit a form. But if you have the form submit as soon as the page loads, then your problem is that in most browsers, refreshing the page clears the form. My suggestions:

1) Either check if the form is blank using JavaScript and don't submit it if it is.

OR

2) Don't have the form submit as soon as the page loads.

-IMP ;) :)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Hi, I'm new, both to DevNet and to PHP.
As I was reading this post, I was wondering - coudn't it be a POST issue?
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

My form must be submitting when the page reloads but NOT by design.
How can I debug this problem?

Basically I have a switch which executes the following code by default..
(I've removed a chunk of code to make it easier to read.

Any pointers would be rad!, Ta Will.

Code: Select all

function viewSAStockSummary() {
	
$paperCategoryId = isset($_POST['paperCategoryId']) ? $_POST['paperCategoryId'] : '';
$colloPaperName = isset($_POST['colloPaperName']) ? $_POST['colloPaperName'] : '';

$sql_add = "INSERT INTO ausapapersummary values ('','$paperCategoryId','$colloPaperName','$manufacturerName','$cpl','$stockId','$adhesiveId','$linerId','$supplierId','$availability', '$features', '$limitations','$productExamples','$suitabilityFoil','$suitabilityYellowLight','$suitabilityLabel','$suitabilityOpacity','$suitabilityBronze','$suitabilityScreen','$suitabilityIceBucket','','')";

mysql_query($sql_add) or die(mysql_error());

echo "<form name=\"addSummary\" method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<table onMouseover=\"changeto('lightgreen')\" onMouseout=\"changeback('white')\" class=\"sorttable\">\n";
echo "<td width=200px colspan=2 valign=top>Paper Category</td>";
echo "<td width=200px colspan=3>".paperCategory()."</td></tr>";

$second=array('Collo Paper Name','Manufactured Name','Computer Loopup Prefix');
$secondTitles = array('colloPaperName','manufacturerName','cpl');
	
for($x = 0; $x<count($second); $x++) {
	echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$second[$x]."</td>\n";
	echo "<td width=\"200px\" colspan=\"4\"><input type=\"text\" name=\"".$secondTitles[$x]."\" size=\"50\" maxlength=\"100\"></td></tr>";
}

$displayStock = array('Face Stock','Adhesive','Liner');
$displayStockTitles = array(listFaceStock(),listAdhesive(),listLiner());
$displayButton = array(viewStock(),viewAdhesive(),viewLiner());
$displayButton2 = array(addFaceStock(),addAdhesive(),addLiner());
	
for($x = 0; $x<count($displayStock); $x++) {
	echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$displayStock[$x]."</td>\n\n";
	echo "<td width=\"200px\" colspan=\"2\">$displayStockTitles[$x]</td>\n";
	echo "<td width=50px>$displayButton[$x]</td>\n\n";
	echo "<td width=50px>$displayButton2[$x]</td></tr>\n\n";
	}
echo "</table></form>";
}
Post Reply