0

I'm using this HTML code in an HTML page:

<form method="post">
  <div class="form-group">
    <input type="text" class="form-control" name="username">
  </div>
  <div class="form-group">
    <input type="password" class="form-control" name="password">
  </div>
  <input type="hidden" name="ref" value="post-ad.php"/>
  <button type="submit" name="submit" id="submit" class="btn">S'identifier</button>
</form>

On clicking submit button which action will this form execute? I noticed that it execute the value of input named "ref" in this example "post-ad.php" or "index.php" or "dashboard.php". Is it normal?! As I know the action attribute is mandatory?

Argus Duong
  • 2,356
  • 1
  • 13
  • 24
devattitude
  • 21
  • 1
  • 2
  • 3
    without an `action` attribute it will POST/GET to the same page dependant upon `method`. The `action` is not mandatory – Professor Abronsius Dec 05 '17 at 10:04
  • https://stackoverflow.com/questions/1131781/is-it-a-good-practice-to-use-an-empty-url-for-a-html-forms-action-attribute-a Without the action attribute the current page is used. your field named ref is just like a normal input so the value will be available in $_POST['ref'] as a string. – Dennis de Best Dec 05 '17 at 10:04

3 Answers3

3

without action attribute it will POST/GET to the same page see here

Dhiarj Sharma
  • 328
  • 3
  • 12
2

If I understood right you're asking about action attribute that goes inside <form>.

If you put nothing there, it'll send the POST to the same page it is right now. If that form is in "index.php" it'll send all <form> data to "index.php"

0

You call form without action with this code:

<form action="javascript:void(0);"></form>