Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Contact Plugin
#1
Simple Contact Plugin v1.1
Updated: March 9th, 2010

http://internet54.com/getsimple/simple-contact-plugin

You will find a simple and easy to use contact plugin that will make it way to easy to create a usable form.
This version requires a small modification to the downloaded file. The next version will enable the ability to edit the file through the plugin panel.

With this plugin, you just have to know how to insert one line of code. Smile
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#2
this is great! now we can begin the process of pulling the contact form out of the core.
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#3
Awesome plugin. I have a suggested improvement though.

Code:
/*
Added by Brian Nowell
*/

$xval = rand(1, 9);
$yval = rand(1, 9);

$sc_to = 'my@email.com'; // Your email address
$sc_captcha_question = 'What is ' . $xval . ' + ' . $yval . '?'; // The question to display for the captcha
$sc_captcha = $xval + $yval; // This will approve or disapprove the form submission upon the correct answer.
                             // Change this to any string.

// END CHANGES FROM Brian Nowell

Change to this and it will make the CAPTCHA dynamic. All changes made in the EDITABLE Area of plugin.
Reply
#4
Brian, I think that is a good option for those using addition only captcha. I wanted to make this easy so that anyone can add a simple question and answer. IE: Is GS a good program? Yes.
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#5
We're all about simple. Here is ver. 2

Code:
$question_array = array('What is 4 + 8?'=>'12','What is the capitol of Texas?'=>'Austin','What is 5 - 1?'=>'4');
$qindex = array_rand($question_array);

$sc_captcha_question = $quindex; // The question to display for the captcha
$sc_captcha = $question_array[$qindex];

See if that works.
Reply
#6
This would be easier. Half the people here would screw up an array.
I will try it out later today.

Code:
// Create 3 questions
$q1 = 'What is 4 + 8?';
$q2 = 'What is the capitol of Texas?';
$q3 = 'What is 5 - 1?';

// The answers relative to the questions
$a1 = '12';
$a2 = 'Austin';
$a3 = '4';

$question_array = array($q1 => $a1, $q2 => $a2, $q3 => $a3);
$qindex = array_rand($question_array);

$sc_captcha_question = $quindex; // The question to display for the captcha
$sc_captcha = $question_array[$qindex];
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#7
I’d go with an array, but one configurable through the admin panel. That will make sure people won’t screw up.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#8
Newbie here! Is there something I'm missing? I can't seem to get this plugin to work. I've tried installing it on both GetSimple 2.0 and 2.01 versions, I've tried different permissions settings, and I've re-read and followed the instructions several times... nothing shows up.

Got this in when I turned on debug mode:

Notice: Undefined variable: thisfile in .../plugins/simple-contact.php on line 103
Notice: Undefined variable: thisfile in .../plugins/simple-contact.php on line 104

Any thoughts?

I'd be eternally grateful to have a working contact-form plugin with CAPTCHA!
Reply
#9
On line 101 you’ll find the following:
Code:
// Run the plugin in the theme
function sc_show() {
    add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
    add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));
}
Change these to the following:
Code:
// Run the plugin in the theme
add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));

I didn’t test it but it shouldn’t break the contact form in any way and should also fix your problem with $thisfile.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#10
matt Wrote:Newbie here! Is there something I'm missing? I can't seem to get this plugin to work. I've tried installing it on both GetSimple 2.0 and 2.01 versions, I've tried different permissions settings, and I've re-read and followed the instructions several times... nothing shows up.

Got this in when I turned on debug mode:

Notice: Undefined variable: thisfile in .../plugins/simple-contact.php on line 103
Notice: Undefined variable: thisfile in .../plugins/simple-contact.php on line 104

Any thoughts?

I'd be eternally grateful to have a working contact-form plugin with CAPTCHA!

Matt,

Make sure you've added this to your template (AT THE VERY TOP, LINE 1), AND that you've gone to that page and selected the template.
Code:
<?php if (function_exists('sc_show')) { sc_show(); } ?>

Also, change this:
Code:
function sc_show() {
    add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
    add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));
}


