Error Redirect and upload photo - php

Having an interesting time trying to get an upload to work. So here's the thing: I have a form that uses some javascript to pretend it's 3 separate pages. It's all one form, but as you click "next" one section fades away and another section is shown. The last page is the page where you can make the most errors....if you miss a required field or you're trying to sign up with an already used email address the app will kick out an error, but it has to do a:
redirect(/path/to/app#!section2);
to show the correct page where the error is located. I can get all the data back, by quickly putting all the variables into a flashvar. So IF this redirect were to happen I have all the data to show back in the form....except....if you tried to upload a photo, I've lost the photo upload. My first thought was to try and save the $_FILES data to a flashvar, but I don't think that will work.
Anyone see this before? There has to be a way around this.
Thanks

I would make the entire process ajax based so you wouldn't have to worry about preserving data through redirects. You could do all of your validation in your controllers as usual and then either return json or javascript code back to the browser to parse and handle what to do next.

Related

PHP - Browser BACK button crashes the website

I am a newbie to programming. I have a PHP website which works as follows
Index Page - Search Results - Show a Product
The site user enters search critera on Index Page and the page is POSTed to Search Results page. From there, the site user clicks on a Product href that takes him to the Product Details. This is working fine till here.
The problem occurs when the user click the browser BACK button. The Search Result page comes up totally crashed and the user has to press F5/Browser Refresh to re-submit it. Any idea/technqiue that I can use to avoid this crash?
When a browser goes back to a page that comes from POSTing some data, the browser often times needs to re-POST the data in order to get the same page back. Since that can sometimes be bad (e.g. re-POSTing an order form), many browsers require the user to force a refresh with a warning.
You can generally use a GET instead of a POST form to avoid this.
An idea would be using GET for the method of your search form instead of POST (that apparently you are using). That way, even if going back in browser history, your server could re-supply its search results.
You would need the following:
change method="post" to method="get" in your search form
change every $_POST relating to the search form data to $_GET in your search form processing php file.
Of course, it could not work for your specific usecase. That's just an idea.

Get request on button click

here is the challenge, I have a webpage, with a form in it , and the button that corresponds to it of course causes a submit. The other button that I have, essentially must trigger a database call that displays content from the database, on this page.
So technically my mind understands that this button should send a GET request to the server and then I retrieve the necessary information and it is displayed. But syntactically, I do not understand how to pull this off, one way to go about doing it is to encapsulate this button in another form, that has a method called GET, and in my server side, I retrieve my information, encode it and send it back to the client. But the idea of encoding this inside a form does not appeal to me as this isn't a form, all I really want to understand is how I can trigger the GET method by clicking a button.
Thanks!
There are two simple ways to send a GET request. One is as you figured out, a new form that has that button as an input and nothing is wrong with that so I'm not sure what is not appealing to you. The second way could be via link, for example:
Link

Can't post data to self because of design

i have a website that uses a number of containers (div's). In this scenario, we have three boxes down the left side and one bigger box on the right of these boxes. The bigger box on the right is the only thing that changes when a link is pressed, this is done with Javascript.
SO i have the index which is the main layout of the website and i also have the "pages" of the site, so when a link is pressed the main box (on the right) loads the new data.
On one of my pages i want to collect data and then run it through a PHP script that is in the head of the file, but when i click the button i realise it refreshes the whole page and it doesn't run the script on the page with the form.
Anyone had a problem like this, or know of something i could do to work around it?
I'm not really sure what code would be useful for helping me but if you need something just ask.
Thanks for the help
Since you are loading all your content via JS already, you could just POST the form data via AJAX to a PHP script to process, then read the output and either provide an error message or remove the form from the page and show your success message.
How to approach your AJAX call is dependant on what you've used as a basis for the rest of your JS.
Personally I like to use the JQuery library, as it makes AJAX calls (and much more) very simple.
How about you make the page design able to do it. Have the backend be able to spit out the state of the page when it posted.
Or use Ajax to post the data back and set the new state like you do already.

Asychronous Image Upload in a Form

So I have this form that needs to be filled out by the user. In the form, there is a place to upload an image. Currently, the upload takes place when the user hits "Submit" at the end of the form, however, that causes an up to 30 second delay (due to image size).
What I'm wondering is if there is a way to start that upload while the user is still filling out the form, rather than selecting the image, finishing the form, then uploading it. (This way it really cuts down on the time needed, per form)
The form itself already has a dozen other things it's doing to submit the information to the database and such, so i've been looking into using javascript with an onchange event to get into the javascript, and perhaps from there moving back into php to perform the upload, all while not reloading the page.
Any ideas or suggestions?
There really aren't many ways, the most common one is to use an iframe. Something along the lines of: http://valums.com/ajax-upload/
This has worked very well for me:
jQUploader

PHP - create a non-interactive copy of a web page, perhaps PDF?

What I have is a search form that submits to the same page and it fetches the results using an AJAX request.
This uses the POST method and I am trying to figure out a way to try and do something along the lines of having a button to open this page in a new window to preserve the search parameters and results and to allow it to be bookmarkable somehow but I can't really think how to do this.
The other main reason for doing this is because the search results contain links to if a user clicks one and then clicks back all the form parameters are lost, I have worked around this by having the links open in a new window.
Any help, advice and opinions would be much appreciated.
If you do a GET method instead of POST, then the user will get to an URL with its form parameters in it.
It won't have to be ajax anymore

Categories