Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple forms on page and using classes. How to structure?

train of thought needs bump

2:42 pm on Feb 16, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 5, 2009
posts: 43
votes: 0

I started using classes in php. Fun!

I now have a form, which is generated by a class. Submitting this form (with ajax or method=post and a submitbutton) raises a problem for me.

Usually, i have the current page in the 'action =' and if a certain condiion is met, a function on a 'functions.php' is executed.

Now that i use classes, i would like to have all intelligence out of the pages and into the class. (Please don' tell me to start using a 'real' language :)) I would love to have this:
<form mehod="post" acion="$object->function()" >

But that's not possible. So how to proceed. I do have a lot of separate forms on that page, and on all other pages (don't ask me, it's a trial-thingy). I woul not like to post on every page a number of conditional statements asking: if this form has nbeen submitted, then please do this, but if it was he other form...

I know i don't give much o go on, but that's bcs it's a bit vague in my head atm.
Any suggestion is welcome.


4:54 pm on Feb 16, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts: 3123
votes: 0

The HTML action attribute takes the URL of the page you want to send the form data to, which can be the current page or any PHP file that is set up to process your form data. This is the same, whether you are coding using classes or functions.

You probably want to set the action attribute to the same PHP script that is instantiating your class that generates your form?

5:02 pm on Feb 16, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 5, 2009
posts: 43
votes: 0

Yes, and that is what i did.

I would be so much happier with it, though if there were anoher way of dealing with it :-)

It's like the code is 'broken' already, by not having all intelligence in the objects themelves. So i was wondering if there was another way of thinking to which i an not used to.