Accessing form element Name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bhm8hwcm
Forum Newbie
Posts: 9
Joined: Mon May 05, 2003 10:53 am

Accessing form element Name

Post 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
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Accessing form element Name

Post 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.
Post Reply