0

I am trying to submit a form. When i click the the submit button it takes me to the next page which is not in my control(hitting an api). From that, that page user can click browsers back button come to my form page. From there onwards user can fill the form and resubmit. In this form i am passing an randomid as a hidden value. Problem is even when user comes back by clicking back button and resubmit the form with different values and that randomid remains the same. How can i solve this?

Here is my form.php

<?php
include_once 'dbconnect.php';

$r= mt_rand();

<body>
<form id="register-form" action="http://api.ipayy.com/v001/c/oc/dopayment" method="get" class="form input-group register-form">
         <div class="container-fluid">
            <div class="row">

                <input type="hidden" id="reqnum" name="reqnum"  value="<?php echo $r ?>" />

                <div class="col-sm-3 col-xs-12">
                    <input name="fname" id="fname" class="form-cus form-control" type="text" placeholder="Your First Name"  autocomplete="off"  required>
</div>

<div class="col-sm-3 col-xs-12">
                    <input name="title" id="title" class="form-cus form-control" type="text" placeholder="Title of Your Web site" autocomplete="off" required>
                </div>

                <div class="col-sm-3 col-xs-12">
                    <input name="descr" id="descr" class="form-cus form-control" type="text" placeholder="Description of Your Web site" autocomplete="off" required>
                </div>

                <div class="form-group col-sm-3 col-xs-12">
                    <button class="btn btn-1 btn-fill" type="submit" id="btn-signup" name="btn-signup" style="display:none;">Submit</button>
                </div>

            </div> 
        </div> 
    </form>
<script>
$('form').submit(function() {
    $.ajax({

        url: "http://ll.php",
        async:false,
        data: $(this).serialize(),
        success: function(data){

        },
        error : function(data) {
            console.log(data);
        }
    });

});
</script> 
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
colombo
  • 520
  • 2
  • 9
  • 24

2 Answers2

0

Update, here's another solution that I've come across...

function Reload() {
    try {
        var headElement = document.getElementsByTagName("head")[0];

        if (headElement && headElement.innerHTML)
             headElement.innerHTML += "<meta http-equiv=\"refresh\" content=\"1\">";
    }
    catch (e) {}
}

window.onload(function () { Reload(); }

By default, a browser will show a cached version of the previous page.

To get around this, it's a very simple fix...

<body onunload="">

This will disable the browser from caching the page and force it to reload the page when a user clicks "back"

LMS94
  • 1,016
  • 1
  • 7
  • 14
0

You should use ajax post form submit. You can use event.preventDefault(); to prevent default form submit. I think it good solution to avoid unwanted page redirect or page reload

Dima Shvets
  • 31
  • 1
  • 7