php - How to keep form values after submitting to another website?

Jows

I'm making a payment gateway and its submitting to itransact.com.

How to keep the values after submitting to itransact? If the values have an error to the itransact the customer back to the form and all values are gone.

Footniko

You can use JavaScript to push needed values to cookies before, as form send. For example:

<form onsubmit="return storeValues(this);" action="" method="POST" name="userForm">
    <input type="text" value="" name="firstname">
    <input type="text" value="" name="lastname">
    <input type="submit" value="Send request">
</form>

Now JavaScript side:

<script>
  /* Set cookies to browser */
  function storeValues(form)  
  {
    setCookie("firstname", form.firstname.value);
    setCookie("lastname", form.lastname.value);
    return true;
  }

  var today = new Date();
  var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); // today + 30 days

  function setCookie(name, value)
  {
    document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
  }
  /* --Set cookies to browser */

  function getCookie(name) {
    var value = "; " + document.cookie;
    var parts = value.split("; " + name + "=");
    if (parts.length == 2) return parts.pop().split(";").shift();
  }

  /* Loading cookie values into the form */
  if(firstname = getCookie("firstname")) document.userForm.firstname.value = firstname;
  if(lastname = getCookie("lastname")) document.userForm.lastname.value = lastname;
  /* --Loading cookie values into the form */

</script>

You can get more info about setting cookies using this example: http://www.the-art-of-web.com/javascript/setcookie/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I keep field values in a form after submit?

How to keep the previous uploaded image (in db) after submitting a form without selecting a new image to be uploaded

how to keep values in textfields after submitting a form in laravel 5.2

How to redirect to another HTML page after submitting a form?

How to redirect user after submitting form with React

How to redirect website after submitting google form?

form in php not redirecting to page after submitting

Trying to redirect in PHP after submitting an email form

How can I get the form values to appear in the table after submitting?

How to keep containers one after another in overlapping form?

How to retain values from textarea after submitting the form

Keep $_GET value of a drop down menu after submitting the form

Submitting HTML Form Values as Array (To PHP)

How to add message after submitting form? PHP, Wordpress

How to redirect after submitting form in php

Form is submitting to another page without validation in php

How to get paper-radio-button, paper-checkbox or core-dropdown-menu values with PHP $_GET after submitting a form

How to keep form values even after page is redirected back

How to open another submit form after submitting one on html or javascript?

run php file on another tab on same page without submitting form values

PHP keep printed/echoed values after submitting

PHP - $_POST variable is not set after form submitting

How to clean a form with stars in javascript after submitting?

redirect to another page after submitting a form

How to load table data after submitting the form in react js php

How can i get data or pass a data from one page to another after submitting a form in reactjs

How to render another component on submitting a form

(Django) How to keep input values after form submit

How to redirect after submitting form