Best tool for the job?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jeffrydell
Forum Commoner
Posts: 77
Joined: Thu Jan 17, 2008 4:39 pm
Location: Menasha, WI

Best tool for the job?

Post by jeffrydell »

Sometimes I feel a little like I'm imposing here ... Theory and Design (at least to me) implies a higher level of understanding than my questions, but I can't seem to fit them in other forums.

So - please forgive if I'm a bit elementary here.

As a part of my "project" I need to implement (for lack of a better description) a form which behaves like a spreadsheet.

I've managed to somewhat achieve the desired results with PHP and Javascript - but I'm not 100% satisfied with the performance and I have to seriously doubt that I'm going about this the best way possible.

The form is a Payment Calculator which is customized from client to client. It looks like a standard Invoice with a Quantity on the left, a text description, then the amount for each line calculated on the right.

When the user enters a value on the left, Javascript refreshes the screen and all other dependent values are adjusted before the page gets refreshed. When the user is satisfied that they have completed the form, they click on the Submit button and the form results are POSTed to an array, off we go to the next step.

Any thoughts on what apps / language / etc. I should be looking at to accomplish this in the most effective manner?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best tool for the job?

Post by Christopher »

Given examples like Google Docs, it could certainly be done in Javascript. And PHP would be a reasonable choice to generate the pages.
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Best tool for the job?

Post by Kieran Huggins »

I'm tempted to suggest looking at the "observer" pattern in UI programming. Each cell would register with cells it's value is dependent on, so each time an element updates it can forward a "recalc" command to it's observers.

This can certainly be done in JS, and then just be submitted as a form when the user is done.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Best tool for the job?

Post by Maugrim_The_Reaper »

Kieran looks on the best path - the one word registering as a red flag from your original post was "refresh". I'm assuming changes don't reload the page here all the time until the final version is submitted?
jeffrydell
Forum Commoner
Posts: 77
Joined: Thu Jan 17, 2008 4:39 pm
Location: Menasha, WI

Re: Best tool for the job?

Post by jeffrydell »

Yep - you saw THE red flag! When a value is entered, the page is submitted ... a form action script puts the POST values in an Array then the user is re-routed back to the original script which reloads the page with the array values as defaults and does the calculations to repopulate all values on the screen.

Really inefficient I know, but my skill set could only come up with that solution.

So where can I learn more about the 'observer' pattern?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Best tool for the job?

Post by Maugrim_The_Reaper »

Look at jQuery for example. The idea is that a change, sparks a set of calls to all the form elements (cells) which should now update. It's really a simple architecture - do a trial for 10 cells, then scale it up to your needs. The Observer pattern is well known in programming circles - any language description will provide the salient points. Variation on a theme, all cells could notify a standalone object of it's new value, this object would in turn notify other cells (who registered themselves as being interested in the current cell) of the change - triggering them to update.

You'd have to fill in the order of precedence though - subtotal cells would need to update before total cells for example. I did something a while back using a calc-depth priority system - the earlier in the final total calc a sub-total is, the higher it's precedence for receiving notifications.
jeffrydell
Forum Commoner
Posts: 77
Joined: Thu Jan 17, 2008 4:39 pm
Location: Menasha, WI

Re: Best tool for the job?

Post by jeffrydell »

Thanks for the lead ... the precedence issue shouldn't be too bad. My issue (in this case) is REALLY WEAK javascript skills. I have other issues, but they're not for discussion here. :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Best tool for the job?

Post by Kieran Huggins »

jeffrydell wrote:Thanks for the lead ... the precedence issue shouldn't be too bad. My issue (in this case) is REALLY WEAK javascript skills. I have other issues, but they're not for discussion here. :)
Javascript kicks major ass, jQuery doubly so. I fully encourage you to learn both, they're amazingly useful and will make you a better programmer.

Douglas Crockford's overview is a great place to start (or even restart) your journey: http://javascript.crockford.com/survey.html

Then give jQuery a look, the DOM is hella annoying without it: http://jquery.com
jeffrydell
Forum Commoner
Posts: 77
Joined: Thu Jan 17, 2008 4:39 pm
Location: Menasha, WI

Re: Best tool for the job?

Post by jeffrydell »

Thanks! Good suggestions now ... learn OOP, Javascript, and jQuery, end world hunger, annnnnd watching the Super Bowl. Hmmm ... just a few things on my To Do list this weekend.

I'll be a super-hero too if I can get all that in! :D
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Best tool for the job?

Post by Kieran Huggins »

isn't that what half-time is for?
Post Reply