-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
151 lines (132 loc) · 3.95 KB
/
index.php
File metadata and controls
151 lines (132 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* mbForms
*
* Form Builder Plugin for WolfCMS
* Please keep this message intact when redistributing this plugin.
*
* @author Mike Barlow
* @email mike@mikebarlow.co.uk
*
* @file index.php
* @date 25/07/2010
*
*/
// check for some constants
if(!defined("CMS_ROOT"))
{
die("Invalid Action");
}
if(!defined("PLUGINS_ROOT")) // done to allow mbmenu to run on 0.6.0
{
define('PLUGINS_ROOT', CORE_ROOT.'/plugins');
}
if(!defined("MBFORMS"))
{
define('MBFORMS', PLUGINS_ROOT.'/mbforms');
}
// setup the plugin info
Plugin::setInfos(array(
'id' => 'mbforms',
'title' => 'mbForms',
'description' => 'Form Builder Plugin for WolfCMS',
'version' => '1.0.3',
'require_wolf_version' => '0.6',
'type' => 'both',
'author' => 'Mike Barlow',
'website' => 'http://www.mikebarlow.co.uk',
'update_url' => 'http://www.mikebarlow.co.uk/mbplugins_version.xml'
)
);
// Add the controller and tab for admin
Plugin::addController('mbforms', __('Form Builder'));
// Add the models to the autoLoader
AutoLoader::addFile('mbforms', MBFORMS.'/models/mbforms.php');
AutoLoader::addFile('mbformsItem', MBFORMS.'/models/mbformsItem.php');
if(defined("CMS_BACKEND"))
{
// add the JS file
Plugin::addJavascript('mbforms', 'js/mbforms.js');
} else
{
// define form display function
function mbForm($name)
{
$name = Record::escape($name);
if(isset($_POST['formaction']) && $_POST['formaction'] == 'send')
{
$form = mbforms::getForm($name, true);
$proceed = true;
if($form['form']->usecaptcha == '1')
{
$proceed = false;
include_once(MBFORMS."/recaptchalib.php");
$resp = recaptcha_check_answer($form['settings']['privatekey'],
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if($resp->is_valid)
{
$proceed = true;
} else
{
$captcha_error = __('You did not enter the correct captcha code, please try again!');
}
}
$required_errors = 0;
// check for required fields
foreach($form['items'] as $k => $item)
{
if($item->isrequired == '1')
{
if(!isset($_POST['form'][$item->id]) || empty($_POST['form'][$item->id]))
{
$required_errors++;
$array['errors'][$item->id] = __("You have not filled out ")."'".$item->label."'";
}
}
}
if($proceed === true && $required_errors === 0)
{
// let's email!
// construct the body
$email_body = __("There has been an email submission via :name. See below for submission details",array(':name'=>$name))."<br /><br />";
foreach($form['items'] as $k => $item)
{
$email_body .= "<strong>".$item->label.":</strong> ".nl2br($_POST['form'][$item->id])."<br />";
}
use_helper('Email');
// setup email class
$Email = new Email(array('mailtype' => 'html'));
$Email->from(Setting::get('admin_email'), 'mbForms - '.$form['form']->formname);
$Email->to($form['form']->emailto);
$Email->subject($form['form']->formname.' '.__('Submission'));
$Email->message($email_body);
$send = $Email->send();
if($send)
{
$tpl = explode('.', $form['form']->successtpl, 2);
echo new View('../../plugins/mbforms/views/results/'.$tpl['0']);
} else
{
$array['formvalues'] = $_POST['form'];
$array['errors']['failed_to_send'] = __('Failed to send your email! Please try again');
mbforms::setValues($array);
echo mbforms::getForm($name);
}
} else
{
$array['formvalues'] = $_POST['form'];
if(isset($captcha_error))
{
$array['errors']['captcha_error'] = $captcha_error;
}
mbforms::setValues($array);
echo mbforms::getForm($name);
}
} else
{
echo mbforms::getForm($name);
}
}
}