Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts

    Question Simple Form Wont Submit to self ... WHY .. its a very simple form LOOK!

    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???

    Code:
    <!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>
    Last edited by maxvee8; 03-03-2008 at 07:05 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    There are a few things that could be the problem:
    1. Output Buffering may not be enabled causing setcookie to fail. Check your server logs to see if this is the problem.
    2. 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:
    PHP Code:
    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 syntax for your output.

    Hope that helps point you in the right direction!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts
    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 ...
    Last edited by maxvee8; 03-03-2008 at 07:42 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    The original problem was you were using a type="button" rather than type="submit".
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    maxvee8 (03-03-2008)

  • #6
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts
    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

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You are right, you can't set a cookie there. Cookies and sessions need to be set before any output to the browser.
    PHP Code:
    <?php
    $name
    =$_POST['name'];

    if (
    $_POST['submit'] == 'submit'){
    $value 'Comment Form';
    setcookie("TestCookie"$valuetime()+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>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    maxvee8 (03-03-2008)

  • #8
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts
    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
    Last edited by maxvee8; 03-03-2008 at 11:56 PM.

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Why doesn't it like it? What makes say that? Are you getting any errors? Post them here please.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    The original problem was you were using a type="button" rather than type="submit".
    omg, can't believe I missed that :P
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    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.
    Last edited by mlseim; 03-04-2008 at 02:14 PM.

  • #12
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts

    Question

    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

    Code:
    			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!

    Code:
    	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.
    Last edited by maxvee8; 03-04-2008 at 02:59 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •