0

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

@EBenWaine thanks for your reply. do I need to use a framework for any of the solution you are referring to because I ma using a plain notepad++ to do this because this system wasn't set up in a framework and I can't just move it.
These components are from frameworks however you can use them independently by installing them with composer. This then allows you to just use the components you need. It even builds an autoloader for you! - Composer getcomposer.org - Symfony Forms (packagist) packagist.org/packages/symfony/form
thanks. I learn more and more from this website every time I use it
0

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.

1 Comment

this is actually the solution I am trying to use now. thanks. I will come back in the future when I have 15 rep to +1 this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.