Home » Php » php – HTML Form Submit To Self

php – HTML Form Submit To Self

Posted by: admin July 12, 2020 Leave a comment

Questions:

Can someone tell me why on earth this is not submitting to self?

I have the following setup:

<?php
     print_r($_POST);
?>

 <form name="bizLoginForm" method="post" action"" >
    <table id="loginTable">
        <tr><td>Username:</td><td><input type="text" id="loginUsername" /></td></tr>
        <tr><td>Password:</td><td><input type="password" id="loginPassword" /></td></tr>
    </table>
    <input type="Submit" value="Login" />
</form>

and every time I click on the submit button i see nothing inside the POST array. What simple thing have I totally overlooked?

Thanks!

How to&Answers:

Aside from the fact the equals is missing from your action attribute in your form element.

Your inputs need name attributes:

<tr>
    <td>Username:</td>
    <td><input id="loginUsername" name="loginUsername" type="text" /></td>
</tr>

Answer:

 <form name="bizLoginForm" method="post" action"" >

should be

 <form name="bizLoginForm" method="post" action="" >

Missing = sign.

You’re also missing the name attribute inside your input tags, so change

<input type="text" id="loginUsername" />

and

<input type="password" id="loginPassword" />

to

<input type="text" id="loginUsername" name="loginUsername" />

and

<input type="password" id="loginPassword" name="loginPassword" />

Answer:

  • You should add equals sign between action and “”
  • Also specify name attribute for each input field.

<?php
     print_r($_POST);
?>

 <form name="bizLoginForm" method="post" action="" >
    <table id="loginTable">
        <tr><td>Username:</td><td><input type="text" name="login" id="loginUsername" /></td></tr>
        <tr><td>Password:</td><td><input type="password" name="password" id="loginPassword" /></td></tr>
    </table>
    <input type="Submit" value="Login" /></form>

Answer:

Try this

<?php
   if(isset($_POST['submit_button']))
      print_r($_POST);
?>

<form name="bizLoginForm" method="post" action"<?php echo $_SERVER['PHP_SELF']?>" >
  <table id="loginTable">
    <tr><td>Username:</td><td><input type="text" id="loginUsername" /></td></tr>
    <tr><td>Password:</td><td><input type="password" id="loginPassword" /></td></tr>
  </table>
  <input type="Submit" name="submit_button" value="Login" />
</form>

Save the file with .php extension

Answer:

try this

<?php
if(isset($_GET["submitted"])){
    print_r($_POST["values"]);
} else {
?>
 <form name="bizLoginForm" method="post" action="?submitted" >
    <table id="loginTable">
        <tr><td>Username:</td><td><input type="text" name="values[]" id="loginUsername" /></td></tr>
        <tr><td>Password:</td><td><input type="password" name="values[]" id="loginPassword" /></td></tr>
    </table>
    <input type="Submit" value="Login" />
</form>
<?php
}
?>