devattitude
devattitude

Reputation: 31

HTML tag form without "action" attribute

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?

Upvotes: 1

Views: 4400

Answers (3)

NELSON RODRIGUEZ
NELSON RODRIGUEZ

Reputation: 369

You call form without action with this code:

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

Upvotes: 0

Pavlo Zakharuk
Pavlo Zakharuk

Reputation: 115

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"

Upvotes: 2

Dhiarj Sharma
Dhiarj Sharma

Reputation: 346

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

Upvotes: 4

Related Questions