Results 1 to 4 of 4

Thread: [RESOLVED] php Many forms

  1. #1
    Hyperactive Member louvelle's Avatar
    Join Date
    Jun 08
    Posts
    464

    Resolved [RESOLVED] php Many forms

    Hi guys. I have a question.
    If I have many form codes with same name like these:
    Code:
        <form action="reservedata.php" method="post">
            <input type="text" name="Name" />
            <input type="submit" value="reserve" name="button1" />
        </form>
    
        <form action="reservedata.php" method="post">
            <input type="text" name="Name" />
            <input type="submit" value="reserve" name="button2" />
        </form>
    
        <form action="reservedata.php" method="post">
            <input type="text" name="Name" />
            <input type="submit" value="reserve" name="button3" />
        </form>
    And if I click on the submit button, would the result $_POST['Name'] will change depending on the button that I click?
    For example, the three textboxes have different values like "George", "Paul" and "Andrew".
    If I click on the button1, would the result be "George" or if I click on the button 2 would the result be "Andrew"?

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  2. #2
    Hyperactive Member louvelle's Avatar
    Join Date
    Jun 08
    Posts
    464

    Re: php Many forms

    I have a previous thread and if the answer in my question is yes then my problem with the other thread and this will be marked as solve.
    Sorry if I keep on opening many threads at the same time.

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 08
    Location
    Trivandrum, Kerala, India
    Posts
    7,557

    Re: php Many forms

    If the user presses the first button, then the value in that textbox with the button will be available at the server side.

    For example, if the user enter the value "a", "b", "c" in each of the textboxes and presses the first form's button, then the values available in the $_POST array would be:
    PHP Code:
    Array ( [Name] => [button1] => reserve 
    If it was the second button that the user pressed, then the values would be:
    PHP Code:
    Array ( [Name] => [button2] => reserve 
    And for the third:
    PHP Code:
    Array ( [Name] => [button3] => reserve 
    That is, when you access the "Name" element of the $_POST array like this:
    PHP Code:
      echo $_POST['Name']; 
    you will get the value from the textbox belonging to the form, which the user had pressed the button.

    Hope it's clear. Let me know if you are still having trouble understanding it.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD Athlon X2 5200+, ASUS Motherboard, 2 GB RAM, 400 GB HDD, Nvidia 8600 GT 512MB, 19.5" TFT(Wide), Creative 5.1 Home Theater

    Social Group: VBForums - Developers from India

    Skills: PHP, MySQL, jQuery, VB.Net, VB6, Photoshop...

  4. #4
    Hyperactive Member louvelle's Avatar
    Join Date
    Jun 08
    Posts
    464

    Re: php Many forms

    I actually tried it myself and my idea really worked out. Thanks for the reply @akhileshbc
    No more problems so far. I'll marked two of my threads solve and link the solution from the other thread here.

    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

Posting Permissions

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