You can try this out
1st Form: formA.html
<body>
<form action="formB.html" method="get">
Name: <input type="text" name="nome">
<input id="submit_button" type="submit" value="PAGINA B »">
</form>
</body>
2nd Form: formB.html
<body>
<form action="processar.php" method="post">
Nome: <input type="text" name="nome">
Idade: <input type="text" name="idade">
<input type="submit" value="SALVAR DADOS">
</form>
<script type="text/javascript">
var query = window.location.search.substring(1);
var Field=query.split("=");
document.getElementById("nome").value = Field[1];
</script>
</body>
Then you can use a regular expression to remove the +
of the expression.
Another option might be HTML5 functionality, localStorage
or sessionStorage
which is less permanent:
Part 1: A.html
<form action="B.html" onsubmit="return validar(this)" method="post">
Nome: <input type="text" name="fnome">
<input type="submit" value="PAGINA B »">
</form>
<script>
function validar(form){
if(typeof(Storage) !== 'undefined'){
if(form["fnome"].value != ""){
sessionStorage.setItem('nome', form["fnome"].value);
return true;
} else {
alert('Preencha o campo');
}
} else {
alert('O navegador nao suporta storage');
}
return false;
}
</script>
Part 2: B.html
<form action="validar.php" method="post">
Name: <input type="text" name="fnome">
Idade: <input type="text" name="fidade">
<input type="submit" value="Salvar">
</form>
<script>
if(typeof(Storage) !== 'undefined'){
var form = document.querySelector("form");
if(sessionStorage.getItem('nome')){
form["fnome"].value = sessionStorage.getItem('nome');
form.addEventListener('submit', function(ev){
ev.preventDefault();
if(form["fnome"].value != "" && form["fidade"].value > 0){
alert('Dados digitados:\n\nNome: ' + form["fnome"].value + "\nIdade: " + form["fidade"].value + "\n\nA enviar para servidor...");
sessionStorage.clear();
this.submit();
} else {
alert("Preencha os campos em branco");
}
return false;
});
} else {
form["fnome"].value = "sem nome";
}
} else {
alert('O navegador nao suporta storage');
}
</script>
You can also see the first example in SOen .