user523196
user523196

Reputation:

About form submit with javascript

If I submit forms without input(type="submit") and I use a href with javascript, like this:

<a href="javascript:document.form-name.submit();" rel="nofollow">Button</a>

Is a way to check with php what form is submitted? (with input, I use if (isset($_POST['input-name'])))

Upvotes: 0

Views: 182

Answers (3)

cwallenpoole
cwallenpoole

Reputation: 82088

Natively? Not through JS. You'll need to modify the values which are sent. There are a couple of ways to do that:

  • Change the action: <form action="/processor.php?input-name=INPUT!"> Then get the value from $_GET in PHP (warning, this will not work if the request is a get request).
  • Add a hidden input: <input type="hidden" name="input-name" value="INPUT!" /> The value will now be part of either $_GET or $_POST, depending on the action of the form.

Upvotes: 0

Cups
Cups

Reputation: 6896

Just use this temporarily to understand what PHP is receiving from the POST array.

var_dump($_POST);

Upvotes: 0

George Cummins
George Cummins

Reputation: 28936

Include a hidden field in your form that contains the form identification data you desire.

Upvotes: 2

Related Questions