Posts: 339
Threads: 27
Joined: Nov 2009
Are you able to embed php into a page when it's in a plugin?
For example. I want to add my php code for the contact form I'm working on.
Here's what I have that is causing the problem. When I have this coded in my plugin, the ENTIRE site, admin and all, will not load and stays a blank white screen.
Any suggestions?
Code: function sc_mail () {
if( isset($_POST["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 ($error !== 1){
$from = "From: " .$_POST["sc_email"];
$message = "Name: ".$_POST["name"];
$message = $message."\n". "E-mail: ".$_POST["sc_email"];
$message = $message."\n". "Message: ".$_POST["sc_message"];
mail(global $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 = "";
}
}
It appears that I can print html or text, but I can't embed php code.
Thanks.
Posts: 972
Threads: 27
Joined: Aug 2009
What do you mean by embed? Define a callable function to use on your site? That’s very possible, just look at Mike’s CustomFields plugin which adds functions for you to echo those fields in your templates.
Posts: 339
Threads: 27
Joined: Nov 2009
^ Yes, my plugin can and does display my function (which creates a contact form). The problem that I'm running into is that it isn't importing php code itself into the page.
I don't really know why.
Posts: 1,848
Threads: 86
Joined: Aug 2009
- What are you expecting to see on the page?
- Admin page or template page?
- What do you see on the page now?
- 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!
Posts: 339
Threads: 27
Joined: Nov 2009
2010-03-05, 12:24:21
(This post was last modified: 2010-03-05, 12:24:58 by ChrisFrank.)
Here is the entire plugin so far. It makes EVERY page not load.
Code: <?php
////////////////////////////////////////////////////////
// Simple Contact for GetSimple 2.X
// Plugin created by internet54 - http://internet54.com/
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// EDITABLE OPTIONS
$sc_to = 'my@email.com'; // Your email address
$sc_captcha = '7'; // This will approve or disapprove the form submission upon the correct answer. Change this to any string.
// 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.0', # 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, 'Simple Contact'));
/////////////////////////////////////////
// Create gallery folder if doesn't exhist
// Also show options in plugin page
function sc_options() {
// Get gallery dir, check for existance, make if not found
print "<h2>How to get this thing working?</h2>
<p>Please add this line of code in your template files where you want your contact form to display. For example
place this code into your contact template file so it displays on that page. This plugin is set to display the form right below the content of the page.<br />
<p><strong>if (function_exists('sc_show')) { sc_show(); }</strong><br />
Make sure to wrap it in php tags.</p>";
}
// PHP mail function
function sc_mail () {
if( isset($_POST["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 ($error !== 1){
$from = "From: " .$_POST["sc_email"];
$message = "Name: ".$_POST["name"];
$message = $message."\n". "E-mail: ".$_POST["sc_email"];
$message = $message."\n". "Message: ".$_POST["sc_message"];
mail(global $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 () {
print '<div id="sc-container">';
if ($_POST['sc_submitted'] == 'true') {
print '<div id="sc-successmsg">';
print $successmsg;
print '</div>';
}
print '<form action="" method="post" class="contactform" >
<div><b>Name:</b> <input class="text" type="text" value="" name="sc_name" /></div>
<div><b>Email:</b> <input class="text" type="text" value="" name="sc_email" /></div>
<div><b>Subject:</b> <input class="text" type="text" value="" name="sc_subject" /></div>
<div><b>Message:</b> <textarea class="text" name="sc_body" ></textarea></div>
<div><b>What is 4+3? <input class="text" type="text" value="" name="sc_captcha" /></div>
<div><input type="submit" value="Send Email" 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() {
add_action('content-top', 'sc_mail', array($thisfile, 'Simple Contact'));
add_action('content-bottom', 'sc_form', array($thisfile, 'Simple Contact'));
}
?>
Posts: 339
Threads: 27
Joined: Nov 2009
Apparently you can't do a global call inside a plugin function.
Posts: 103
Threads: 12
Joined: Aug 2009
Turn on debug mode in gsconfig.php to see the issue
# Turn on debug mode
#define('GSDEBUG', TRUE);
to
# Turn on debug mode
define('GSDEBUG', TRUE);
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
Posts: 103
Threads: 12
Joined: Aug 2009
also place all 'add_action' into the bottom of your function otherwise you receive a PHP warning
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
Posts: 103
Threads: 12
Joined: Aug 2009
Also do you mean, in your content area of a page, you want to write:
<?php display_form(); ?>
Style thing?
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
Posts: 103
Threads: 12
Joined: Aug 2009
2010-03-05, 13:07:18
(This post was last modified: 2010-03-05, 13:13:50 by haplo37.)
Error:
Parse error: syntax error, unexpected T_GLOBAL, expecting ')' in /path/plugins/simple-contact.php on line 64
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
Posts: 103
Threads: 12
Joined: Aug 2009
Change line 64 to:
mail($sc_to, $_POST['sc_subject'], $message, $from);
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
Posts: 339
Threads: 27
Joined: Nov 2009
Thanks, I got everything fixed.
I managed to get the globals to work. Guess my brain was fried.
http://internet54.com/getsimple/simple-contact-plugin
Posts: 103
Threads: 12
Joined: Aug 2009
Ohh don't worry, important thing is it works!
Nothing is too difficult... anything is possible.
'But you tried, and you failed.. the important thing? never try'
|