Enter data in a form to a database

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
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

Enter data in a form to a database

Post by junestag »

Hi,
I've created a form that allows users to submit the form to a database and everything works fine as far as that goes. However, my users have requested an additional 'submit' button at the top of the page called 'save' that allows them to save what they've entered so far (they're not quite done with the record), and then they want to be able to click a 'view record' link/button that allows them to see how the end-user will view what they've entered so far. Is this possible with just php or is some javascript needed?

Either way, does anyone have any ideas on how to approach this problem?

thanks,
sage
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Enter data in a form to a database

Post by califdon »

junestag wrote:Hi,
I've created a form that allows users to submit the form to a database and everything works fine as far as that goes. However, my users have requested an additional 'submit' button at the top of the page called 'save' that allows them to save what they've entered so far (they're not quite done with the record), and then they want to be able to click a 'view record' link/button that allows them to see how the end-user will view what they've entered so far. Is this possible with just php or is some javascript needed?

Either way, does anyone have any ideas on how to approach this problem?

thanks,
sage
Sure, you could do it any number of ways, either with javascript (smoother, no page refresh) or with php. What I would be concerned about is the concept of "saving" the data. They would NOT be doing that unless you actually saved the data in the database, using php. That would be rather a lot of programming, but it's certainly do-able. What I mean is, if you used javascript to merely reformat the data on another part of the page, the data would not really be saved, and if they closed their browser, it would be lost. On the other hand, if you really save the data in the database, a whole new set of issues must be dealt with, such as: what if the user logs off and then logs on again tomorrow, to complete the entry--how will you identify the record that was started? what if the user never returns to complete the entry? etc. So this is not so much a programming question as an application design question.
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

Re: Enter data in a form to a database

Post by junestag »

Interesting point. After hearing your description of it I think I would prefer the JavaScript version. Is there a way that you know of to save data into some sort of JS buffer and then when they click the 'view entry' link/button it opens a new window that shows what they've saved so far - formatted the way a user would see it?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Enter data in a form to a database

Post by Jade »

Well, you could save it all in variables and then reproduce the page in javascript with all the variables plugged into the correct places. Although there's a downside to this as well. Because they'll think they've "saved" the data before they finish the page what happens if they leave it half way through or close it half way through? Then you'd either have to put in some kind of trigger that auto-saves what they have so far. Your best bet in my opinion is either a session or ajax that updates as they enter each thing in.
junestag
Forum Commoner
Posts: 39
Joined: Tue Sep 18, 2007 5:14 pm
Location: Alaska
Contact:

Re: Enter data in a form to a database

Post by junestag »

mmm, i've always wanted an excuse to use ajax. do you know where i might find some samples of ajax code to use for an application such as this?
Post Reply