Page 1 of 1

Accessing form element Name

Posted: Wed Jun 04, 2008 1:39 am
by bhm8hwcm
I need help trying to access the name of a form element.

eg. Sample 1: <input name="function1_name" type="text" />
Sample 2: <input name="function2_name" type="text" />

When the form is submitted I will use explode() or someother string function on the input Name (eg function1_name). The resulting string, or string portion, will actually be the name of the function to be called to process that value.

In the above example, the value for the first input would be passed to a procedure called function1 and the value for the second input would be passed to function2. The problem is that I am not sure how to access the names of the form elements in my php scripts.

Make sense?

Thanks

Re: Accessing form element Name

Posted: Wed Jun 04, 2008 1:53 am
by Kieran Huggins
if I understand you properly, it's an exceptionally bad idea form a security standpoint :evil:

What you might want to look into the the MVC / router concept. A URL maps to a controller action, with extra URL parameters as arguments.

Example:

Code: Select all

http://somesite.com/controller/action/a ... 2/val2/....
That way a controller (class) named "contorller" would execute the "action" method with specified arguments. This ensures that you make only the methods you want the user to have access to available to the application interface.

There are plenty of PHP frameworks that use MVC, but it's easy enough to roll your own. Chris Corbyn wrote a nice and simple one somewhere with a great explanation; I think it's on his blog.