To this:
Code:
function sc_show() {
    global $thisfile;
    add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
    add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));
}
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#11
Thanks Internet54, that did the trick!
Reply
#12
Updated to Version 1.1 to include the $thisfile bug fix and also a captcha array.
More install information has been added to the website as well.
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#13
Excuse me for the probably stupid question but if I put <?php if (function_exists('sc_show')) { sc_show(); } ?> in the template (theme/mytheme/template.php), every pages will have the contact form no ?
So, I don't understand how to integrate it ?
Reply
#14
That would be correct, as long as that template is called by every page you create.
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#15
spilarix, you can have multiple template files (PHP-files) per theme. So you’d create a contact.php file with a template for the contact page, then when creating a new page to be the contact page you can select contact.php as the template under page options.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#16
OK ! Very good modularity :-)
It gives me a lot of good ideas to implement.

Thank you.
Reply
#17
Hi
I tested this plugin and randomly send e-mail or said

Captcha incorrect

http://www.psychoterapiaintegra.pl/konta...oterapeuta

i also tested it on your demo site

http://internet54.com/getsimple/simple-contact-plugin

and works randomly as on my site
kotos.net - webdesign / dtp / graphics / photography
Reply
#18
Hello,

You can improve your plugin :
1 - print (with concatenations) => echo (with commas) // performance
2 - Put a real action attribute
Code:
echo '<form action="',htmlentities($_SERVER['REQUEST_URI']),'" method="post" class="contactform"> // Security
3 - eregi replacement :
Code:
if (!preg_match("/[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}/", $sc_email)){ // Php 5.3 compatibility
4 - Managing an 'h2' title with a specific class for the form by passing an optionnal param to sc_form function
Code:
function sc_form ($formTitle = '')
{
...
if (!empty($formTitle))
{
  echo '<h2 class="contactFormTitle">', $formTitle, '</h2>';
}

Moreover, captcha implementation can't work like this.
You are comparing a local variable with a post variable => the local variable is overwritten on POST...
So, the comparison is between the answer to the previous question and the answer to the actual question.
Reply
#19
i add 2 fields and form don't work:
Code:
// PHP mail function
function sc_mail () {
    global $successmsg;
    global $sc_captcha;
    global $sc_to;
    $error = 0;
    if( isset($_POST['sc_submitted']) ) {
        $sc_email = $_POST['sc_email'];
        if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$sc_email )){
            $successmsg = "<div style=\"color:red; text-align:center;\">Adresse E-mail incorrecte.</div>";
            $error = 1;
        }
        if ( empty($_POST['sc_name']) || empty($_POST['sc_email']) || empty($_POST['sc_website']) || empty($_POST['sc_budget']) || empty($_POST['sc_subject']) || empty($_POST['sc_message'])) {
            $successmsg = "<div style=\"color:red; text-align:center;\">Remplissez tout les champs.</div>";
            $error = 1;
        }
        if ($_POST['sc_captcha'] != $sc_captcha) {
            $successmsg = "<div style=\"color:red; text-align:center;\">La r&eacute;ponse anti-spam est incorrecte.</div>";
            $error = 1;            
        }
        if ($error != 1){
            $from = "De: " .$_POST['sc_email'];
            $message = "Nom: ".$_POST['sc_name'];
            $message = $message."\n". "E-mail: ".$_POST['sc_email'];
            $message = "SiteWeb: ".$_POST['sc_website'];
            $message = "Budget du projet: ".$_POST['sc_budget'];
            $message = $message."\n". "Message: ".$_POST['sc_message'];
            mail($sc_to, $_POST['sc_subject'], $message, $from);
            $successmsg = "<div style=\"color:red; text-align:center;\">Merci...Votre message a r&eacute;tr&eacute; envoyr&eacute; avec succr&egrave;s.</div>";
            //Clear values
            $_POST = array();
        }
    } else {
        $successmsg = "<div style=\"color:red; text-align:center;\">TOTO ???????</div>";
    }
}

