doubledee — 2013-10-04T12:02:41-04:00 — #1
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.
force — 2013-10-04T13:01:01-04:00 — #2
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']).
doubledee — 2013-10-04T15:25:32-04:00 — #3
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?!
force — 2013-10-04T17:37:00-04:00 — #4
You have to assign it as an attribute in your HTML first.
<form name="myform" method="post">
<!-- other stuff here -->
echo 'myform was submitted.';
doubledee — 2013-10-04T19:05:31-04:00 — #5
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['formtoken']) 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.)
force — 2013-10-04T20:40:42-04:00 — #6
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.
felgall — 2013-10-04T20:48:08-04:00 — #7
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.