Jump to content

form not working ; working with $_GET but not $_POST ?


adamriley

Recommended Posts

form.html

 

-----------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>* | Sumbit Form</title>
<script language="JavaScript" type="text/javascript">
<!--
function ValidateForm1(theForm)
{
var strValue = theForm.Editbox2.value;
var strFilter = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
if (!strFilter.test(strValue))
{
   alert("Please enter an email address");
   return false;
}
return true;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" style="scrollbar-face-color:#D4D0C8;scrollbar-arrow-color:#000000;scrollbar-3dlight-color:#D4D0C8;scrollbar-darkshadow-color:#404040;scrollbar-highlight-color:#FFFFFF;scrollbar-shadow-color:#808080;scrollbar-track-color:#D4D0C8;">
<div id="Text1" style="position:absolute;left:127px;top:13px;width:570px;height:32px;z-index:11;" align="center">
<font style="font-size:27px" color="#000000" face="Arial"><u>FootBall Game Card</u></font></div>
<div id="Form1" style="position:absolute;left:20px;top:35px;width:709px;height:374px;z-index:12;" align="left">
<form name="Form1" method="POST" action="submit.php" id="Form1" onsubmit="return ValidateForm1(this)">
<input type="text" id="name" style="position:absolute;left:269px;top:31px;width:381px;font-family:Courier New;font-size:16px;z-index:0" name="Name" value="Please Enter your full name">
<div id="Text2" style="position:absolute;left:49px;top:39px;width:146px;height:16px;z-index:1;" align="left">
<font style="font-size:13px" color="#000000" face="Arial">Name</font></div>
<div id="Text3" style="position:absolute;left:49px;top:86px;width:146px;height:16px;z-index:2;" align="left">
<font style="font-size:13px" color="#000000" face="Arial">Email address <b>(****)</b></font></div>
<div id="Text4" style="position:absolute;left:22px;top:217px;width:664px;height:36px;z-index:3;" align="left">
<font style="font-size:16px" color="#000000" face="Arial">(****)Please note that the email address must be the one you use for paypal as this is were if you winnings if you win will be sent </font></div>
<input type="text" id="Editbox2" style="position:absolute;left:268px;top:82px;width:381px;font-family:Courier New;font-size:16px;z-index:4" name="Email" value="E.g (Pay pal Email address)">
<input type="text" id="Editbox3" style="position:absolute;left:268px;top:130px;width:379px;font-family:Courier New;font-size:16px;z-index:5" name="Code" value="<?php echo $random_number ?>" readonly="readonly">
<div id="Text5" style="position:absolute;left:47px;top:135px;width:161px;height:16px;z-index:6;" align="left">
<font style="font-size:13px" color="#000000" face="Arial">Your Random code <b>(*)</b></font></div>
<div id="Text6" style="position:absolute;left:20px;top:271px;width:664px;height:36px;z-index:7;" align="left">
<font style="font-size:16px" color="#000000" face="Arial">(*)You should keep this safe as this will make sure we are talking to the right person<br>
     2. If you forget this code we reserve the right to refuse payment upon winning!</font></div>
<input type="submit" id="Button1" name="Button1" value="By submiting you aggree to tos and the notes above" style="position:absolute;left:26px;top:328px;width:616px;height:24px;background-color:#D4D0C8;font-family:Arial;font-size:13px;z-index:8">
<input type="text" id="Editbox4" style="position:absolute;left:266px;top:175px;width:376px;font-family:Courier New;font-size:16px;z-index:9" name="Spot" value="<?php echo $_SESSION['dir'] ?>" readonly="readonly">
<div id="Text7" style="position:absolute;left:50px;top:181px;width:150px;height:17px;z-index:10;" align="left">
<font style="font-size:15px" color="#000000" face="Arial">Team your picking</font></div>
</form>
</div>
</body>
</html>

------------------------------------------------------------------------------

submit.php

-----------------------------------------------------------------------------

<?php
error_reporting(E_ALL);
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());

session_start();
// check to make sure there is a session
if(!isset($_SESSION['dir'])){ 
echo "Please contact webmaster as soon as posible";
die();
} else { 
}

$Name = $_POST['Name']; // get the name from the form
$Email = $_POST['Email']; // get the email from the form
$code = $_POST['Code']; // Get the secrity code
$dir = $_SESSION['dir']; // Get who they have picked
$file = $_SESSION['dir']; // Get the dir

$Time = date('h.i.s A'); // get the time

$Date = date('l jS \of F Y'); // get the date


$pfile = fopen("places/$dir.txt","w");

fwrite($pfile, "\r\n$Name:$Email:$code:$Date:$Time");
// header('Location: http://localhost/Game/red.php?$dir');

?>

 

Now the form would submit using the get method but when i change it to post it gives me an error of

Notice: Undefined index: Name in C:\xampp\htdocs\Game\submit.php on line 14

Notice: Undefined index: Email in C:\xampp\htdocs\Game\submit.php on line 15

Notice: Undefined index: Code in C:\xampp\htdocs\Game\submit.php on line 16

 

 

 

Link to comment
Share on other sites

Put

<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>

after the "session_start();" line in submit.php to see what is being passed to your script from the form.

 

BTW, I put your code on my local server and it works fine.

 

Ken

Link to comment
Share on other sites

