Tom Blacknell
Tom Blacknell

Reputation: 27

HTML form POST method not working (despite URL params showing)

Got a form setup to submit some stuff.

There are three submit buttons, all with the same name (choice) and different IDs (1, 2 & 3).

Using POST method to submit the form to form.php

Form.php loads and I can see the form params in the URL.

However there is no POST data coming in.

Index.php:

<form action='form.php' action='POST'>

<input type='hidden' name='index' value='".$cell_count."'>

<div class='btn-group btn-group-m'>
  <button name='choice' value='1' type='submit' class='btn btn-default btn-danger'>
    ...
  </button>

  <button name='choice' value='2' type='submit' class='btn btn-default btn-warning'>
    ...
  </button>

  <button name='choice' value='3' type='submit' class='btn btn-default btn-success'>
    ...
  </button>
</div>

<button name='choice' type='submit' value='4' class='btn btn-default btn-sm'>
  ...
</button>

Form.php :

<?php

  var_dump($_POST);

  if($_POST['choice'] == 3) {
    echo "Chose 3";
  }
  else if($_POST['choice'] == 2) {
    echo "Chose 2";
  }
  else if($_POST['choice'] == 1) {
    echo "Chose 1";
  }

 echo "index: " . $_POST['index'];

?>

Result :

https://i.sstatic.net/JrB7j.png Thanks for any help you can offer!

Upvotes: 3

Views: 2529

Answers (3)

Locke
Locke

Reputation: 671

The action isn't supposed to be post, the METHOD is post.

<form action='form.php' method='post'>

Upvotes: 1

War10ck
War10ck

Reputation: 12508

You're form should be using method="POST". The fact that you are seeing the parameters means that your form is submitting as GET.

The form code should be:

<form action='form.php' method='POST'>

Upvotes: 2

jeroen
jeroen

Reputation: 91792

You are mixing the attributes:

<form action='form.php' action='POST'>

Should be:

<form action='form.php' method='POST'>

Now you don't have a method attribute, so the form is sent by GET (the default).

Upvotes: 8

Related Questions