#1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2008
    Posts
    50
    Rep Power
    11

    I simply want to make some fields required in my Form


    I simply want to make the email field and contact name fields required to be completed before Submit, but my code is in need of a fix. I know it's not a state-of-the-art Form, but I just need it functioning properly. Your help will be appreciated:

    [CODE]<script type="text/javascript">
    function checkemail(){
    var str=document.myform.email_address.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(str))
    testresults=true;
    else {
    alert("Please input a valid email address!");
    return false;
    }
    if(document.myform.contact_name.value!=0)
    alert("Please enter your full name.");
    return false;
    }
    return true;
    }
    </script>
    CODE]

    I also have this is the Form itself:
    <form action='form_handle.php' method='post' name='myform' onSubmit="return checkemail() && checkcontact();"
  2. #2
  3. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Here try this code


    Ok I don't know to much Javascript, or PHP. But here is how this would look in ASP/VB Script, I hope that helps.

    Two files needed for my code here

    SignUp.asp
    Code:
    <!DOCTYPE html>
    <html>
    <Title> Sign Up Sheet (Test) </Title>
    <body>
    <form name = "Sign Up Sheet (Test Form)" method = "post" action = "FormValidate.asp">
    <br><br><center>
    First Name :<br><input type="text" name="FirstName" />
    <br><br>
    Last Name :<br><input type="text" name="LastName"/>
    <br><br>
    Email :<br><input type="text" name="Email" />
    <br><br>
    Confirm Email :<br><input type="text" name="Email1" />
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    <br></center>
    </body>
    and then

    FormValidate.asp
    Code:
    <!DOCTYPE html>
    <html>
    <Title> Sign Up Form Validation (Test) </Title>
    <body>
    <%
    '' If Statements covering the Email and Email Confirmation matching (first thing to check :D )
    If Request.Form("Email")<>Request.Form("Email1") Then
    Response.Write("Email and Email Confirmation do not match, please press back on your browser and try again.")
    Response.End
    End If
    ''Response.End stops processing of the rest of the page, so if it fails here it won't look any further. End If closes out the If statement.
    
    '' If Statements to ensure that all fields have input.  So <>="" (not equal to blank)
    If Request.Form("FirstName")<>"" AND Request.Form("LastName")<>"" AND Request.Form("Email")<>"" AND Request.Form("Email1")<>"" THEN
    ''Honestly you don't need to cover Email1 but I already put it in (as it is covered by the must equal Email above anyway it can't be blank if Email can't be blank)
    ''Ok moving on next line is what to execute after THEN, we will go ahead and display the information back to the user and let them know the form was successfully processed.
    Response.Write ("First Name : " & RequestForm("FirstName") & "<br>")
    Response.Write ("Last Name : " & RequestForm("LastName") & "<br>")
    Response.Write ("Email Name : " & RequestForm("Email") & "<br>")
    Response.Write ("All Fields Verified" & "<br>")
    '' You will want to add some code here to store this information (that has now been validated not blank by this page (and that emails match)) into the database/excel document/text document you are planning on storing it in.
    Response.Write ("Added to Database")
    '' Here would be code for a link to redirect, or possibly a timer then autoredirect (so the user can see the success screen for a few seconds before being redirected to another page of your choosing.
    
    ''Else If statement covering any blank entries, informs the user what was blank by echoing back all the fields (you could improve on this to highlight the error in red... ;) )
    ElseIf Request.Form("FirstName")="" OR Request.Form("LastName")="" OR Request.Form("Email")="" OR Request.Form("Email1")="" THEN
    
    Response.Write("<font color=red>Failed to Process Form. </font> " & "<br>" & "All Required Fields were not completed, <br> or your Email and Email Confirmation do not match" & "<br>")
    Response.Write("Please review the entries below, then press back on your browser" & "<br>" & "to return to the previous page, to correct an incorrectly entered fields." & "<br>")
    Response.Write ("First Name : " & RequestForm("FirstName") & "<br>")
    Response.Write ("Last Name : " & RequestForm("LastName") & "<br>")
    Response.Write ("Email Address : " & RequestForm("Email") & "<br>")
    Response.Write ("Confirmation Email : " & RequestForm("Email") & "<br>")
    
    End If
    %>
    
    </Body>
    </html>
    Hope this helps! Please let me know either way!

    - Cheers
  4. #3
  5. No Profile Picture
    Contributing User

    Join Date
    Jun 2011
    Location
    Pasig City, Philippines
    Posts
    26
    Rep Power
    0
    Hi, chrisj!

    Check out the link below as a reference:

    JavaScript Form Validation

    I hope this helps. Thank you.

Similar Threads

  1. How to make fields in form non-editable
    By jaishu in forum Microsoft Access Help
    Replies: 2
    Last Post: June 20th, 2012, 07:38 PM
  2. Using ASP to handle required form fields
    By jerseydevel in forum ASP Development
    Replies: 9
    Last Post: September 21st, 2005, 09:16 AM
  3. Choosing fields from combo box to make fields visible
    By mysterymouse in forum Microsoft Access Help
    Replies: 4
    Last Post: August 31st, 2004, 11:39 PM
  4. What if not all Fields required
    By MrKurk in forum ASP Development
    Replies: 7
    Last Post: July 6th, 2004, 12:43 PM
  5. setting required fields on a form
    By tihonna in forum ASP Development
    Replies: 5
    Last Post: July 5th, 2004, 02:46 PM

IMN logo majestic logo threadwatch logo seochat tools logo