-5

I'm new here and from another country, so excuse my English.

I'm developing a quite common application. It has a request form and I want to transfer (as usual) the data from the form, into the database. But before that, I want to show to each user, who does the request, what he has put in the form.

Then, with two buttons, the user has the opportunity to go back to the empty form, if he has done a mistake, or (with the other button) to trigger the basic php file, which will insert the data into the DB.

My question is if it is possible to trigger that php file with a simple html button...or I must use AJAX for that?

7
  • You can use either/or. Commented Aug 27, 2014 at 9:13
  • Go back to the empty form? Don't you mean: go back to the pre-filled form? Commented Aug 27, 2014 at 9:13
  • Maybe this link can help. Commented Aug 27, 2014 at 9:17
  • Take a look at AJAX : api.jquery.com/jquery.ajax Commented Aug 27, 2014 at 9:17
  • at that point, having handled preview by javascript, yes, a simple submit button will do. Still... dont you think this is a little too basic to ask here ? Commented Aug 27, 2014 at 9:20

3 Answers 3

1

AJAX is asynchronous which means that without redirection you can send a request and recieve the result. A simple button I assume is your form submit button which can accomplish the task. If you use AJAX you must fill your request with relevant data in the form.

You back button should also send form data to the previous page so you can fill them in and allow edit. Best way to achieve this in my opinion is using javascript to replace edit fields into label (for comfimation) and then submiting the form. Otherwise there will be multiple unecessary redirections.

Sign up to request clarification or add additional context in comments.

Comments

1

You can use two button Submit and Reset as in html. Give your php file name in form as like

<form name="frm" method="POST" action="phpfile.php">
//write the form control (input controls)
<input type="submit" value="Insert">
<input type="reset" value="Clear">
</form>

1 Comment

+1 for providing some code for Constantinus to see.
-1

AJAX is by far the easiest way to do that. Whilst it can be complicated, the jQuery $.post() command makes it really easy to use, and it will act like when you submit a POST form, except that the page will not reload.

You can take a look at the docs at http://api.jquery.com/jquery.post/.

6 Comments

You would still have to handle the posted values, send the response for preview and then confirm the post. This is much easier using 'plain' HTML. Besides, good practice is to make stuff like this work without HTML too, even if you increase UX by assing JavaScript. I therefor strongly disagree that AJAX is by far the easiest way (it is not).
Yes, but then you would need to save the form data for the user to go back to, which would make it more difficult.
You would need to do that anyway.
Not if the page doesn't reload.
Then what are you going to $.post() to PHP then? Where are you going to store the values between the original post and the confirmation? How are you going to rebuild the confirmation page inbetween?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.