[RESOLVED] Form validating issues; form action to php file negates validation, why?
Iíve been trying to mesh tutorials and this is what Iíve come up with. However, my ďYour message has been sentĒ alert which I was trying to apply at the end (if everything was verified) never comes through and Iím absolutely stumped. Any pointers would be greatly appreciated.
if (document.contactAPC.name.value == '')
alert('Please enter a name.');
else if(document.contactAPC.email.value == '')
alert('Please enter an email address.');
else if(document.contactAPC.message.value == '')
alert('Please write a message.');
else if(document.contactAPC.email.value != '')
emailpattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
alert("Please enter a valid email address");
//Why can't I get this message to show?
alert("Your message has been sent.");
<form name="contactAPC" method="post" action="" onSubmit="return checkform()">
Name <input type="text" size="26" id="name" name="name" class="txtfield_details">
<br />Email <input type="text" size="26" id="email" name="email" class="txtfield_details">
<br /><textarea cols="24" rows="4" class="txtfield_details" name="message" id="message"></textarea>
<br /><input type="submit" value="Submit" name="submit" class="btns" />
<input type="reset" value="Clear" name="clear" class="btns" />
Now my other issue is that when I attach the php file (below) to the form action (ie. action=Ēmyfile.phpĒ) Ė the form no longer even bothers to remotely try to validate. It just sends the contents straight through and I get my ďYour message has been sent messageĒ and this also confuses me. I thought checkform() needed to come back as true for the submit button to move the user forward.
I knew it was something simple (and quite possibly stupid). A mentor helped me catch the error(s), which resolved both issues.
For anyone else who might ever have a similar problem. In the last, else-statement, I need to have return true; come AFTER the alert box so that the script does exit before I need the last action to run.
//stop hiding script -->
I didn't have the comment on it and it was spitting out a error (apparently in Firefox), although IE8 was reading everything fine/no errors, so that's why I was just really confused.
I love helpful people. Fixing this did really make my evening so much better. : )