What am I missing I need to store the information from the f
What am I missing? I need to store the information from the form in session storage and have it be displayed on my php page after the submit button is clicked. Everything is working EXCEPT the stored values are not being displayed on the php page. (I think maybe the values aren\'t saving...possibly the JS file)
HTML MAIN FILE:
<form action=\"print.php\" method=\"get\">
<h2>Register Here</h2><br>
<label>Email :</label>
<input id=\"email\" name=\"email\" placeholder=\"Valid Email\" type=\"text\">
<label>Gender :</label>
<input id=\"male\" name=\"gender\" type=\"radio\" value=\"Male\">
<label>Male</label>
<input id=\"female\" name=\"gender\" type=\"radio\" value=\"Female\">
<label>Female</label>
<label>Contact # (numeric entry only): </label>
<input id=\"contact\" name=\"contact\" placeholder=\"Contact No\" type=\"text\">
<input type=\"submit\" value=\"Submit\">
</form>
VALIDATION JS FILE
function ValidationEvent() {
// Storing Field Values In Variables
var email = document.getElementById(\"email\").value;
var gender = document.getElementById(\"gender\").value;
var contact = document.getElementById(\"contact\").value;
// Regular Expression For Email
var emailReg = /^([\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4})?$/;
var phoneReg =/^[(]{0,1}[0-9]{3}[)]{0,1}[-\\s\\.]{0,1}[0-9]{3}[-\\s\\.]{0,1}[0-9]{4}$/;
// Conditions
if (email != \'\' && contact != \'\') {if (email.match(emailReg)) {if (document.getElementById(\"male\").checked || document.getElementById(\"female\").checked) {
if (contact.length == 10 && contact.match(phoneReg) ) {
localStorage.email = email;
localStorage.contact = contact;
return true;
} else {
alert(\"The Contact Number must be at least 10 digits.!\");
return false;
}
} else {
alert(\"Select a gender!\");
return false;
}
} else {
alert(\"Invalid Email Address...!!!\");
return false;
}
} else {
alert(\"All fields required!\");
return false;
}
}
PHP FILE
<body>
<h1>You\'re registered</h1>
<br>
<script>
document.write(\"Phone: \", SessionStorage.contact, \"<br>\");
document.write(\"Email: \", SessionStorage.email, \"<br>\");
</script>
</body>
Solution
HTML FILE (included in js also)
<form action=\"print.php\" method=\"get\"id=\"formid\" onsubmit=\" return ValidationEvent()\">
<h2>Register Here</h2><br>
<label>Email :</label>
<input id=\"email\" name=\"email\" placeholder=\"Valid Email\" type=\"text\">
<label>Gender :</label>
<input id=\"male\" name=\"gender\" type=\"radio\" value=\"Male\">
<label>Male</label>
<input id=\"female\" name=\"gender\" type=\"radio\" value=\"Female\">
<label>Female</label>
<label>Contact # (numeric entry only): </label>
<input id=\"contact\" name=\"contact\" placeholder=\"Contact No\" type=\"text\">
<input type=\"submit\" value=\"Submit\">
</form>
<script>
function ValidationEvent() {
// Storing Field Values In Variables
var email = document.getElementById(\"email\").value;
var gender = document.getElementsByName(\"gender\").value;
var contact = document.getElementById(\"contact\").value;
// Regular Expression For Email
var emailReg = /^([\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4})?$/;
var phoneReg =/^[(]{0,1}[0-9]{3}[)]{0,1}[-\\s\\.]{0,1}[0-9]{3}[-\\s\\.]{0,1}[0-9]{4}$/;
// Conditions
if (email != \'\' && contact != \'\') {if (email.match(emailReg)) {if (document.getElementById(\"male\").checked || document.getElementById(\"female\").checked) {
if (contact.length == 10 && contact.match(phoneReg) ) {
localStorage.setItem(\"email\", email);
localStorage.setItem(\"contact\", contact);
// localStorage.email = email;
//localStorage.contact = contact;
return true;
} else {
alert(\"The Contact Number must be at least 10 digits.!\");
return false;
}
} else {
alert(\"Select a gender!\");
return false;
}
} else {
alert(\"Invalid Email Address...!!!\");
return false;
}
} else {
alert(\"All fields required!\");
return false;
}
}
</script>
PHP FILE :
<body>
<h1>You\'re registered</h1>
<br>
<script>
document.write(\"Phone: \", localStorage.getItem(\"contact\"), \"<br>\");
document.write(\"Email: \", localStorage.getItem(\"email\"), \"<br>\");
</script>
</body>
Output :
You\'re registered
Phone: 1234567890
Email: a@f.com