form validation and sending info to email address?

Discussion in 'C#' started by akinak, May 30, 2008.

  1. #1
    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?
     
    akinak, May 30, 2008 IP
  2. Free Born John

    Free Born John Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    add some validator controls to your form.
     
    Free Born John, Jun 4, 2008 IP
  3. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #3
    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):
     
    itcn, Jun 4, 2008 IP
  4. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    u using classic asp or asp.net ??

     
    webexpert, Jun 6, 2008 IP
  5. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    classic asp
     
    akinak, Jun 10, 2008 IP
  6. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Sorry about that, I was giving answers for .NET..
     
    itcn, Jun 10, 2008 IP
  7. webexpert

    webexpert Banned

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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>
     
    webexpert, Jun 10, 2008 IP