Henry
Henry

Reputation: 35

How to pass variables using PHP OOP

I have a table(1) with a table(2) and this table has a form. This form is intended to be used to sort out items in their groups. This page was build to loop and this looping causes the page to so separate items in their groups.

Because of the way this page was designed, it needs to have a button to update individual row instead of all the records on the table. Anyways, I create a form(2) within the table but because of the way the page was build (not by me), it wouldn't put the contents I want in a form.

I was thinking of using OOP to write a function and have the func. pass anything in a row to button.

e.g. $page->main .= '<td><button value="' . $value . '_' . $domain . '_' . $acayear . '_' . $desc . '" type="submit" id="no" name="insert_Product">Update</button></td>'; and I used explode to separate whatever the function pass to the button before I run an UPDATE statement.

I have no idea if this is possible with OOP because I am still at the beginning stage of learning it. If this is possible. How will I go about doing it.

Summary:

Pass the variables from the select options and input to an OOP class and pass those variables stored in the OOP class to a button which will then separate using PHP explode before updating a table.

I have use PHP explode before but is the OOP class function that I haven't. I am asking two questions here: If the method I am thinking is possible and if so, how will I start writing this code.

I am sorry I haven't post an OOP example code because I have no idea on how to know using it with this method.

Upvotes: 0

Views: 121

Answers (2)

the_pete
the_pete

Reputation: 822

Another solution would be (if your row count is fairly small) to use jQuery and ajax to pass the data to your class to be submitted.

You would have to update your current code so that each id in the table was unique, I make them unique to the row ie: id="dropdown_domain" would be id="dropdown_domain1" for row 1, etc across the row, updating to "2" for row 2... (nice and quick)

And in your right most column you would have just have a with an .click() function that would post the appropriate variables to your class.

Upvotes: 0

Ben Waine
Ben Waine

Reputation: 1648

The approach you have described in your proposed solution is possible. You could consider representing the different elements of your form with objects or properties within an object.

In fact this is the approach many, many libraries have already taken. The advantage of using a library to achieve your goal is you can learn from a well documented solution and the resulting form will be a lot more flexible than the solution you have proposed.

Here are links to two popular form frameworks:

http://symfony.com/doc/current/book/forms.html

http://framework.zend.com/manual/2.0/en/modules/zend.form.quick-start.html

Upvotes: 1

Related Questions