tags:

views:

22

answers:

2

Hello all,

I have a form that the user needs to populate and then the form will be sent to a server. After the user submits the form, if the server script found that the form is not correctly populated (i.e. the uploading file is too big), it should return error to the client side.

Now, my question is as follows:

How do I keep the user seeing the same page without transferring to a different page? Because I don't want the user to waste time to reenter everything again. I just want the user to correct the wrong part.

I also would like to see some tutorials or examples for conveying the basic idea of this topics.

thank you

A: 

You need to show form again and fill previously entered data in input's "value" fields. Of course, don't forget to replace special characters with html entities with htmlentities();

I also found one tutorial for you: http://evolt.org/node/60144

Māris Kiseļovs
+3  A: 

Because I don't want the user to waste time to reenter everything again. I just want the user to correct the wrong part.

This is a good intention, but the wrong solution.

To stay on the same page would mean you have to submit the form using javascript. While possible, why make things more complicated than they have to be?

Instead, submit the form to the server and when you write out the form again to the user with the error message, set what the user entered as the default value on the form. Then it will be there for them and they won't have to type it again.

Note: Don't do this for passwords tho; the page may be cached and then the users password is saved in a plain file on the hard disk. This is why most sites make users retype passwords each time.

James
Hello James,Thank you for your helps.I plan to use Ajax ajaxForm from http://jquery.malsup.com/form/ to submit the form since my form is quite complicated. I don't know whether or not this is a good choice.I like your proposal to rewrite only valid one back to the user. Do you know whether I could find some tutorial to show me how this jQuery + PHP work has you suggested? In other words, I would like to see an example that show me how to repopulate the form with jQuery.Thank you again.
q0987
My point is don't use jQuery. Don't use JavaScript. That makes it complex. Keep it simple. When writing the HTML form, put what the user has already entered into the form in the HTML. <input name="Title" value="This bit of data was entered previously"/> That will work in every browser with no problems.
James