...

View Full Version : Simple Form Wont Submit to self ... WHY .. its a very simple form LOOK!



maxvee8
03-03-2008, 06:01 PM
hi ivwe got a cookie thing goin on which works i think cause ive tested it but i cant get the from to submit and post the name / echo the name on to the page when it is submitted there fore i dont think it is submitting .. any help

its a simple test form ive made whts wrong lol...

PS . would this be a correct way to not allow some one access to a form for 1 hour if they have alredy submitted the form???



<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cookie Test</title>
</head>
<body>
<?php
$name=$_POST['name'];

if ($_POST['submit'] == 'submit'){
$value = 'Comment Form';
setcookie("TestCookie", $value, time()+3600);/* expire in 1 hour */
print $_POST['name'];
}

if (isset($_COOKIE['TestCookie'])) {
$message.= "please wait one houre before posting anouther comment";
}else{
print "<form name='form' action='".$_SERVER['PHP_SELF']."' method='post' id='form' />
<input name='name' id='name' type='ext' size='30' maxlength='30' />
<input name='submit' type='button' value='submit' />
</form>";
}

print $_COOKIE["TestCookie"];
print $_POST['name'];
print $message;
?>
</body>
</html>

Fou-Lu
03-03-2008, 06:31 PM
There are a few things that could be the problem:

Output Buffering may not be enabled causing setcookie to fail. Check your server logs to see if this is the problem.
I do not believe that cookies are effective before the page is refreshed. Use a header to resend them to this page.

Check those ones out.
Oh, you should also confirm that values exist for your _POST by checking against an isset val. That will allow you to use greater constraints on your code. A few things can be done with this:


print "<form name='form' action='".$_SERVER['PHP_SELF']."' method='post' id='form' />
<input name='name' id='name' type='ext' size='30' maxlength='30' />
<input name='submit' type='button' value='submit' />
</form>";

First, I don't recommend using PHP_SELF as it is open to XSS. Instead, using $_SERVER['SCRIPT_NAME'] in conjunction with any required _GET/_POST requests is a better option (or sending the _GET/_POST through as hidden fields). Because you are using multiple lines as well, if you want to keep your syntax and newlines, you may consider using a heredoc (http://ca3.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) syntax for your output.

Hope that helps point you in the right direction!

maxvee8
03-03-2008, 06:37 PM
LOL ok ill try out sum of those things but most of them ive not herd of, but ill give it my best...

btw could i use a session instead of a cookie or do they get destryed when you leaave the page??? / exit the web site

ok i have had a brian wave ...

Fou-Lu
03-03-2008, 06:52 PM
No, sessions are lost after the user shuts down unless you explicitly add cookies. Cookies are not very reliable either as they can be shut off. Best option would be to use some IP tracking trickery to try and block them.

_Aerospace_Eng_
03-03-2008, 06:54 PM
The original problem was you were using a type="button" rather than type="submit".

maxvee8
03-03-2008, 10:20 PM
ok thanks Aero, i was about to put this little chesnut on the back burner but since its now sortof working .. or not, i get this errror when i submit the form


Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/a/x/maxstanworth2/html/googletestmap/cookietest.php:8) in /home/content/m/a/x/maxstanworth2/html/googletestmap/cookietest.php on line 13

this means ... i cant set a cookie there , or am i doing some thing wrong ... this form is going to be used on a google map to add a marker location to it i just need s way of restricting people to one post per hour...

max

_Aerospace_Eng_
03-03-2008, 10:25 PM
You are right, you can't set a cookie there. Cookies and sessions need to be set before any output to the browser.

<?php
$name=$_POST['name'];

if ($_POST['submit'] == 'submit'){
$value = 'Comment Form';
setcookie("TestCookie", $value, time()+3600);/* expire in 1 hour */
}
?>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cookie Test</title>
</head>
<body>
<?php
if (isset($_COOKIE['TestCookie'])) {
$message.= "please wait one hour before posting anouther comment";
}else{
print "<form name='form' action='".$_SERVER['SCRIPT_NAME']."' method='post' id='form' />
<input name='name' id='name' type='ext' size='30' maxlength='30' />
<input name='submit' type='submit' value='submit' />
</form>";
}

print $_COOKIE["TestCookie"];
print $_POST['name'];
print $message;
?>
</body>
</html>

maxvee8
03-03-2008, 10:33 PM
oh thats sexy i like it... ok ive never used cookies before only sessions so i guess we / i learnt some thing haha, thanks for sorting that out aero, i new it sorta worked just needed re jiggin.. now to concatinate that beast in to java pop up window html google language , oh joy



EDIT : looks like google maps pop up box doesnt like such code god damnit

_Aerospace_Eng_
03-03-2008, 11:05 PM
Why doesn't it like it? What makes say that? Are you getting any errors? Post them here please.

Fou-Lu
03-04-2008, 04:47 AM
The original problem was you were using a type="button" rather than type="submit".

omg, can't believe I missed that :P

mlseim
03-04-2008, 01:01 PM
Another thought .... you might want to use a separate script for setting
the cookie(s), then redirect back. Seems easier to troubleshoot and it
will solve any "header" issues.

