How do I make a form field a requirment to submit the form? And whne they submit with out the required field how do you make it so the fields they did fill in stay there?
How do I make a form field a requirment to submit the form? And whne they submit with out the required field how do you make it so the fields they did fill in stay there?
Dave Kovaleski REALTOR
Pocono Pennsylvania Real Estate Agent
Pocono Real Estate
Hideout Real Estate
Lake Wallenpaupack Real Estate
You can do it with javascript (it just pops up one of those js prompts... you need to fill out this field) and keeps them on the same page until the field is filled out.
If you're using dreamweaver there are a couple of free extensions available that will generate the code for you.
On my forms I just create a session variable for the required field, and then on the confirming page redirect the visitor if the session is null (response.redirect in asp). I'm not sure exactly how this translates to php but I'm sure it has to be similar and as simple. If you're on a Windows server and don't mind using asp I'd be glad to send a sample.
Thinking about it though, you probably wouldn't even have to create the session, you could just request the variable from the form directly and redirect if that was empty.
It may not be the most elegant solution but using the js back after the redirect message takes them back to the original page with all of the data they entered intact. javascript:history.back(1)
OverlyReal.com - The best little real estate directory on the planet!
It's better to do that check on server side or both. In php you can simple check the value of your field this way:
To keep values on form (PHP) :if (!empty($_POST['field'])) {
// code here.
}
<input type="text" name="field" value="$_POST[field]" />
I don't use any php at the moment just html. Not sure if this helps or hurts my solution.
Thanks so far
Dave Kovaleski REALTOR
Pocono Pennsylvania Real Estate Agent
Pocono Real Estate
Hideout Real Estate
Lake Wallenpaupack Real Estate
then you can add this:
and in your form add :<script type="text/javascript">
function checkField(fieldname) {
if(document.getElementById(fieldname).value == "") {
alert('Required field');
return false;
}
}
function checkFields(form) {
// you can check here your fields
if (!checkField(form.field1)) return false;
if (!checkField(form.field2)) return false;
}
</script>
and<form name="formname" action="youraction" method="post_or_get" onsubmit="return checkFields(this)">
Hope this help.<input type="text" name="field1" id="field1" />
© Copyright Real Estate Webmasters 2004-2010, All Rights Reserved. Terms of Service