SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Rochester, NY
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Curious Submit button

    I have a .php file that contains an html form that begins with this:

    <form method="POST" action="<?php echo $PHP_SELF;?>">

    and has a submit button invoked this way:

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

    I have discovered that the file does not work without including

    name="Submit"

    even though I cannot find another instance of the word Submit in any other statement in the .php file. If I haven't missed a reference to it, is there some reason why name="Submit" is required?

    Also, name="submit" doesn't work either. The string name="Submit" must be in the submit statement and it must be capitalized. I have seen on the Internet .php files that use only

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

    for the submit button.

    I would appreciate any clarification.

    Thank you for your help.

    Jim Adrian
    <snip/>
    Last edited by Mittineague; May 17, 2010 at 20:37. Reason: removing private info for member's protection

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by it "does not work"? As in, the form doesn't get submitted, or what?

    There could be some javascript interfering. Perhaps some "validation" code that accesses the submit button via its name attribute?

    Or of course, the other option is that you missed a reference to it. There could be some kind anti-spam check to ensure the submit button was used by a human user, rather than some robot submitting the form. If there are some included files in your PHP file, did you check in there?

  3. #3
    SitePoint Addict tbakerisageek's Avatar
    Join Date
    Sep 2006
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey jamesadrian,
    This sounds like the method I use to submit data back to the server.

    How I prefer to do this (for simplicity sake), is to have any forms submit the data back to themselves. Before any page out put is sent to the browser, I have a check looking for $_POST['Submit'] (or $_GET['Submit']) being set to the "Value" of the form element. The Value is the text that's displayed on the button, and in your case "Submit Form".

    If the Variable is set to "Submit Form" that would mean that the form was filled out and the button was clicked. In this case, you'd want to then include the php file that evaluates, parses, checks, stores, processes, emails, or anything else you intended to do with the data.

    My own design method for doing this was because I've never been a huge fan of using Javascript/Client-side scripting to do form validation. I keep all the validation happening on the server end, and if there is an error, you can then pass the existing, submitted values back to the page and have them be displayed as the default values. You can also set the Class on the labels or form elements themselves to indicate if corrections need to be made.

    I can gather up some sample code if my rambling explanation on how I use this is not clear. Let me know.

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Rochester, NY
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tbakerisageek,

    Sample cod is always of interest. I'm not ready for a reply other that this because I am still confused.

    Jim Adrian

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,807
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jamesadrian View Post
    I have discovered that the file does not work without including

    name="Submit"

    even though I cannot find another instance of the word Submit in any other statement in the .php file. If I haven't missed a reference to it, is there some reason why name="Submit" is required?
    Somewhere near the top of the page there will be a test to see if $_POST['Submit'] exists in order to work out whether the form has been submitted and if so to process it. If the form hasn't been submitted or if there are errors then it eventually gets to the part of the code where it displays the form.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2010
    Location
    Rochester, NY
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't believe it!

    The very first statement after <?php is

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

    That's where the reference is.

    In a way, it is a fortunate mistake because your answers have introduced me to additional concepts in php and a more specific understanding of how these statements work.

    Thank you all so much for your answers.

    Jim Adrian
    <snip/>
    Last edited by Mittineague; May 17, 2010 at 20:39. Reason: removing private info for member's protection


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
  •