-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?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You can use either/or. – Funk Forty Niner Aug 27 '14 at 09:13
  • Go back to the empty form? Don't you mean: go back to the pre-filled form? – GolezTrol Aug 27 '14 at 09:13
  • Maybe this [link](http://bit.ly/1p867LB) can help. – Alex VII Aug 27 '14 at 09:17
  • Take a look at AJAX : http://api.jquery.com/jquery.ajax/ – SBD Aug 27 '14 at 09: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 ? – Tuncay Göncüoğlu Aug 27 '14 at 09:20
  • @Constantinus - this was probably a good beginner question. Don't be put off by the rudeness and the down votes. Some folks on Stack Overflow have a bad reputation for "I know more than you" and they get offended when someone asks a question they consider beneath them. They also close for irrelevant reasons, so don't be surprised if the question is closed as "Unclear" even though your question is clear. Also see [Could we please be a bit nicer to new users?](https://meta.stackexchange.com/questions/9953/could-we-please-be-a-bit-nicer-to-new-users). – jww Aug 27 '14 at 09:57
  • @jww It was closed as 'too broad'. For me the reason to choose that, is because the question basically asks us to choose between two technologies, without OP having explored them himself (or so it seems). It looks to me like the he asks explanation on how to handle forms in the first place, which I think should be better learned from one of the many tutorials. But based on the interpretation, 'unclear' or 'opinionated' could be proper closing reasons as well, especially since every commenter and answerer seems to have a different interpretation of the question. – GolezTrol Aug 27 '14 at 12:26

3 Answers3

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.

Arijoon
  • 2,184
  • 3
  • 24
  • 32
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>
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
Nishath
  • 11
  • 3
-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/.

Zak
  • 1,910
  • 3
  • 16
  • 31
  • 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). – GolezTrol Aug 27 '14 at 09:23
  • Yes, but then you would need to save the form data for the user to go back to, which would make it more difficult. – Zak Aug 27 '14 at 09:26
  • You would need to do that anyway. – GolezTrol Aug 27 '14 at 09:26
  • Not if the page doesn't reload. – Zak Aug 27 '14 at 09:27
  • 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? – GolezTrol Aug 27 '14 at 09:29
  • I'm not aware that the question included any sort of confirmation. It appears to me that the features wanted in that regard are a placeholder and an option to reset the form. – Zak Aug 27 '14 at 09:31