#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Cool PHP contact form


    Hi Everyone

    I have a contact form on my wordpress site and have have all fields set out. However i have this contact form from my theme and i want to take validation off (as i dont mind if people dont fill their email out) and i want to add another field.

    I cant figure how to add another field to the php file that send the data via email. Field is added in the front end in the form but i cant get the php ajax file to pick it up. I also cant take the validation off email without it failing.

    contant from php
    PHP Code:
    <?php
    /* 
        Spark  Simple and Effective 
        Rev. 6
    */

    // Load WordPress
    require( '../../../../../wp-load.php' );

    // Grab all Spark theme options
    global $spark_options;
    $spark_options get_spark_options();

    // Get user's email (defined in the OptionTree backend)
    $to_email $spark_options['spark_user_email'];


    $aErrors = array();
    $aResults = array();

    /* Functions */

    function stripslashes_if_required($sContent) {

        if(
    get_magic_quotes_gpc()) {
            return 
    stripslashes($sContent);
        } else {
            return 
    $sContent;
        }
    }

    function 
    get_current_url_path() {

        
    $sPageUrl "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        
    $count strlen(basename($sPageUrl));
        
    $sPagePath substr($sPageUrl,0, -$count);
        return 
    $sPagePath;
    }

    function 
    output($aErrors = array(), $aResults = array()){ // Output JSON

        
    $bFormSent = empty($aErrors) ? true false;
        
    $aCombinedData = array(
            
    'bFormSent' => $bFormSent,
            
    'aErrors' => $aErrors,
            
    'aResults' => $aResults
            
    );
            
        
    header('Content-type: application/json');
        echo 
    json_encode($aCombinedData);
        exit;
    }

    // Check supported version of PHP
    if (version_compare(PHP_VERSION'5.2.0''<')) { // PHP 5.2 is required for the safety filters used in this script

        
    $aErrors[] = 'Unsupported PHP version. <br /><em>Minimum requirement is 5.2.<br />Your version is 'PHP_VERSION .'.</em>';
        
    output($aErrors);
    }


    if (!empty(
    $_POST)) { // Form posted?

        // Get a safe-sanitized version of the posted data
        
    $sFromEmail filter_input(INPUT_POST'email'FILTER_SANITIZE_EMAIL);
        
    $sFromName filter_input(INPUT_POST'name'FILTER_SANITIZE_STRINGFILTER_FLAG_STRIP_LOW);
        
    $sMessage  stripslashes_if_required($_POST['message']);
        
    $sMessage .= "\r\n--\r\nEmail sent from "get_current_url_path();
        
        
    $sHeaders  "From: '$sFromName' <$sFromEmail>"."\r\n";
        
    $sHeaders .= "Reply-To: '$sFromName' <$sFromEmail>";
        
        if (
    filter_var($sFromEmailFILTER_VALIDATE_EMAIL)) { // Valid email format?
        
            
    $bMailSent mail($to_email"New inquiry from $sFromName"$sMessage$sHeaders);
            if (
    $bMailSent) {
                
    $aResults[] = "Message sent, thank you!";
            } else {
                
    $aErrors[] = "Message not sent, please try again later.";
            }

        } else {
            
    $aErrors[] = 'Invalid email address.';
        }
    } else { 
    // Nothing posted
        
    $aErrors[] = 'Empty data submited.';
    }

      
    output($aErrors$aResults);
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0
    Hey this just my recommendation but here is code for a contact form plugin that i use all the time. It is very basic and the code is pretty easy to follow.

    codetutorial.caroshaw.com/contact_form_php_arvixe.php

IMN logo majestic logo threadwatch logo seochat tools logo