1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Form Validation on PhP page using javaScript..?

Discussion in 'JavaScript' started by Kryptickitty, Jun 20, 2013.

  1. #1
    hey all i have a PHP where they want JavaScript validation and i just cannot get it to work.....

    here is the page code
    <?php

    // change these for every sub page to be populated in the MD_header.php section when served

    $title = "";
    $description = "";
    $keywords = "";

    include('MD_header.php');

    ?>

    <!-- Content Wrapper -->
    <div id="content_wrapper" style="height:480px;">
    <div id="cw_left" style="height:480px;"><img src="images/about_logo.png" width="122" height="318" alt="MD Logo" /></div>
    <div id="cw_right" style="height:480px;">
    <div id="cw_r_left" style="height:480px;">
    <div id="cw_r_l_top" style="height:72px;"><img src="images/contact_header.png" alt="Our Mission" /><br /></div>
    <div id="cw_r_l_bot">
    <form action="contact_processing.php" method="post" enctype="multipart/form-data" >
    <table border="0" cellpadding="4" class="body_text" style="font-size:12px;">
    <tr>
    <td align="right" >First Name:</td>
    <td>
    <input name="first_name" type="text" id="first_name" tabindex="1" size="30"> *</td>
    </tr>
    <tr>
    <td align="right">Last Name:</td>
    <td>
    <input name="last_name" type="text" id="last_name" tabindex="2" size="30"> *
    </td>
    </tr>
    <tr>
    <td align="right">Phone:</td>
    <td><input name="phone" type="text" id="phone" tabindex="7" size="30"> *</td>
    </tr>
    <tr>
    <td align="right">Email:</td>
    <td><input name="email" type="text" id="email" tabindex="8" size="30"40> *</td>
    </tr>
    <tr>
    <td align="right">Address:</td>
    <td><input name="address" type="text" id="address" tabindex="3" size="30"> *</td>
    </tr>
    <tr>
    <td align="right">City:</td>
    <td><input name="city" type="text" id="city" tabindex="4" size="30"> *</td>
    </tr>
    <tr>
    <td align="right">State:</td>
    <td><select name="state" id="state">
    <option value="AL" <?PHP if($state=="AL") echo "selected";?>>Alabama</option>
    <option value="AK" <?PHP if($state=="AK") echo "selected";?>>Alaska</option>
    <option value="AZ" <?PHP if($state=="AZ") echo "selected";?>>Arizona</option>
    <option value="AR" <?PHP if($state=="AR") echo "selected";?>>Arkansas</option>
    <option value="CA" <?PHP if($state=="CA") echo "selected";?>>California</option>
    <option value="CO" <?PHP if($state=="CO") echo "selected";?>>Colorado</option>
    <option value="CT" <?PHP if($state=="CT") echo "selected";?>>Connecticut</option>
    <option value="DE" <?PHP if($state=="DE") echo "selected";?>>Delaware</option>
    <option value="DC" <?PHP if($state=="DC") echo "selected";?>>District of Columbia</option>
    <option value="FL" <?PHP if($state=="FL") echo "selected";?>>Florida</option>
    <option value="GA" <?PHP if($state=="GA") echo "selected";?>>Georgia</option>
    <option value="HI" <?PHP if($state=="HI") echo "selected";?>>Hawaii</option>
    <option value="ID" <?PHP if($state=="ID") echo "selected";?>>Idaho</option>
    <option value="IL" <?PHP if($state=="IL") echo "selected";?>>Illinois</option>
    <option value="IN" <?PHP if($state=="IN") echo "selected";?>>Indiana</option>
    <option value="IA" <?PHP if($state=="IA") echo "selected";?>>Iowa</option>
    <option value="KS" <?PHP if($state=="KS") echo "selected";?>>Kansas</option>
    <option value="KY" <?PHP if($state=="KY") echo "selected";?>>Kentucky</option>
    <option value="LA" <?PHP if($state=="LA") echo "selected";?>>Louisiana</option>
    <option value="ME" <?PHP if($state=="ME") echo "selected";?>>Maine</option>
    <option value="MD" <?PHP if($state=="MD") echo "selected";?>>Maryland</option>
    <option value="MA" <?PHP if($state=="MA") echo "selected";?>>Massachusetts</option>
    <option value="MI" <?PHP if($state=="MI") echo "selected";?>>Michigan</option>
    <option value="MN" <?PHP if($state=="MN") echo "selected";?>>Minnesota</option>
    <option value="MS" <?PHP if($state=="MS") echo "selected";?>>Mississippi</option>
    <option value="MO" <?PHP if($state=="MO") echo "selected";?>>Missouri</option>
    <option value="MT" <?PHP if($state=="MT") echo "selected";?>>Montana</option>
    <option value="NE" <?PHP if($state=="NE") echo "selected";?>>Nebraska</option>
    <option value="NV" <?PHP if($state=="NV") echo "selected";?>>Nevada</option>
    <option value="NH" <?PHP if($state=="NH") echo "selected";?>>New Hampshire</option>
    <option value="NJ" <?PHP if($state=="NJ") echo "selected";?>>New Jersey</option>
    <option value="NM" <?PHP if($state=="NM") echo "selected";?>>New Mexico</option>
    <option value="NY" <?PHP if($state=="NY") echo "selected";?>>New York</option>
    <option value="NC" <?PHP if($state=="NC") echo "selected";?>>North Carolina</option>
    <option value="ND" <?PHP if($state=="ND") echo "selected";?>>North Dakota</option>
    <option value="OH" <?PHP if($state=="OH") echo "selected";?>>Ohio</option>
    <option value="OK" <?PHP if($state=="OK") echo "selected";?>>Oklahoma</option>
    <option value="OR" <?PHP if($state=="OR") echo "selected";?>>Oregon</option>
    <option value="PA" <?PHP if($state=="PA") echo "selected";?>>Pennsylvania</option>
    <option value="RI" <?PHP if($state=="RI") echo "selected";?>>Rhode Island</option>
    <option value="SC" <?PHP if($state=="SC") echo "selected";?>>South Carolina</option>
    <option value="SD" <?PHP if($state=="SD") echo "selected";?>>South Dakota</option>
    <option value="TN" <?PHP if($state=="TN") echo "selected";?>>Tennessee</option>
    <option value="TX" <?PHP if($state=="TX") echo "selected";?>>Texas</option>
    <option value="UT" <?PHP if($state=="UT") echo "selected";?>>Utah</option>
    <option value="VT" <?PHP if($state=="VT") echo "selected";?>>Vermont</option>
    <option value="VA" <?PHP if($state=="VA") echo "selected";?>>Virginia</option>
    <option value="WA" <?PHP if($state=="WA") echo "selected";?>>Washington</option>
    <option value="WV" <?PHP if($state=="WV") echo "selected";?>>West Virginia</option>
    <option value="WI" <?PHP if($state=="WI") echo "selected";?>>Wisconsin</option>
    <option value="WY" <?PHP if($state=="WY") echo "selected";?>>Wyoming</option>
    </select> *</td>
    </tr>
    <tr>
    <td align="right">Zip:</td>
    <td><input name="zip" type="text" id="zip" tabindex="6" size="30"> *</td>
    </tr>
    <tr>
    <td align="right">&nbsp;</td>
    <td>Additional Information:<br /><textarea name="information" cols="30" rows="2"></textarea></td>
    </tr>
    <td align="right">*Required</td>
    <td>
    <input type="button" name="clear_date" id="clear_date" value="Clear">
    <input type="submit" name="submit" id="submit" value="Submit">
    </td>
    </tr>
    </table>

    </form>
    </div>
    </div>
    <div id="cw_r_right" style="height:480px;">
    <div style="width:347px; height:200px; margin-top:50px; margin-left:20px; float:left; text-align:left;font-family: 'Century Gothic', sans-serif; font-size: 15px; color:#CCCCCC;">
    <p><strong>Thank you for visiting SolarexMD!</strong></p>
    <p>To ensure that your question or comments are properly received, please fill out the information requested on our form.
    Messages are usually replied to on the following business day.</p>
    <p>You may also contact us directly from the information below. </p>
    <p style="font-size:10px">(Please Note: Your personal information is confidential and will not be shared with or sold to outside sources.)
    <strong><p>SolarexMD<span style="font-size:8px;">®</span><br />
    4908 Golden Parkway, Suite 400<br />
    Buford, GA &nbsp;30518<br />
    Phones: 800.728.7873 / 770.271.4412 <br />
    Fax: 770.614.4436<br />
    Email: <a href="mailto:" class="whitelink"></a></p></strong>
    </div>
    </div>
    </div>
    </div>
    <!-- End Content Wrapper -->
    <!-- Line -->
    <div id="line"></div>
    <!-- End Line -->
    <?php include('MD_products.php'); ?>
    </div>
    <!--End 980 Wrapper -->
    <?php include('MD_footer.php'); ?>
     
    Last edited by a moderator: Jun 20, 2013
    Kryptickitty, Jun 20, 2013 IP
  2. d3v1l

    d3v1l Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    Digital Goods:
    1
    #2
    i can fix this for you...
     
    d3v1l, Jun 21, 2013 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    Fix it if you can, but keep in mind - this isn't a section where one gets paid for something.
     
    ActiveFrost, Jun 21, 2013 IP
  4. d3v1l

    d3v1l Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    Digital Goods:
    1
    #4

    Ohh.. ok bro no problem :) thn contact me... personally. :)
     
    d3v1l, Jun 21, 2013 IP
  5. Kryptickitty

    Kryptickitty Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    var addReplyClick = 0;

    function submitFormContactUs(strAction)
    {
    document.frmForm.action.value = strAction;
    document.frmForm.submit();
    }
    function addNew()
    {
    var strMsg = "";
    if (document.frmForm.customer.value.trim() == "")
    strMsg += " - Name cannot be blank.\n";
    if (document.frmForm.custemail.value.trim() == "" || !isValidEmail(document.frmForm.custemail.value))
    strMsg += " - Email cannot be blank and must be a valid email address.\n";
    if (document.frmForm.subject.value.trim() == "")
    strMsg += " - Subject cannot be blank.\n";
    if (document.frmForm.reply.value.trim() == "")
    strMsg += " - Message cannot be blank.\n";
    <!--START: captchascript-->
    if (document.frmForm.ramdomWord.value.trim() == "")
    strMsg += " - Verification word cannot be blank.\n";
    <!--END: captchascript-->

    if (strMsg != ""){
    alert(strMsg);
    return false;
    }
    if (addReplyClick == 0){
    addReplyClick = 1;
    submitFormContactUs('addnew');
    }

    }
    String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
    }
    function isValidEmail(str) {

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)

    if (str.indexOf(at)==-1)
    return false

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    return false

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    return false

    if (str.indexOf(at,(lat+1))!=-1)
    return false

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    return false

    if (str.indexOf(dot,(lat+2))==-1)
    return false

    if (str.indexOf(" ")!=-1)
    return false

    return true
    }

    </script>



    will this not work?
     
    Kryptickitty, Jun 21, 2013 IP
  6. d3v1l

    d3v1l Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    Digital Goods:
    1
    #6
    This script is too long.... this can be simplified.... using jquery we can done easily in few lines...

    Ex: for email validation

    If you want.. you prefer jquery or javascript.....

    if you want Jquery see this link i have posted for you... i wrote my self.... for form validation.


    https://marketplace.digitalpoint.com/form-validation-using-jquery-full-validation-script.1551/item
    HTML:
    If you want javascripts pls let me kno.
     
    d3v1l, Jun 21, 2013 IP
  7. Kryptickitty

    Kryptickitty Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    I have typed out a javascript code:
    window.onload = startForm;
     
    function startForm () {
        document.forms[0].onsubmit = checkForm1;
    }
     
    function checkForm1 () {
        if (document.forms[o].fname.value.length == 0)
          {alert("Please enter your first name");
            return false;}
        else if (document.forms[o].lname.value.length == 0)
            {alert("Please enter your last name");
            return false;}
        else if (document.forms[o].phone.value.length == 0)
            {alert("Please enter your phone number");
            return false;}
        else if (document.forms[o].street.value.length == 0)
            {alert("Please enter your street address");
            return false;}
        else if (document.forms[o].city.value.length == 0)
            {alert("Please enter the name of your city");
            return false;}
        else if (checkZip(document.forms[o].zip.value) == false)
            {alert("Invalid zip code");
            return false;}
        else return true;
    }
     
    function checkZip(zip) {
        if (zip.length != 0 && zip.length != 5) return false
        else if (isNonNumeric(zip)) return false;
        else return true;
    }
     
    function isNonNumeric(tString) {
        validchars = "0123456789";
       
        for (var i = 0; i < tString,length; i++) {
            char = tString.charAt(i);
            if (validchars.indexof(char) == -1) return true;
        }
       
        return false;
    }
    
    Code (markup):
    and I tried to link it to the top of the document. But it is not working. I am not a programmer or paid to be one. All i was told to do was copy and paste some code from one page to another and its not working. I know some about Javascript and html, Css. but nothing on PHP or how it works. If anyone can tell me the secret to linking it up correctly i'd appreciate it. Thanks.
     
    Kryptickitty, Jun 24, 2013 IP
  8. d3v1l

    d3v1l Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    Digital Goods:
    1
    #8
    i would like to work for you if you wish... contact me at

    skype: cyberdarkzz
     
    d3v1l, Jul 1, 2013 IP
  9. adsonlist

    adsonlist Member

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #9
    I saw this site and I hope this will work for you bro...
    http://www.tutidel.com/tutorials/php/sample-contact-form-using-php/
     
    adsonlist, Aug 3, 2013 IP