2

I have question regarding form submit. I have this simple form on processFabrication.php to submit all the variables then process it to the database in another page called processExceededQty.php

Co, in processFabrication.php, I have

 echo "<form action='processExceededQty.php' method='post'>";

When I click submit it goes to the processExceededQty.php.

What I am aiming to do is,

  1. When user click submit, display confirmation yes/no with popup
  2. After user click yes with the confirmation window, stay in processFabrication.php but methods in processExceededQty.php is still executed.
  3. When user click no on the popup, go back and don't do form action

Any help would be greatly appreciated.

Jenz
  • 8,280
  • 7
  • 44
  • 77
Chriskonz
  • 199
  • 1
  • 3
  • 12

3 Answers3

3

Something like this in your javascript:

function doSubmit(){

if (confirm('Are you sure you want to submit?')) {
    // yes
    return true;
} else {
    // Do nothing!
    return false
}
}

add the onsubmit to your form in html:

<form action='processExceededQty.php' method='post' onsubmit='doSumit()'>
AssemblyX
  • 1,841
  • 1
  • 13
  • 15
  • it works like charm but how do I stay withour redirecting to the process page ? – Chriskonz May 24 '14 at 05:00
  • @Chriskonz..You can submit the form to the form page itself without passing values to another page. Otherwise you can pass values to another page and after it, redirecting back to the form page – Jenz May 24 '14 at 05:01
  • if you want to sumbit values and not leave the page you need xmlhttp request, this example will allow the submit to pass by return true and stop it by return false – AssemblyX May 24 '14 at 05:04
  • you have to use AJAX to submit data without returning on action page. – shyammakwana.me May 24 '14 at 05:06
  • http://www.w3schools.com/xml/xml_http.asp will explain how to submit without leaving the page – AssemblyX May 24 '14 at 05:07
2

Addition to @N0M3 answer. Include below script in your <head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

and slight change in your function

function doSubmit(){

if (confirm('Are you sure you want to submit?')) {
    // yes
     $(this).submit(function(e){
        e.preventDefault();
     });

    jQuery.ajax({
        url : 'processExceededQty.php',
        data : {'username':username}, // where first 'username' is your field name, and second one is your field's value
        method: 'post',
        success: function(data) {
             // data is variable which has return data from `processExceededQty.php` 
             // do whatever you want with data
        }
    });    


} else {
    // Do nothing!
    return false;
}
}
shyammakwana.me
  • 5,562
  • 2
  • 29
  • 50
0

Use function on the "onsubmit" of the form like below,

<form action='processExceededQty.php' method='post' onsubmit='reutrn show_pop_up()'>

And on script you ca write following

<script>
   function show_pop_up()
   {
      // show pop up
      if(op_up_return =="Yes")
          return true;
      else
          return false;
   }
</script>

Hope this will help.

Purushottam zende
  • 552
  • 1
  • 6
  • 20