I have a booking form that submits the chosen information to a PHP file that displays it in style with the theme on the left. The user then has the option to log in or register on the right hand side.
The problem is that if they log in or register the information that was submitted by the form to the PHP file is not there once the form submitted for signing in is complete.
I am well aware of the reason why, the question however is how to get around it.
Submitting the form data again with the log in form would be the best option but I cannot locate the file that the form submits to. The url is, ?action=login&instance=1 and ?action=register&instance=1 respectively. Any ideas chaps.
I will provide you with the link for the working example, however it is rather long winded as you have to submit certain forms to get there. Go To www.divethegap.com/update/diving-trips/adveture-training Then CLICK on beginners, choose anyone of the dates you see and press continue. Then you are there.
Many Thanks,
Many Thanks,
Why not just store the data from the first form in a $_SESSION variable? This is the cleanest, most flexible, and easiest way to pass data between multiple unrelated pages, especially when the data changes. Here's the general process.
Get variables from form 1 (adventure training form?)
Do normal form actions (validation, whatever
Put form variables into $_SESSION (e.g.: $_SESSION['tmp']['adventure-training-form'] = array('somefield' => $blah, 'someotherfield' => $foo, 'etc' => $yaddayadda);)
User either logs in or registers.
At the end of either process from step 4, get data from $_SESSION['tmp']['adventure-training-form'] and do whatever you need with it
Related
I am trying to understand if the following scenario is possible:
a .PHP page that has a form and inputs for the user to submit information
The page itself offers several different languages for the user to view it in
The user can change languages but the form and the inputs retain their values (if the user has added information) - so the page cannot be re-loaded (as it would lose the information)
I think this might be achieved using an Ajax solution but I'd appreciate any thoughts or advice.
You actually want to change the page, so reload might still be the best choice. Otherwise you need to change every string on the page with javascript, which can get tedious.
You can do the reload without loosing the data. Just add the language information to the form and send another parameter to avoid the actual action that would normally happen when you send the form on the php side. Render the page in the new language and insert the transmitted data in the form.
Hi really hoping to get some help with a complex form issue.
I am building a real estate site where the agents will be able to log into an admin page and upload new houses that are for sale in an HTML form. I have a multi 3 page form that has Listing Info, More Listing Details and a Photo upload page. I have created these 3 pages and a nice css tab navigation to switch between the 3 pages. My issue is I would like the agent to be able to go back and forth between the 3 pages and have the data stay in the form. However if this is a brand new "Listing" then the form would be completely blank. I have the forms set up to submit through php and enter data in a mysql DB and then send you to the next page in the form.
The only way I can come up with is to have if statements that check session variables to see if a "listing_id" variable has been set. If it has it creates a form and fills in the blanks with the data from that pending "listing_id" if not it just creates a blank form. Is there an easier way to do this??? I would like to stick with PHP and HTML however simple JS would be ok too. Thanks for any incite anyone can give!
Whoa whoa whoa. Not sessions. No .. hell naw.
A very simple solution is to make it so the tabs are only visual. Don't throw away the HTML, just hide the container and show another. This way, when you go back, your data is still there.
I would save a cookie on their end with the data they have most recently put in and only clear the cookie once they have completed the form. Then you can use this data to fill the form.
For example,
Imagine the form data from their last inputs were separated by colons ":"
$prevform=$_COOKIE["lastform"]
$data=explode($prevform,":")
All the form data would be separated and reusable by setting the value of each input from $data[int]
I have an application in which I display a form so a user can search for client records based on last name. After entering search parameters, the record or records (there could be multiple clients with the same last name) are displayed. I then want the user to be able to select a client record, possibly with a radio button, and hit one of two buttons: Display details, or Create Reservation. The Display Details button should cause a new display with details of the selected record. The Create Reservation button should cause a new form, with its own handling, to be displayed.
Now, I know I can set things up according to this login
<?php
if (display button was pressed)
{
php code to retrieve more data and display details
}
else if (create reservation button was pressed)
{
php code to generate and display the reservation form, with appropriate handling
}
?>
display the original form with the search results
The problem is, I end up with really ugly, hard to read code because the php code to generate and display the reservation form is lengthy, and needs its own validation, database interaction, and form handling. The code, to my Java-oriented eye, looks ugly and non-modular. Plus, the code for handling the reservation form is icky, with lots of flag setting to determine if we are in form entry mode or form handling mode. I would like a much cleaner way to do this. So my question is, what is the best practice for handling the situation where there are multiple buttons and the action associated with each button is complex?
I could call a function, obviously, but I still end up with the ugly flags determining which state the script is in (are we displaying the reservation form or handling it?). I could create another php file and include it, but the ugliness persists. Or, I could use header, and pass the client record id in a session variable to the new php script. But that would mean a second, unnecessary retrieve from the database to get the client information again.
All the code examples I see on the web show very simple processing after a form button is pressed. What is the best way to do complex processing and displaying a second form based on a button press?
Have you considered using a framework like Laravel for your site. It would seem to me that you must be doing this "manually". With the complexities you described, having a system with routes and "build-in" functionality (like Eloquent ORM) might serve to simplify things for you.
I would go for using ajax and a rich jQuery plugin (or some other framework) to do what you want.
Basically you will handle lists and the functionality that you mentioned with the php reading data and jQuery scripts to dysplay it. And the information that you have to show would be through ajax. Or when you want to edit.
Here is a cleaner example of what you need:
http://jqueryui.com/dialog/#modal-form
I have a database app written in PHP (jQuery/JS on the front end) that has bilingual labels/text. Currently one can only change one's language on a maintenance page (form submission, then PHP updates a session variable with their new language choice), but the users would like me to add a language pulldown that would appear in the corner of all pages. When the page contains a form, I don't want users to lose their partially entered data if they happen to change the language, so I need to save/restore the form data somehow. Is there an easy way to do that? I know I can use jQuery to serialize the form, but then what? Send that added onto the URL and pick it up in PHP? Then what? Write some routine to loop through the form fields and handle them properly (inputs, selects, radio boxes, etc. are all different)? It seems like there should be an easier way. I don't mind restricting myself to HTML5-supported solutions or adding jQuery plugins.
How about localStorage?
If user has filled any input fields, save them to localStorage and delete the data after user submits the form.
My suggestion is to:
Submit the Language and any wanted user data when changing language to the server using $.ajax or $.post
I have searched over SO for quite awhile so I apologize if a similar question is asked and answered but I don't believe there is.
I am using a PHP validation script and jQuery Validate to process all of the forms on my site. With known fields, no issues. However, there are pages which a user can enter additional person(s) information.
A user is asked to enter his family member's names in a form. The user can submit the form or choose to add additional family members to the form. I have not quite figured out how to properly cycle through all the fields and display unique messages based on the users input in jQuery but know I can do so with metadata and the validation plugin.
My issue lies with PHP. I can take each array and run though foreach loops, however, if an error is found in ANY field, an error is generated and the form is displayed again with all fields' previously entered data. I am unable to determine how to point each field's original data to it given the fields are built dynamically when errors appear.
The SIMPLEST METHOD I can come up with for demonstration is this:
A user must enter the percentages of pie he wants his friends to eat.
He must give out 100% of his pie. The user can choose to dynamically
add friends to his pie eating extravaganza but each person must
receive atleast 1% of the pie and they must all together eat 100%.
Sample code
I have created a sample script here which shows the form setup but obviously there is no PHP backend to test. You will need to use your imagination the backend works (I have added into the comments in the html). The same principle would apply with PHP SESSION variable since this data would need to be passed from page to page (if a user revisits this page, the amounts entered for each piece of pie should display). Also, I think it goes without saying but this data MUST BE validated server-side.
Will you not be reloading the page in the event of a PHP error? In which case you know the index of the error in the foreach loop, saved off to some variable - most likely an array to handle multiple errors. When you print the options back out and you are looping through the submitted array again can you not add an additional css class to the text box when you reach a count that is in your error array.