ZapForm.php

<?php
/*
Plugin Name: ZapForm
Description: Smple contact page to demo code for plugin.
Version: 0.1
Author: GGarchar
Author URI: http://saratogameetup.com/
Plugin URI: http://saratogameetup.com/category/plugin-php/
*/

register_activation_hook(__FILE__,”createPage”);

function createPage () {
$page[‘post_content’] = ‘[zapform]’;
$page[‘post_parent’] = 0;
$page[‘post_status’] = ‘publish’;
$page[‘post_title’] = ‘Zap Form Page’;
$page[‘post_type’] = ‘page’;
wp_insert_post ($page);
}

add_shortcode( ‘zapform’, ‘evaluateForm’ );

function evaluateForm ( $atts ) {
if (isset($_POST[‘submitForm’])) {
$name = $_POST[‘formName’];
$email = $_POST[‘formEmail’];
$subject = $_POST[‘formSubject’];
$level = $_POST[‘expertLevel’];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
sendMail ($name, $email, $subject, $level);
echo “Thanks! Your data has been sent.”;
}
else { echo “Need to enter a valid Email Address”; }
}
else { // INITIALIZE VALUES
$name = “”;
$email = “”;
$subject = “”;
$level = “”;
}
include(“html.txt”);
}

function sendMail ( $name, $email, $subject, $level ) {
$to = myname@mydomain.com”; // CHANGE THIS TO YOURS
$message = $name . ” at ” . $email . ” is a “;
$message .= $level . “-level WordPress Expert”;
mail ( $to, $subject, $message );
}

?>

Advertisements