// Form Display
function sc_form () {
    global $successmsg;
    global $sc_captcha_question;
    print '<div id="contact"><h2>Demande de Devis</h2>';
    print $successmsg;
    print '<form action="#contact" method="post" accept-charset="utf-8" enctype="multipart/form-data">
        <div class="row">
            <div class="column w2">
                <p>
                    <label for="sc_name">Nom &amp; Pr&eacute;nom *</label> <input id="sc_name" name="sc_name" type="text" value="" /></p>
                <p>
                    <label for="sc_email">Votre E-mail *</label> <input id="sc_email" name="sc_email" type="text" value="" /></p>
                <p>
                    <label for="sc_subject">Object </label> <input id="sc_subject" name="sc_subject" type="text" value="" /></p>                    
            </div>
            <div class="column w2">
                <p>
                    <label for="sc_website">Votre SiteWeb</label> <input id="sc_website" name="sc_website" type="text" value="" /></p>
                <p>
                    <label for="sc_budget">Votre budget</label> <input id="sc_budget" name="sc_budget" type="text" value="" /></p>
                <p>
                    <label for="sc_captcha">Question Anti-Spam *:</label><em style="color:green;"> '.$sc_captcha_question.'</em> <input id="sc_captcha" name="sc_captcha" type="text" value="" /></p>                    
            </div>
        </div>
        <div class="row">
            <p>
                <label for="sc_message">Votre Projet *</label><textarea cols="40" id="sc_message" name="sc_message" rows="8"></textarea></p>
                <button type="submit" id="contact-submit" name="contact-submit">Envoyer ma demande</button></div>
    <input type="hidden" value="true" name="sc_submitted" />
    </form>
    </div>';
}

Any idea please ?
Sorry for my little english :rolleyes:

Thx for GS
Reply
#20
My messages are not sent
Code:
<?php
////////////////////////////////////////////////////////
// Simple Contact v1.1 for GetSimple 2.X
// Plugin created by internet54 - http://internet54.com/
// Author: David Guerra - david@internet54.com
// Last Edited on March 9th, 2010
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
// EDITABLE OPTIONS

// Your email address
$sc_to = 'bes64@mail.ru';

// Create 3 questions
$q1 = 'Сложите 4 + 8?';
$q2 = 'Столица России?';
$q3 = 'Мы живем на Марсе?';
// The answers relative to the questions
$a1 = '12';
$a2 = 'Москва';
$a3 = 'нет';
// DO NOT EDIT PAST THIS LINE
////////////////////////////////////////////////////////

# get correct id for plugin
$thisfile = basename(__FILE__, ".php");

# register plugin
register_plugin(
    $thisfile,    # ID of plugin, should be filename minus php
    'Simple Contact',    # Title of plugin
    '1.1',    # Version of plugin
    'internet54',    # Author of plugin
    'http://internet54.com',    # Author URL
    'This plugin will install a simple contact form into your website.',    # Plugin Description
    'plugins',    # Page type of plugin
    'sc_options'    # Function that displays content
);

# Creates a menu option on the Admin/Theme sidebar
//add_action('admin-menu','createSideMenu',array($thisfile,'Plugin Gal'));
add_action('plugins-sidebar', 'createSideMenu', array($thisfile, 'Контактная форма'));
/////////////////////////////////////////

// Captcha maker thanks to Brian Nowell for the input
$question_array = array($q1 => $a1, $q2 => $a2, $q3 => $a3);
$qindex = array_rand($question_array);

$sc_captcha_question = $qindex;
$sc_captcha = $question_array[$qindex];

// Show options in plugin page
function sc_options() {
    print "<h2>Как создать форму с каптчей?</h2>
    <p>Создайте страницу \"Контакты\".<br />
    <p>Вставьте ниже, выше или вместо текста вот этот код: <strong>&lt;? if (function_exists('sc_show')) { sc_show(); } ?&gt;</strong><br />
    ÃÂ˜ все? И все...</p>";
}

// PHP mail function
function sc_mail () {
    global $successmsg;
    global $sc_captcha;
    global $sc_to;
    $error = 0;
    if( isset($_POST['sc_submitted']) ) {
        $sc_email = $_POST['sc_email'];
        if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$sc_email )){
            $successmsg = "<div style=\"color:red; text-align:center;\">Invalid email address entered.</div>";
            $error = 1;
        }
        if ( empty($_POST['sc_name']) || empty($_POST['sc_email']) || empty($_POST['sc_subject']) || empty($_POST['sc_message'])) {
            $successmsg = "<div style=\"color:red; text-align:center;\">Please fill out all fields.</div>";
            $error = 1;
        }
        if ($_POST['sc_captcha'] != $sc_captcha) {
            $successmsg = "<div style=\"color:red; text-align:center;\">Captcha answer incorrect.</div>";
            $error = 1;            
        }
        if ($error != 1){
            $from = "From: " .$_POST['sc_email'];
            $message = "Name: ".$_POST['sc_name'];
            $message = $message."\n". "E-mail: ".$_POST['sc_email'];
            $message = $message."\n". "Message: ".$_POST['sc_message'];
            mail($sc_to, $_POST['sc_subject'], $message, $from);
            $successmsg = "<div style=\"color:red; text-align:center;\">Thank you... The form was successfully sent.</div>";
            //Clear values
            $_POST = array();
        }
    } else {
        $successmsg = "";
    }
}

