Skip to content
Advertisement

How to access the form’s ‘name’ variable from PHP

I’m trying to create a BMI calculator. This should allow people to use either metric or imperial measurements.

I realise that I could use hidden tags to solve my problem, but this has bugged me before so I thought I’d ask: I can use $_POST['variableName'] to find the submitted variableName field-value; but…I don’t know, or see, how to verify which form was used to submit the variables.

My code’s below (though I’m not sure it’s strictly relevant to the question):

JavaScript

I verified that it worked (though without validation at the moment -I didn’t want to crowd my question too much) with metric; I’ve added the form but not the processing for the imperial yet.

Advertisement

Answer

To identify the submitted form, you can use:

  • A hidden input field.
  • The name or value of the submit button.

The name of the form is not sent to the server as part of the POST data.

You can use code as follows:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement