How to access the form's 'name' variable from PHP

后端 未结 12 2033
小鲜肉
小鲜肉 2020-11-29 09:07

I\'m trying to create a BMI calculator. This should allow people to use either metric or imperial measurements.

I realise that I could use hidden tags to solve my pr

相关标签:
12条回答
  • 2020-11-29 09:40

    For some reason, the name of the submit button is not passed to the superglobal $_POST when submitted with Ajax/jQuery.

    Just in case it helps someone...

    0 讨论(0)
  • 2020-11-29 09:42

    The form name is not submitted. You should just add a hidden field to each form and call it a day.

    0 讨论(0)
  • 2020-11-29 09:42

    You can use GET in the form's action parameter, which I use whenever I make a login/register combined page.

    For example: action="loginregister.php?whichform=loginform"

    Hope this helps!

    0 讨论(0)
  • 2020-11-29 09:46

    To identify the submitted form, you can use:

    • A hidden input field.
    • The name or value of the submit button.

    The name of the form is not sent to the server as part of the POST data.

    You can use code as followed

    <form name="myform" method="post" action="" enctype="multipart/form-data">
        <input type="hidden" name="frmname" value=""/>
    </form>
    
    0 讨论(0)
  • 2020-11-29 09:48

    You can do it like this:

    <input type="text" name="myform[login]">
    <input type="password" name="myform[password]">
    

    Check the posted values

    if (isset($_POST['myform'])) {
        $values = $_POST['myform'];
    
        // $login = $values['login'];
        // ...
    }
    
    0 讨论(0)
  • 2020-11-29 09:56

    You do realize that with echo $height; you are opening up a very, very serious security hole in your application, right?

    0 讨论(0)
提交回复
热议问题