I'm a bit rusty in PHP,
I'm curently doing an PHP assignment where a user can select and save listed images/data/values into their own collection.
I have inputted all the data and printed it out in a repeat region with recordset paging.
I'm confused about how I am supposed to save a checked checkbox temporary before submission as there a more then 1 page as I'm using recordset paging to output the options.(Meaning: i have selected 2 values in the first page then i click next page to select balance values and finally submit my selection)
TIA
I have read an article on storing in session , that is the solution I guess, but I wonder how I'm supposed to send the value to the session when chaging the page (recordset paging generated by Dreamweaver)
To clarify the previous answers, you will most likely want to create a new $_SESSION variable for each check-box and associate a boolean with it.
You can store the result of a form post in PHP's $_SESSION variable.
Read this post for more information: Storing Form Data as a Session Variable
Also, there has to a tutorial or something in Google Land.
If you need to save the form results without submitting the form, try a JavaScript/AJAX approach. The idea is that you actually do submit the form, but in a behind-the-scenes kind of way (that is, the user never notices it). Essentially, you're going to want to build a "autosave" functionality. Look at these two posts:
Autosaving Form Input Using Prototype and PHP
AJAX Autosave functionality
They probably won't fit your needs exactly, but they should give you a good idea of what you should do.
Note: both of these posts use a timer to trigger their autosave functionality. I would suggest tweaking the trigger to detect any changes in your form instead.
Store them in _SESSION and process when needed.
Related
I've just started recently to delve into the depths of html/php & co, so basically I'm a noob.
My question is simple: I'm using a php session to store a variable I'm using for an operation on the successive page. This variable is 'id' which is the primary key of my postgreSQL table. The user has a form on the web page in which it inserts the 'id' so as to select a particular row of the database to visualize and modify. Since the operations of visualization and modification are all in successive pages, I wanted the variable to remain memorized through the session (so that it's not required to post it again every time)
$_SESSION[id] = $_POST[id]
The problem arises when on a successive page I try to use a form to modify data on that particular row. I don't want the user to have to submit the 'id' again, so I use a select that involves $_SESSION[id]. But when the user submits the form, $_POST[id] is not specified in that form and its value goes to null. The result is that $_SESSION[id] is null and I cannot access the database using the query.
I found a way to solve the problem, but I find it extremely inelegant. I basically add a hidden section on the form that sends the id variable like this
<input type="hidden" name="id" value="$_SESSION[id]">
Is there a better way to do this?
I really hope my question makes sense to you, feel free to comment for additional info.
Thanks a lot :)
I have a file which displays the resultset of a query. Now there is an option to compare the individual records (maximum upto 4 simultaneously). Problem is when I switch to next page, the previously selected values for comparison are lost (as the same file loads new records afresh, through pagination algorithm). Is there anyway, I could pass the selected values from the first selection and thereon to the final call(of same page). Technology being used is PHP, MySQL & Javascript. Any help would be highly appreciated. Thanks!
This is a shot in the dark without some sample code or a clear explanation of the pagination, but if you are using a form then you can pass the selections to hidden fields, session variables or some other scoped variable. It appears you are using AJAX, but without the code, I can't give you specifics. If you have full access to the code then a click function on the selection of the elements would allow you to pass the variables via AJAX store them via JAVASCRIPT.
If you can provide a few more details, my answer can be more specific. I would have just asked for clarification but I just joined and don't have the 'reputation' for that yet. ;-)
I am trying to develop a registration page which involves three separate information.
First Page will get contact details
Second page - working details
Third page - study details.
How to keep the form data of the previous pages before posting the form?
You could do it with Ajax - multiple divs and hide/show the appropriate ones.
Or you could POST each page and save the data in the $_SESSION global variable until all pages are complete. Then save it all to the database.
While the other answers are certainly good ideas, you may also want to consider persisting the intermediate data to your database between each page. So, submitting the first page would create the new row, with the columns relating to contact details populated, and a status column set to a value indicating that the submission is not yet complete.
The second page would update that record in the database. The third page would also update the record, as well as the status flag to indicate the submission is complete.
The main benefit to this is that the user can walk away after the first (or second) page, and then return to it later, even if he had closed his browser and his session had expired. (As long as he has a unique URL to return).
This approach might not have a lot of benefit if you are only collecting three pages of data, but if you had many pages, the ability to leave and return later might be more important.
You should take a look at http://jqueryui.com/demos/tabs/, it should be able to do what you need.
While shifting to another page, you just put the values of first page variable in sessions, then you can access the value of previous page at any page, then post the value to the database query. In this way, you can use the use the value of first page at third page, up to when browser is open. As the browser close then variable lost their values.
Back in the day, I would've put hidden fields for all of the previous pages in each subsequent page, so the final submit would have everything... i.e.
Now, I would probably only have one actual page.. with multiple steps implemented by showing/hiding div's and collecting all of the data in one big form, broken up visually for the user... and if I was feeling especially frisky, with frequent validation and final submission through ajax.
I'm looking to create a multi page ordering form the first page would contain some dropdown and text fields, the second page would contain more text fields, the third page would be an order summery with paypal payment option.
I'm just wondering what the best way to create this order form is. I've used sessions in the past but never with users entering in text and picking items from drop downs, does anyone have any resources for doing this? Or does anyone know of a jquery or other ajax example or plugin I might be able to use and modify.
any insight would be a big help.
thanks
The simplest technique might be to use hidden form fields to carry fields from previous screens through to the final screen.
Just make sure you validate all the values when the final screen is submitted to make sure that the user hasn't twiddled the data.
You don't need to do pagination at all if you don't won't to. Just use css to show/hide the "pages". It doesn't sound like you have to save the "state" at any point.
But if you want to do multiple pages, use a session or a cookie to track the user. Then save the data to a database a mark it as incomplete. On the final page, retrieve it all and show it on the page. The server can't tell if a request is ajax or not, so it doesn't matter what you use for submission.
I want to do a search with pagination, but I don't know how to 'store' the data in the $_POST array, should I do it with sessions?
Rolensen
If you are doing a search, you are trying to GET data from the server, and not send data to it -- which means you probably should use GET, and not POST.
Also, it would allow your users to bookmark the result pages (or send those links by e-mail, IM, ...), which is always nice ; and, also, use the back/forward buttons of the browser without getting an alert box, which is nice too ^^
(Oh, and, BTW, it would help solve your problem ;-) )
Yes, you can use sessions or hidden fields and even better GET method in your form.
It is possible to use both GET and POST in form, just add appropriate attribute method to form tag:
<form action="index.php?page=5" method="POST">
So the pager links are submit buttons while rest of the data is stored in hidden fields. But that's not a good way to do this because you cannot pass someone link (on IM for example) to your search results.
But the best way is to store somewhere POST input data (look here: http://www.symfony-project.org/plugins/, when you input your query once, it is stored and remembered so you dont need to fill form multiple times)