Name of a Form?

How do I get the name of a Form?

I looked in the HTML manual, and it is unclear - to me - if there is a currently supported attribute.

The Manual mentions something about using “ID”…

I want the name of each Form in my website, so I can use that to name a $_SESSION variable.

Thanks,

Debbie

You can retrieve it like any other form variable using $_POST or $_GET.

It’s usually only needed if you are processing multiple forms on the same page. In that case, you only need to check isset($_POST[‘myform’])​.

Hang on. You’re telling me to look in $_POST - which is what I would have expected - but that still doesn’t tell me how my Form gets a name and what that name is?!

Sincerely,

Debbie

You have to assign it as an attribute in your HTML first.

<form name="myform" method="post">
<!-- other stuff here -->
</form>

if(isset($_POST['myform'])){
echo 'myform was submitted.';
}

Does that actually work?

When added name=‘createAccount’ to my Form, and then I echoed the $_POST array, name was no where to be seen!!

Based on what I have researched, name does not get carried over in the $_POST array and is a throwback to older code.

Doesn’t seem like your code can work.

(BTW, I think I figured a workaround. I just need to unset($_SESSION[‘form_token’]) AFTER my script has successfully validated all Form data. That way, the Form doesn’t need to get reloaded, and a NULL form_token seems to be okay.)

Sincerely,

Debbie

Hm, it looks like I was mistaken.

The only other alternatives would be to create a hidden field within the form to identify it, or go by the name of the submit button.

The name attribute on forms is not actually used for anything (except for antiquated JavaScript).

Where you have the same form being submitted for different purposes or different forms being submitted to the same process you need to distinguish between them by the name on the submit button fields. To handle the bug in some IE versions where the submit button name doesn’t get passed when the form is submitted using enter it is always the first submit button that gets triggered in that situation so no value passed for the submit button can be treated the same as the value of the first submit button.