I have a simple contact form with fields for entering a users name, email id and address. I want to validate the form using ASP or javascript. I want all the fields to be required and also validate email address. Also, how can I send all form information into my email?
You can use .NET validator controls like this to make fields required: <asp:RequiredFieldValidator id="reqUserName" ControlToValidate="userName" ErrorMessage="Please enter a user name." display="dynamic" runat="server" /> Code (markup): And Regex validators for email addresses: <asp:RegularExpressionValidator id="regexEmail" ControlToValidate="usEmail" ErrorMessage="Email must be in the form [email]someone@domain.com[/email]." display="dynamic" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" runat="server" /> Code (markup):
to send the email data, you can simply use cdonts or cdosys. Just google "sending email using cdosys using classic asp" or "sending email using cdonts using classic asp" and you will find allott of help.. for validations.. its so simple - on form tag. add this; <form onSubmit="return validate(this);"> and then. javascript validate function you can write within head tag. <script language="javascript"> function validate(theform) { if(theform.email.value="") {alert("please enter email address.."); return false;} else if(theform.address.value="") {alert("please enter address.."); return false;} else{return true;} } </script>