add more values in the same form using php - php

I am working on Reservation System
I have a Form that Enters Information about a Voucher
The Voucher can have one Group
and that one group can have many passengers
Now what i want to do is that Take all the information about a Voucher in the same form and add everything related to that voucher in database once Everything is entered by the user.
how am i planning to do it:
I have placed an Anchor tag that says "Add more Passengers" and onclick() function will be called that will reset those fields and then ajax will go to an php page and save those values somewhere temporarily that temporary place/variable should be Global or super Global cause i have to access them all when i have to finally add everything to the database at once
but the problem is where do i store those values that were previously entered by the user
I really hope i have made my question clear, any help would be great and really thanks in advance

Store the data in the Session. See http://php.net/manual/en/features.sessions.php

I'd recommend saving the data incrementally into the DB each step of the way. This way your session remains light. The session is really meant for data that must be stored there for easy access on all pages.
The only downside to this is that if the user gets 3/4 of the way through the forms/pages, and quits, you have a row with incomplete information. I'd argue that this is a good thing to keep, and then you can prompt them to "finish what they started" later when they log back in!
So you see, there is no need to temporarily save anything. Just REALLY save it in the DB, exactly where it should go. On your next pages, your form can UPDATE MySQL instead of INSERTing.

Related

How to get website to remember choices to be inputed in to a form

I'm looking for a way to create a page with items on it where each item has a button which can be clicked to "like" or "choose" the item. The website would then remember the choices and input them to a form on another page. Is there anyway of doing this?
At first glance if we are talking about a registered user, i would create fields in the database for the user's input and store its value everytime he makes a selection. Then its only a matter of putting those values wherever you want.
You have several choices. If it is persistent data, I'd suggest a database like MySQL. If you don't have access to that, then Google for "flat file database" and you'll find some great ideas.
If the data is persistent, but not a big deal if it gets deleted or spoofed, you can use cookies.
If the data is fleeting (it goes away at the end of the visit), then use sessions.
The best way to do is storing each result in a SESSION and reusing it in other form.

architecture help with a website in php

I am helping to make a website in PHP which is an ERP purpose website. We made mockups of a form to collect user details which is split into 4 screens facebook style where the end user keeps clicking next after filling in each partial form. Finally they get the preview and confirmation receipt is generated.
How should I go about this in the backend, I am sure that after the preview I will write the values to the Mysql db and generate a receipt. My question is how do I go about storing the values before the preview?
you can use php sessions to store the variables in a session and then at the end store them all in the database.
http://php.net/manual/en/features.sessions.php
You cannot really answer your question in isolation. It really depends on how your user is going to use the system, whether the information they enter should be persistent, and even whether you know who the user is?
Assuming you know who the user is, and you want to keep failed sessions, my suggestion would be to store the partial responses in a database so you can always access them later.
You can then populate or re-populate the form as you wish. You should also have a "start again" button in this scenario.
More information would help give a better answer.
You can just have one form per screen/page and send these values as parameters to the next page via post or get - it's the most simple way
It is also possible to keep all the form markup on single page and divide form into steps using formToWizard jquery plugin.
http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx
This way user has all data available when users clicks and back and forth during the steps and you can just have single submit button.

PHP pages that store information between forms so that the form information is stored before submit

This is inside a PHP website form.
An example is like:
First page:
-Username:
-Password
Second page:
-Email
-[Checkbox]
Thirdpage:
-Contact Details
-Address
Fourth page:
Review all of the above forms in hard copy but with a back and forward command so that the user does not loose any information when switching between these pages.
Please post.
You could use cookies and do your own sessions with MySQL too. I like doing it like that because the data is easier to access if necessary.
Or you can pass the previous variables to the next page though hidden form elements.. but that can get messy.
You Have to use session. I like Zend_Session.
If you want users to be able to come back later and complete the form (assuming you have some kind of login system, or a way to recognize users), you could still save the data into a database. Make another table, temp_submissions. Keep data in it until the user completes the form and commits the data they send. Once committed, clear the data out of the temp_submissions folder and insert it into the "permanent" table. It may not be practical in this case, or total overkill, but it's an alternative to sessions and cookies.

saving form data to database

I am new to PHP, so I am looking for some input on how to make my project a little simpler.
I have a form in which a user can create a list of song, the Submit button then sends it to an intermediate page that saves it to a MySQL database for later use, the intermediate page then forwards them on to the final page that shows them the lyrics of the songs in the order that they chose them.
Originally I had the intermediate page and the final page combined, but ever time a user refreshed the page it would resubmit the data to the DB. What I have works, but it seems like there should be an easier way to accomplish this.
#micahmills: An easier way of stopping duplicate data from being added to the database? Well, it would depend on what you'd consider "easier" -- less code? Less steps? Something else?
What you could do is generate a unique hash or token that submits with the form. This token is then stored in a session after successfully inserting to the database. Attempts to repost the form will then fail because the token sent with the form will be the same as the one stored in the session.
Redirecting to another page after posting to the database is still one of the best and simplest ways of preventing duplicate data being posted though.
Best practice is to redirect after database operation to success / failure page.
You can have form & intermediate combined and a final success page, on failure you need to return back form.

How do you recommend I pass data from one form to another, and finally to another final page?

I'm taking a class in PHP and I'm a real newbie when it comes to best practices and whatnot.
I have a little homework that the teachers wants me to hand in.
Create a form that asks a user for his name, last name, age and birthday.
When the users clicks submit, take him to the second form and ask for his location, nationality and religion.
Finally when he submits that, take him to a 'thank you' page showing all the written information he input previously.
I'm thinking about using GET to pass things along, but I've only done this with one form to another, not multiple 'hops'. Would this work?
What other way do you think I should do this? I'm not sure if this should be community wiki because I'm sure there's a perfect answer, but please let me know and I'll change it.
Thank you SO. :)
You need sessions. Sessions store an ID on the computer, (sometimes in a cookie) that references information on the server. You just create a session, and then you can put whatever data you want in it. Just grab that data on another page whenever you want.
page 1
session_start(); // start session
$_SESSION['name'] = 'Jimmy'; // put something into the session
And on the next page...
echo $_SESSION['name']; // echos "Jimmy"
session_destroy(); // don't want the session anymore
More info at http://w3schools.com/php/php_sessions.asp
Use session.. Make sure you clear it when you are done saving the data.
when rendering the second form you could include all the fields from the previous form as hidden fields.

Categories