By using two cookies, you have a "test" cookie that determines that cookies
are enabled, and a "time" cookie that retains the server timestamp when the
form was first submitted.

If at any time you check the "test" cookie and it's not there, which might mean
someone turned it off, you can decide whether or not to process the form.

==================

About people disabling cookies.

Do a cookie check BEFORE you display the form.
Use another PHP script to set a cookie with a "test" variable.
Redirect back to the form script and check that test cookie.

If the test cookie exists, display the form, otherwise, don't
even display it ... instead, explain that cookies need to be enabled.

==================

I see another problem too.

You're using the cookie expire property to time your one hour limit.

This is a problem because each time they use the form it resets the cookie?
It will never "time out"? You really have no idea when the first form was submitted.

I think you should grab the server's time, $t=time(); and save that as a variable
in a cookie. When you return to your form, if the test cookie is not set, that means they
have cookies disabled, so you automatically don't display the form. If they do have
the cookie set, you check the value of the "time" cookie against the current server time.
If it's off by 3600 (1 hour), you know you've passed one hour.

Don't ever reset the "time" cookie until one hour has elapsed (3600 seconds).

time(); is counted by seconds.

maxvee8
03-04-2008, 01:47 PM
ok mlseim i was thinking the same about the cookie being renewed when the form is submitted ... i ll have to look at this .. but oone of the major prblems is that the form needs to be put inside a google maps windowhtml that pops up on a marker iv been having troble putting PHP script inside these boxes so i had to strip out all my dynamic dropdows from the database too ... so the first problem is really how i can concatinate the php script in to the pop up window ( if thats what its called in this instance). otherwise im tempted to leave the cookie thing which i dont really wan to do.

JavaScript for the comment marker: This shows a HTML form in the window whic works


var marker1 = new GMarker(center, {draggable: true});

GEvent.addListener(marker1, "dragstart", function() {
map.closeInfoWindow();
});

GEvent.addListener(marker1, "dragend", function() {

marker1.openInfoWindowHtml(
"<form name='Submit Crime' action='addcrime.php' method='post' id='submitCrimeForm' />" + "<br />" +
"Name:<input type='text' name='name' id='name' size='20' />" + "<br />" +
"address:<input type='text' name='address' id='address' size='20' />" + "<br />" +
"<input type='hidden' name='lat' id='lat' size='20' />" +
"<input type='hidden' name='lng' id='lng' size='20' />" +
"<label id='labels'>Type Of Crime:</label><SELECT name=type ><OPTION value='Stabbing'>Stabbing</OPTION><OPTION value='Burglary'>Burglary</OPTION></SELECT>" + "<br />" +
"<input name='submit' type='submit' value='Submit Crime' />" +
"</form>"
);

document.getElementById('lat').value = marker1.getPoint().lat();
document.getElementById('lng').value = marker1.getPoint().lng();
});

GEvent.addListener(marker1, "click", function() {
marker1.openInfoWindowHtml("<b>Have your say!,</b><br />Click and drag this marker to a location <br />and submit a comment about crime in that area.");
});

GEvent.addListener(marker1, "openonload", function() {
marker1.openInfoWindowHtml("<b>Have your say!,</b><br />Click and drag this marker to a location <br />and submit a comment about crime in that area.");
});

map.addOverlay(marker1);
GEvent.trigger(marker1,"openonload");


THisis the same code with the cookie script in which doesnt give an error just makes it not show the map so there must be an error some where!


var marker1 = new GMarker(center, {draggable: true});

GEvent.addListener(marker1, "dragstart", function() {
map.closeInfoWindow();
});

GEvent.addListener(marker1, "dragend", function() {

marker1.openInfoWindowHtml(
"<?php
if (isset($_COOKIE['TestCookie'])) {
$message.= "please wait one hour before posting anouther comment";
}else{
print "<form name='form' action='".$_SERVER['SCRIPT_NAME']."' method='post' id='form' />
<input name='name' id='name' type='ext' size='30' maxlength='30' />
<input name='submit' type='submit' value='submit' />
</form>";}?>"
);

document.getElementById('lat').value = marker1.getPoint().lat();
document.getElementById('lng').value = marker1.getPoint().lng();
});

GEvent.addListener(marker1, "click", function() {
marker1.openInfoWindowHtml("<b>Have your say!,</b><br />Click and drag this marker to a location <br />and submit a comment about crime in that area.");
});

GEvent.addListener(marker1, "openonload", function() {
marker1.openInfoWindowHtml("<b>Have your say!,</b><br />Click and drag this marker to a location <br />and submit a comment about crime in that area.");
});

map.addOverlay(marker1);
GEvent.trigger(marker1,"openonload");


so thats the code for the php marker once that has been properly interggrated then i can add sstuff.. ive been trying to add php to a pop up for 2 weeks the only thing i managed to addd succesfully was <? echo date(Y-m-d");?>

hope some ones knows whts goin on to get this thing workin cause that would be awsome!

thanks max.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum