Php get submitted form name

PHP Form Handling

The PHP superglobals $_GET and $_POST are used to collect form-data.

PHP — A Simple HTML Form

The example below displays a simple HTML form with two input fields and a submit button:

Example

When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named «welcome.php». The form data is sent with the HTTP POST method.

To display the submitted data you could simply echo all the variables. The «welcome.php» looks like this:

The output could be something like this:

The same result could also be achieved using the HTTP GET method:

Example

and «welcome_get.php» looks like this:

The code above is quite simple. However, the most important thing is missing. You need to validate form data to protect your script from malicious code.

Think SECURITY when processing PHP forms!

This page does not contain any form validation, it just shows how you can send and retrieve form data.

However, the next pages will show how to process PHP forms with security in mind! Proper validation of form data is important to protect your form from hackers and spammers!

GET vs. POST

Both GET and POST create an array (e.g. array( key1 => value1, key2 => value2, key3 => value3, . )). This array holds key/value pairs, where keys are the names of the form controls and values are the input data from the user.

Both GET and POST are treated as $_GET and $_POST. These are superglobals, which means that they are always accessible, regardless of scope — and you can access them from any function, class or file without having to do anything special.

Читайте также:  Ajax PHP MySQL Search Example

$_GET is an array of variables passed to the current script via the URL parameters.

$_POST is an array of variables passed to the current script via the HTTP POST method.

When to use GET?

Information sent from a form with the GET method is visible to everyone (all variable names and values are displayed in the URL). GET also has limits on the amount of information to send. The limitation is about 2000 characters. However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.

GET may be used for sending non-sensitive data.

Note: GET should NEVER be used for sending passwords or other sensitive information!

When to use POST?

Information sent from a form with the POST method is invisible to others (all names/values are embedded within the body of the HTTP request) and has no limits on the amount of information to send.

Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to server.

However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

Developers prefer POST for sending form data.

Next, lets see how we can process PHP forms the secure way!

Источник

Get the name of submit button in php

For example In the PHP code, you can do this: Solution 3: Why not do this: and then Solution 1: You could just check in if there is an entry with the name of each one of your three buttons : Note that I’d suggest you give better names (that don’t begin with a number) to your buttons — which means generating your form like this : And, on form’s submission, using something like this : BTW: your loop’s syntax is incorrect — it seems you’ve mixed up and 😉 Solution 2: It would probably make more sense to use the same name and different values for multiple submit buttons.

Читайте также:  Дополнить число нулями python

Get the name of submit button in PHP

You will find the name in the $_POST array.

This way you will see everything in the $_POST array.

You can iterate through the array with:

foreach($_POST as $name => $content) < // Most people refer to $key =>$value echo "The HTML name: $name 
"; echo "The content of it: $content
"; >

‘submitbutton’ is the name of your submit button. you can get the names of super global $_POST array elements with array_keys() function

$postnames = array_keys($_POST); 

Its like any other POST variable, the name will be in the $_POST array. The name is the key in the $_POST array.

Get the name of submit button in PHP, How do I get the name of the submit button in PHP? I got the value of submit button, but I could not find any code to get the name of the button. Below is the code I have written. Code sampleforeach($_POST as $name => $content) < // Most people refer to $key =>$valueecho «The HTML name: $name
«;echo «The content of it: $content
«;>Feedback

PHP Get name value from submit button

Try this: Separate the name with asymbol and then split.

" /> foreach($_POST as $name => $content) < //echo "The TOURNAMENT NAME IS: $name 
"; list($tournament, $round) = explode('_', $name); >

When you concatenate both variables, you can add an unique string that you can use for splitting.

In the PHP code, you can do this:

foreach($_POST as $name => $content) < //echo "The TOURNAMENT NAME IS: $name 
"; list ($tournament, $weekNumber) = explode('|-|', $name); >
if (isset($_POST["tournament"]) < foreach ($_POST["tournament"] as $tournament =>$weeks) < foreach ($weeks as $round=>$value) < //Do stuff >> 

How get (Submit Button’ name) in next page in PHP?, If you can change the HTML, you could use subscripting by changing all submit element names to, e.g., submit[the_name] — this way you could find the name of the pressed submit button by looking at array_keys($_POST[‘submit’])[0].

Читайте также:  PyScript Example

Can I get the name of submit button in another form?

You could just check in $_POST if there is an entry with the name of each one of your three buttons :

Note that I’d suggest you give better names (that don’t begin with a number) to your buttons — which means generating your form like this :

And, on form’s submission, using something like this :

BTW: your while loop’s syntax is incorrect — it seems you’ve mixed up while and for 😉

Generate another input element

And then get your id with $_REQUEST[‘buttonId’]

Php — How to get id of submit type button, when button, You can have many buttons of type=»submit» with the same name (id), and the value will be the one which was clicked, or the first one, if the form was submitted by pressing enter. Share. Improve this answer. The ‘id’ attribute doesn’t submit to PHP, only the ‘value’ attribute submits.

Can I get the name of submit button in another form? [duplicate]

You can examine the $_POST array to see which number was sent through.

How you do that is entirely up to you, it could be as basic as a few isset() checks.

if (isset($_POST['1'])) < echo "Clicked button 1"; >if (isset($_POST['2'])) < echo "Clicked button 2"; >if (isset($_POST['3']))

It would probably make more sense to use the same name and different values for multiple submit buttons.

In two.php you can then simply pull the value of the submit button that was pressed using $_POST[‘submitButton’]

Forms — PHP Get name value from submit button, I have searched for a solution to this problem, the closest I came was this answer, however it does not provide sufficient explanation.. The following button contains BOTH a tournaments name and a tournaments number.

Источник

Оцените статью