SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Name of a Form?

  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Name of a Form?

    How do I get the name of a Form?

    I looked in the HTML manual, and it is unclear - to me - if there is a currently supported attribute.

    The Manual mentions something about using "ID"...

    I want the name of each Form in my website, so I can use that to name a $_SESSION variable.

    Thanks,


    Debbie

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    You can retrieve it like any other form variable using $_POST or $_GET.

    It's usually only needed if you are processing multiple forms on the same page. In that case, you only need to check isset($_POST['myform'])​.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    You can retrieve it like any other form variable using $_POST or $_GET.

    It's usually only needed if you are processing multiple forms on the same page. In that case, you only need to check isset($_POST['myform'])​.
    Hang on. You're telling me to look in $_POST - which is what I would have expected - but that still doesn't tell me how my Form gets a name and what that name is?!

    Sincerely,


    Debbie

  4. #4
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    You have to assign it as an attribute in your HTML first.

    Code:
    <form name="myform" method="post">
    <!-- other stuff here -->
    </form>
    Code:
    if(isset($_POST['myform'])){
    echo 'myform was submitted.';
    }
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Force Flow View Post
    You have to assign it as an attribute in your HTML first.

    Code:
    <form name="myform" method="post">
    <!-- other stuff here -->
    </form>
    Code:
    if(isset($_POST['myform'])){
    echo 'myform was submitted.';
    }
    Does that actually work?

    When added name='createAccount' to my Form, and then I echoed the $_POST array, name was no where to be seen!!

    Based on what I have researched, name does not get carried over in the $_POST array and is a throwback to older code.

    Doesn't seem like your code can work.

    (BTW, I think I figured a workaround. I just need to unset($_SESSION['form_token']) AFTER my script has successfully validated all Form data. That way, the Form doesn't need to get reloaded, and a NULL form_token seems to be okay.)

    Sincerely,


    Debbie

  6. #6
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Hm, it looks like I was mistaken.

    The only other alternatives would be to create a hidden field within the form to identify it, or go by the name of the submit button.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The name attribute on forms is not actually used for anything (except for antiquated JavaScript).

    Where you have the same form being submitted for different purposes or different forms being submitted to the same process you need to distinguish between them by the name on the submit button fields. To handle the bug in some IE versions where the submit button name doesn't get passed when the form is submitted using enter it is always the first submit button that gets triggered in that situation so no value passed for the submit button can be treated the same as the value of the first submit button.
    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="^$">


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
  •