SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question New to PHP need help with form Process!!!

    Hi,
    IMPORTANT!! PLEASE HELP!!!
    I'm new to PHP and I need some help with a form I'm doing for a customer. Several fields need to be validated. I grabbed some code online to get me started, but have have to edit it. I'm not sure if it is the PHP that is causing it to not work or the js(validation). most all of the validation code works. The only thing that messes up is instead of it reading the field Company as Company it reads it as Your Message although i clearly labeled that field as id="Company". Other than that the validation is working but when i go to submit I get this error message:

    The page cannot be displayed
    The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

    Please try the following:

    Contact the Web site administrator if you believe that this request should be allowed.
    Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.

    HTTP Error 405 - The HTTP verb used to access this page is not allowed.
    Internet Information Services (IIS)

    Technical Information (for support personnel)

    Go to Microsoft Product Support Services and perform a title search for the words HTTP and 405.
    Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Setting Application Mappings, Securing Your Site with Web Site Permissions, and About Custom Error Messages.


    So Please help me here is the PHP I'm using (free_process.php):
    <?php

    if(isset($_POST

    ['Email_Address'])) {

    include 'free_settings.php';

    function died($error)

    {
    echo "Sorry, but there were error(s) found with the form you submitted. ";


    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";


    echo "Please go back and fix these errors.<br /><br />";
    die();
    }

    if(!isset($_POST['First_Name']) ||
    !isset($_POST['Last_Name']) ||


    !isset($_POST['Company']) ||
    !isset($_POST['Add_1']) ||
    !isset($_POST

    ['Add_2']) ||
    !isset($_POST['City']) ||
    !isset($_POST['State']) ||


    !isset($_POST['Zip']) ||
    !isset($_POST['Country']) ||
    !

    isset($_POST['Email_Address']) ||
    !isset($_POST['Telephone'])) {
    died

    ('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $first_name = $_POST['First_Name']; // required
    $last_name = $_POST

    ['Last_Name']; // required
    $email_from = $_POST['Email_Address']; // required


    $telephone = $_POST['Telephone_Number']; // not required
    $company = $_POST['Company'];

    // required
    $add_1 = $_POST['Add_1']; // required
    $add_2 = $_POST['Add_2']; // not

    required
    $city = $_POST['City']; // required
    $state = $_POST['State']; // required


    $zip = $_POST['Zip']; // required
    $country = $_POST['Country']; // required




    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';


    if(preg_match($email_exp,$email_from)==0) {
    $error_message .= 'The Email Address you

    entered does not appear to be valid.<br />';
    }
    if(strlen($first_name) < 2) {


    $error_message .= 'Your Name does not appear to be valid.<br />';
    }
    if(strlen($last_name)

    < 2) {
    $error_message .= 'Your Name does not appear to be valid.<br />';
    }
    if

    (strlen($error_message) > 0) {
    died($error_message);
    }
    $email_message = "Form

    details below.\r\n";

    function clean_string($string) {
    $bad = array

    ("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\r\n";
    $email_message

    .= "Last Name: ".clean_string($last_name)."\r\n";
    $email_message .= "Company:

    ".clean_string($Company)."\r\n";
    $email_message .= "Add_1: ".clean_string

    ($Add_1)."\r\n";
    $email_message .= "Add_2: ".clean_string($Add_2)."\r\n";


    $email_message .= "City: ".clean_string($City)."\r\n";
    $email_message .= "State:

    ".clean_string($State)."\r\n";
    $email_message .= "Zip: ".clean_string($Zip)."\r\n";


    $email_message .= "Country: ".clean_string($Country)."\r\n";
    $email_message .= "Email:

    ".clean_string($email_from)."\r\n";
    $email_message .= "Telephone: ".clean_string

    ($telephone)."\r\n";

    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n"

    .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    header("Location: $thankyou");
    ?>
    <script>location.replace('<?php echo $thankyou;?>')</script>
    <?php
    }
    die();
    ?>


    Here is the PHP settings I'm using as well free_settings.php):
    <?php

    $email_to = "contact@mentalnoteonline.com"; // your email address
    $email_subject = "New Register"; // email subject line
    $thankyou = "thankyou.htm"; // thank you page

    ?>


    Also here is the javascript I'm using (free_validation):

    function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
    return true;}
    function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
    return true;}
    function $$(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;}
    if(has_id(id)){return document.getElementById(id).value;}else{return;}}
    function $val(id){return document.getElementById(id);}
    function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');}
    var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\n';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];}
    tmp=false;}}
    if(!tmp){alert(error_message);}
    if(to_focus.length>0){document.getElementById(to_focus).focus();}
    return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};


    You can find the code source at this url www.mentalnoteonline.com/register/register.html


    It is also listed below:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Contact Us</title>
    <script src="free_validation.js"></script>
    <script>
    required.add('First_Name','NOT_EMPTY','Last Name');
    required.add('Last_Name','NOT_EMPTY','First Name');
    required.add('Email_Address','EMAIL','Email Address');
    required.add('Company','NOT_EMPTY','Your Message');
    required.add('Add_1','NOT_EMPTY','Address Line 1');
    required.add('City','NOT_EMPTY','City');
    required.add('State','NOT_EMPTY','State');
    required.add('Zip','NOT_EMPTY','Zip');
    required.add('Country','NOT_EMPTY','Country');
    </script>
    <link rel="stylesheet" type="text/css" href="free_styles.css">




    </head>
    <body>
    <div id="wrapper">

    <form name="contactformfree" method="post" action="free_process.php" onsubmit="return validate.check(this)">
    <table width="240px" class="cffree">
    <tr>
    <td colspan="2">
    <p style="text-align:center">Fields marked with <span class="required_star"> * </span> are required.</p>

    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="First_Name" class="required">First Name<span class="required_star"> * </span></label>
    </td>
    <td valign="bottom" class="cffree_td">

    <input type="text" name="First_Name" id="First_Name" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Last_Name" class="required">Last Name<span class="required_star"> * </span></label>
    </td>

    <td valign="bottom" class="cffree_td">
    <input type="text" name="Last_Name" id="Last_Name" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Company" class="required">Company/Practice<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Company" id="Company" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Add_1" class="required">Address Line 1<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Add_1" id="Add_1" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Add_2" class="not-required">Line 2</label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Add_2" id="Add_2" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="City" class="required">City<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="City" id="City" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="State" class="required">State<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="State" id="State" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Zip" class="required">Zip<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Zip" id="Zip" maxlength="80" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Country" class="required">Country<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Country" id="Country" maxlength="80" style="width:140px">
    </td>
    </tr>

    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Email_Address" class="required">Email<span class="required_star"> * </span></label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:140px">
    </td>
    </tr>
    <tr>
    <td align="right" valign="bottom" class="cffree_td">
    <label for="Telephone_Number" class="not-required">Phone</label>

    </td>
    <td valign="bottom" class="cffree_td">
    <input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:140px">
    </td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:center" class="cffree_td">
    <input type="submit" value=" Submit Form ">
    </td>

    </tr>
    </table>
    </form>
    </div>
    </body>
    </html>

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Dont suppose the Technical Information provided the verb in question - this seems to be a web server issue, rather than a code problem.

  3. #3
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might just happen to be correct because when posted on another server (which can be found at this address it seemed to actually do something but I still got an error message:

    Sorry, but there were error(s) found with the form you submitted. These errors appear below.

    We are sorry, but there appears to be a problem with the form you submitted.

    Please go back and fix these errors.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    Yeah. That actually indiciates with certainty that this is a problem with your web server setup - gonna flag this for moving to their forum, and then when we get that fixed, if you're still having issues, feel free to ask to have it moved back (or start a new thread)

    PS: Give you a hint; why are you requiring the existance of Add2 and Telephone in your PHP, when you dont require it on your form?


Tags for this Thread

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
  •