// Form Display
function sc_form () {
    global $successmsg;
    global $sc_captcha_question;
    print '<div id="sc-container">';
    print $successmsg;
    echo '<form action="" method="post" class="contactform">
    <div><b>Имя:</b> <input class="text" type="text" value="" name="sc_name" /></div>
    <div><b>E-mail:</b> <input class="text" type="text" value="" name="sc_email" /></div>
    <div><b>Тема:</b> <input class="text" type="text" value="" name="sc_subject" /></div>
    <div><b>Вопрос:</b> <select name="qwest"><option selected="selected">2222</option><option>333</option></select></div>
    <div><b>Сообщение:</b> <textarea class="text" name="sc_message" ></textarea></div>
    <div><b>Каптча:</b> '.$sc_captcha_question.'<br /> <input class="text" type="text" value="" name="sc_captcha" /></div>
    <div><input type="submit" value="Отправить" id="contact-submit" name="contact-submit" /></div>
    <input type="hidden" value="true" name="sc_submitted" />
    </form>
    </div>';
}

// Run the plugin in the theme
function sc_show() {
    global $thisfile;
    add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
    add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));
}
?>

wrong?
Reply
#21
mail receiving, but only 3 points Rolleyes
Reply
#22
Like I said in #18, the plugin is unusable.
Please wait for an update of the author.
Reply
#23
I learned how to add new elements to the form and everything works
Code:
if ($error != 1){
            $from = "From: " .$_POST['sc_email'];
            $message = "Имя: ".$_POST['sc_name'];
            $message = $message."\n". "E-mail: ".$_POST['sc_email'];

$message = $message."\n". "Вопрос: ".$_POST['sc_qwest'];     // added element

            $message = $message."\n". "Тема: ".$_POST['sc_subject'];
            $message = $message."\n". "Сообщение: ".$_POST['sc_message'];

mail($sc_to, $_POST['sc_qq'], $message, $from);                      // invisible element

            $successmsg = "<div style=\"color:green; text-align:center;\">Ваше сообщение отправлено.</div>";
            //Clear values
            $_POST = array();
        }
    } else {
        $successmsg = "";
    }
}

// Form Display
function sc_form () {
    global $successmsg;
    global $sc_captcha_question;
    print '<div id="sc-container">';  
    print $successmsg;
    echo '<form action="" method="post" class="contactform">
    <div><b>Имя:</b> <input class="text" type="text" value="" name="sc_name" /></div>
    <div><b>E-mail:</b> <input class="text" type="text" value="" name="sc_email" /></div>

<div><b>Вопрос:</b> <select class="text" name="sc_qwest"><option>11111111</option></select></div>     // added element

    <div><b>Тема:</b> <input class="text" type="text" value="" name="sc_subject" /></div>

<div style="display:none;"><b>qqqqqqqq:</b> <input class="text" type="text" value="" name="sc_qq" /></div>               // invisible element

    <div><b>Сообщение:</b> <textarea class="text" name="sc_message" ></textarea></div>
    <div><b>Каптча:</b> '.$sc_captcha_question.'<br /> <input class="text" type="text" value="" name="sc_captcha" /></div>
    <div><input type="submit" value="Отправить" id="contact-submit" name="contact-submit" /></div>
    <input type="hidden" value="true" name="sc_submitted" />
    </form>
    </div>';
}
Reply
#24
I will work on getting an update soon.
I am aware of all the issues, but I have been real busy with work and life in general.
I am going to change the mail variables to work off an array, that way the admin can add as many fields as necessary and they will be included in the sent email.

If you are having problems with not having emails sent, it's because the captcha is implemented incorrectly. Just make all 3 questions and answers the same to override the problem. Sorry.
Clients always want to be able to change the content of their pages, but they are unwilling to do so.

Have you ever coded in your underwear before?
Reply
#25
somehow have to click on a button 2-3 times to a letter dispatched
Reply




Users browsing this thread: 3 Guest(s)