in google chrome i get this in the source code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Foot Ball Game Card | Sumbit Form</title> 
<script language="JavaScript" type="text/javascript"> 
<!--
function ValidateForm1(theForm)
{
var strValue = theForm.Editbox2.value;
var strFilter = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
if (!strFilter.test(strValue))
{
   alert("Please enter an email address");
   return false;
}
return true;
}
//-->
</script> 
</head> 
<body bgcolor="#FFFFFF" text="#000000" style="scrollbar-face-color:#D4D0C8;scrollbar-arrow-color:#000000;scrollbar-3dlight-color:#D4D0C8;scrollbar-darkshadow-color:#404040;scrollbar-highlight-color:#FFFFFF;scrollbar-shadow-color:#808080;scrollbar-track-color:#D4D0C8;"> 
<div id="Text1" style="position:absolute;left:127px;top:13px;width:570px;height:32px;z-index:11;" align="center"> 
<font style="font-size:27px" color="#000000" face="Arial"><u>FootBall Game Card</u></font></div> 
<div id="Form1" style="position:absolute;left:20px;top:35px;width:709px;height:374px;z-index:12;" align="left"> 
<form name="Form1" method="POST" action="submit.php" id="Form1" onsubmit="return ValidateForm1(this)"> 
<input type="text" id="name" style="position:absolute;left:269px;top:31px;width:381px;font-family:Courier New;font-size:16px;z-index:0" name="Name" value="Please Enter your full name"> 
<div id="Text2" style="position:absolute;left:49px;top:39px;width:146px;height:16px;z-index:1;" align="left"> 
<font style="font-size:13px" color="#000000" face="Arial">Name</font></div> 
<div id="Text3" style="position:absolute;left:49px;top:86px;width:146px;height:16px;z-index:2;" align="left"> 
<font style="font-size:13px" color="#000000" face="Arial">Email address <b>(****)</b></font></div> 
<div id="Text4" style="position:absolute;left:22px;top:217px;width:664px;height:36px;z-index:3;" align="left"> 
<font style="font-size:16px" color="#000000" face="Arial">(****)Please note that the email address must be the one you use for paypal as this is were if you winnings if you win will be sent </font></div> 
<input type="text" id="Editbox2" style="position:absolute;left:268px;top:82px;width:381px;font-family:Courier New;font-size:16px;z-index:4" name="Email" value="E.g (Pay pal Email address)"> 
<input type="text" id="Editbox3" style="position:absolute;left:268px;top:130px;width:379px;font-family:Courier New;font-size:16px;z-index:5" name="Code" value="6812" readonly="readonly"> 
<div id="Text5" style="position:absolute;left:47px;top:135px;width:161px;height:16px;z-index:6;" align="left"> 
<font style="font-size:13px" color="#000000" face="Arial">Your Random code <b>(*)</b></font></div> 
<div id="Text6" style="position:absolute;left:20px;top:271px;width:664px;height:36px;z-index:7;" align="left"> 
<font style="font-size:16px" color="#000000" face="Arial">(*)You should keep this safe as this will make sure we are talking to the right person<br> 
     2. If you forget this code we reserve the right to refuse payment upon winning!</font></div> 
<input type="submit" id="Button1" name="Button1" value="By submiting you aggree to tos and the notes above" style="position:absolute;left:26px;top:328px;width:616px;height:24px;background-color:#D4D0C8;font-family:Arial;font-size:13px;z-index:8"> 
<input type="text" id="Editbox4" style="position:absolute;left:266px;top:175px;width:376px;font-family:Courier New;font-size:16px;z-index:9" name="Spot" value="Stockport" readonly="readonly"> 
<div id="Text7" style="position:absolute;left:50px;top:181px;width:150px;height:17px;z-index:10;" align="left"> 
<font style="font-size:15px" color="#000000" face="Arial">Team your picking</font></div> 
</form> 
</div> 
</body> 
</html>

 

which uses "POST"

 

Link to comment
Share on other sites

would the php bit of the file make a difference?

<?php
session_start();
error_reporting(E_ALL);
srand ((double) microtime( )*1000000);
$random_number = rand(0,10000);
if(isset($_SESSION['dir'])){ 
// Show the form
require($_SERVER["DOCUMENT_ROOT"]."/Game/includes/Form.html");
} else { 
echo "Please contact webmaster as soon as posible due there being no session";
} 
?>

 

Link to comment
Share on other sites

put this

<?php
echo '<pre>$_GET:' . print_r($_GET,true) . '</pre>';
echo '<pre>$_SERVER: . print_r($_SERVER,true) . '</pre>';
?>

after the dump of $_POST.

In the $_SERVER dump, look for the value of $_SERVER['REQUEST_METHOD'] and post it.

 

Also, is there a URL we could go to in order to test your code?

 

Note: I tested with Chrome and your code worked fine there. Did you clear your cache in Chrome?

 

Ken

Link to comment
Share on other sites

I missed typed:

<?php
echo '<pre>$_SERVER: . print_r($_SERVER,true) . '</pre>';
?>

should be

<?php
echo '<pre>$_SERVER:' . print_r($_SERVER,true) . '</pre>';
?>

 

Did you clear the cache in Chrome. I've noticed that Chrome has a nasty habit of showing one thing via show source and using an old copy in its cache.

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.