Retain data in web form

User 2877157 Photo


Registered User
4 posts

Hello

I am new to Web Form (just purchased) i have created a pop-up form all good, my question is:
Is there a way to retain the information in the form if the user clicks back on the website and then clicks the form button again the form is blank again I would like any data entered to still there, is this posable?.

Thanks
User 187934 Photo


Senior Advisor
20,188 posts

Hi Steven,
The form builder doesn't have this ability built in but you can add some custom code to accomplish it.
Google search retain form data before submit.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2877157 Photo


Registered User
4 posts

Hi

Thanks for that, had a look but don't really understand it.
Does some custom code have to be added to one of the Web Form files or a new file?
User 187934 Photo


Senior Advisor
20,188 posts

Here's one approach.
http://ericrohloff.com/coffeecup/ccforu … index.html
Let me know if this looks like it's the correct direction.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2877157 Photo


Registered User
4 posts

Hi Eric

Yes something like that is good.

Thanks
User 187934 Photo


Senior Advisor
20,188 posts

Here's how I did this approach. I suggest testing with only two inputs until you confirm it's working then adjust the code by adding more.
This requires that you setup your host to parse php inside html. You could also change your form to have a .php extension.
Make a php page named save-data.php with the code below and save it on your host. Add more variables if needed and adjust their names to meet your needs.
<?php
session_start();
if(isset($_POST["number1"]) && isset($_POST["text1"])){
$_SESSION['number1'] = $_POST["number1"];
$_SESSION['text1'] = $_POST["text1"];

echo json_encode(array($_SESSION['number1'],$_SESSION['text1']));
}
?>

Paste this code at the very top of your form page above all other html. There should be no spaces or content before it.
<?php session_start();?>


This code goes on your actual form. It can be placed within the head section or use an HTML element. Adjust the number1 and text1 to the actual name of your inputs. Add more variables if needed. Adjust the url to where you saved the save-data.php page on your host.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var jQ = $.noConflict();

setInterval(function(){
var number1 = jQ('input[name="number1"]').val();
var text1 = jQ('input[name="text1"]').val();
if(number1 != '' && text1 != '' ){
var request = jQ.ajax({
url: "http://mydomain.com/save-data/save-data.php",
method: "POST",
data: {
number1: number1,
text1: text1
},
dataType: "json"
});

request.done(function(data) {
console.log(data[0]);
console.log(data[1]);

});
request.fail(function( jqXHR, textStatus ) {
alert( "Save failed: " + textStatus );

});
}
}, 2000);</script>


This is the forget-data.php
Save this php page to the same location you saved the save-data.php. Adjust the url to your actual domain and the location of the page your form is on.
<?php
Session_start();
session_destroy();
header("Location: http://mydomain.com/save-data/index.html");
die();
?>


Put a link on your for on your form pointing to the forget.php. This is how we unset the $_SESSION variables.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2877157 Photo


Registered User
4 posts

That will help

Many Thanks

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.