SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    When is $submit set?

    I am using an if clause to check if a form has been submitted:

    Code:
    if (isset($submit)) {
    
    //my gibberish here
    
    }
    Here's my question, is the $submit variable only set when the user CLICKS on the button (input type="submit") or just when the form data is sent. (i.e. the user presses 'enter', and the browser sends the data)

    So will the user get a never-ending loop if they press 'enter'? or will the if test true?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should either use a hidden variable, or a form field name when checking if the form has been submitted. I am guilty of the same thing. When the user clicks enter, it doesn't pick up sometimes. So your best bet is to check a different variable.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have used:

    <input type="submit" name="submit" value="Submit">

    and:

    PHP Code:
    if ($submit){

    //blah


    and it has always worked for with no problems what so ever...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw, $submit isn't an official variable or anything, it's just a name some people use to name a submit button. For example, the following submit button creates $foo and NOT $submit :
    Code:
    <input type="submit" name="foo">
    
    if (isset($foo)) {
    // form has most likely been sent
    print_r($HTTP_GET_VARS);
    }
    I usually use a hidden form element as well, sometimes the submit button name/value isn't sent, I forget exactly when but perhaps will remember again later. Be sure to keep in mind $HTTP_POST_VARS, $HTTP_GET_VARS, and $REQUEST_METHOD.

    http://www.php.net/manual/en/languag...predefined.php

    Regarding if ($submit) { , this is okay syntax and should work. Something to keep in mind is if $submit does not exist (isn't TRUE), a NOTICE error is created. Although usually supressed, the error exists nevertheless.

    http://www.php.net/manual/en/phpdeve...ernal.e-notice

  5. #5
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I knew $submit was dependent on the variable, I'll just add a hidden form element.


Bookmarks

Posting Permissions

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