Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Form validation / submit to url

  1. #1
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Form validation / submit to url

    I am trying to set up a form that contains 3 text fields as well as select between two radio spots. I'd like all fields to be required to be filled in as well as (if possible) verify the email is valid. Then after clicking submit I'd like this to go to a url, but only be able to access the url from this form page with all fields complete.

    Still new to Javascript sorry! Thanks in advance


    <script type="text/javascript">
    function validateForm()
    {
    var x=document.forms["myForm"]["fname"].value;
    if (x==null || x=="")
    {
    alert("First Name must be filled out");
    return false;
    }
    }
    {
    var x=document.forms["myForm"]["lname"].value;
    if (x==null || x=="")
    {
    alert("Last Name must be filled out");
    return false;
    }
    }
    {
    var x=document.forms["myForm"]["email"].value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    {
    alert("Not a valid e-mail address");
    return false; }
    }

    function GetSelectedItem() {

    chosen = ""
    len = document.f1.r1.length

    for (i = 0; i <len; i++) {
    if (document.f1.r1[i].checked) {
    chosen = document.f1.r1[i].value
    }
    }

    if (chosen == "") {
    alert("No Type Chosen")
    }
    else {
    alert(chosen)
    }
    }
    </script>


    <table style="width: 300px;" align="center" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0"><form name="myForm" action="https://thecesolution.cecity.com/" onsubmit="returnvalidateForm()" method="get">
    <tbody><tr>
    <td width="135px"><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px; padding-left: 15px;">
    <strong>First
    Name:</strong></span></td>
    <td style="width: 165px;"><input name="fname" type="text"></td>
    </tr>
    <tr>
    <td width="135px">&nbsp;</td>
    <td style="width: 165px;">&nbsp;</td>
    </tr>
    <tr>
    <td><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px; padding-left: 15px;">
    <strong>Last
    Name:</strong></span></td>
    <td style="width: 165px;"><input name="lname" type="text"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td style="width: 165px;">&nbsp;</td>
    </tr>
    <tr>
    <td><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px; padding-left: 15px;">
    <strong>Email Address:</strong></span></td>
    <td style="width: 165px;"><input name="email" type="text"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2" style="padding-left:15px; padding-bottom:7px;"><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px;">
    <strong>Which best describes your workplace?</strong></span></td>
    </tr>
    <tr>
    <td style="text-align: center">
    <input type="radio" name="r1" value="location" /><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px;"><strong> </strong>Independent
    <br />
    </span></td>
    <td style="text-align: center">
    <input type="radio" name="r1" value="Franchise" /><span style="font-family: Arial,Helvetica,sans-serif; font-size: 12px;"><strong> </strong>Franchise
    <br />
    </span></td>
    </tr>
    <tr>
    <td colspan="2" style="padding-top: 15px;" align="center"><input value="Submit" type="submit" onclick="parent.location='https://thecesolution.cecity.com/"></td>
    </tr>
    </tbody></form></table>

  2. #2
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    I don't understand the question.
    Thanks,

    Bud

  3. #3
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have the form but I want to have all fields required to fill in. I'd also like the email address to be verified that it is valid. and then after those two criteria are met, have the patron taken to a url.

    Basically when they hit the submit button after filling out the form. The fields of the form are verified and then they are taken to a separate url.

    I can figure out how to do each of these individually, but cannot figure out how to get all three coded so they work simultaneously.

    Thanks
    Keith

  4. #4
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Can you place your code inside [PHP][/PHP] tags please. It makes it a lot easier to debug your code.

  5. #5
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry about that... How's this? I just removed all unnecessary tags

    <form name="form" onsubmit="return formCheck(this);" >

    First Name:<input name="fname" type="text"><br />
    Last Name:<input name="lname" type="text"><br />
    Email Address:<input name="email" type="text"><br />
    Which best describes your workplace?<br />
    <input type="radio" name="r1" value="1" />Independent <br />
    <input type="radio" name="r1" value="2" />Franchise<br />
    <input value="Submit" type="submit" >

    </form>

  6. #6
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    I tend to give this out as a great way to start with a feedback form

    http://devingredients.com/2011/03/bu...-from-scratch/

    It is easily configured and the author is available for support.

    It is pretty much straight forward and is commented as what everything is and how to add to it also.

    You can email me or message me if you need help getting it going
    Thanks,

    Bud

  7. The Following User Says Thank You to ajfmrf For This Useful Post:

    firstnam (05-15-2012)

  8. #7
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    Quote Originally Posted by firstnam View Post
    Sorry about that... How's this? I just removed all unnecessary tags

    <form name="form" onsubmit="return formCheck(this);" >

    First Name:<input name="fname" type="text"><br />
    Last Name:<input name="lname" type="text"><br />
    Email Address:<input name="email" type="text"><br />
    Which best describes your workplace?<br />
    <input type="radio" name="r1" value="1" />Independent <br />
    <input type="radio" name="r1" value="2" />Franchise<br />
    <input value="Submit" type="submit" >

    </form>
    [PHP][/PHP] tags...

    PHP Code:
    <form name="form" onsubmit="return formCheck(this);" >

    First Name:<input name="fname" type="text"><br />
    Last Name:<input name="lname" type="text"><br />
    Email Address:<input name="email" type="text"><br />
    Which best describes your workplace?<br />
    <
    input type="radio" name="r1" value="1" />Independent <br />
    <
    input type="radio" name="r1" value="2" />Franchise<br />
    <
    input value="Submit" type="submit" >

    </
    form

  9. #8
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    Are you saying that after the form is sent(after the submit button is clicked) ,you want the user to be taken to a url like a thank you page?
    Thanks,

    Bud

  10. #9
    Join Date
    May 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Yes hopefully.

  11. #10
    Join Date
    Jan 2011
    Location
    Southeastern CT
    Posts
    612
    Thanks
    46
    Thanked 32 Times in 32 Posts

    Default

    The script I posted has that in it.If all fields are filled,the email is valid then it sends the information on and posts a thank you right there on the form.

    It really is a good script and secure also.

    Message me or email me if you need more help with this
    Thanks,

    Bud

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •