• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

help with self post

i have a simple form and am trying to get it to self post and print the value. just not sure why it is not working quite right. i want the user to enter a code, run php code on it and print to screen in the last message variable.
<?php
//declare variable and set to empty
$message = "";
//get postback
if(isset($_POST['submit']))
{
	//get form data and clean it
    $voucherCode = check_input($_POST['txtbxVCode']);
    //populate variable with form data
    $message = $voucherCode;
}
//run process to clean form data
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script type="text/javascript">
//validate the form
function ValidateForm()
{
	//validate txtbxVCode
	if(document.vcodeform.txtbxVCode.value == "")
   	{ 
    	alert('You must indicate a voucher code.') 
      	document.vcodeform.txtbxVCode.focus(); 
      	return false; 
   	}
return true; 
}
</script>
</head>
<body onload="document.vcodeform.txtbxVCode.focus();">
<form name="vcodeform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table cellpadding="0" cellspacing="0" style="width: 15%">
	<tr>
		<td>Redeem Voucher</td>
	</tr>
	<tr>
		<td>
			<input name="txtbxVCode" type="text" id="txtbxVCode">
		</td>
	</tr>
	<tr>
		<td>
			<input name="btnSubmit" type="submit"  id="btnSubmit" onclick="return ValidateForm()" value="Submit">
		</td>
	</tr>
	<tr>
		<td>
		<?php 
		  //print form data
		      echo "voucher code: ".$message; 
		?>
		</td>
	</tr>
</table>
</form>
</body>
</html>

Open in new window

0
vicomin
Asked:
vicomin
  • 2
1 Solution
 
Greg AlexanderLead DeveloperCommented:
Your checking

if(isset($_POST['submit']))

but your button name is btnSubmit

so should change the button name to submit or the call to:

if(isset($_POST['btnSubmit']))
0
 
vicominAuthor Commented:
lol -- always the little things....
0
 
Greg AlexanderLead DeveloperCommented:
I hear ya :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now