Contact Form by BestWebSoft - Version 2011.05.27

Version Description

Download this release

Release Info

Developer bestwebsoft
Plugin Icon 128x128 Contact Form by BestWebSoft
Version 2011.05.27
Comparing to
See all releases

Version 2011.05.27

Files changed (5) hide show
  1. contact_form.php +327 -0
  2. contact_form_style.css +2 -0
  3. readme.txt +62 -0
  4. screenshot-1.jpg +0 -0
  5. screenshot-2.jpg +0 -0
contact_form.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Contact Form Plugin
4
+ * @version 1
5
+ */
6
+ /*
7
+ Plugin Name: Contact Form Plugin
8
+ Plugin URI: http://bestwebsoft.com/plugin/
9
+ Description: Plugin for portfolio.
10
+ Author: BestWebSoft
11
+ Version: 1.01
12
+ Author URI: http://bestwebsoft.com/
13
+ License: GPLv2 or later
14
+ */
15
+ /* Copyright 2011 BestWebSoft ( plugin@bestwebsoft.com )
16
+
17
+ This program is free software; you can redistribute it and/or modify
18
+ it under the terms of the GNU General Public License, version 2, as
19
+ published by the Free Software Foundation.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
+ */
30
+ wp_enqueue_style( 'cntctfrmStylesheet', WP_PLUGIN_URL .'/contact-form-plugin/contact_form_style.css' );
31
+
32
+ // Add option page in admin menu
33
+ if( ! function_exists( 'cntctfrm_admin_menu' ) ) {
34
+ function cntctfrm_admin_menu() {
35
+ add_options_page( "Contact Form Options", "Contact Form", 'manage_options', __FILE__, 'cntctfrm_settings_page' );
36
+
37
+ //call register settings function
38
+ add_action( 'admin_init', 'cntctfrm_settings' );
39
+ }
40
+ }
41
+
42
+ // Register settings for plugin
43
+ if( ! function_exists( 'cntctfrm_settings' ) ) {
44
+ function cntctfrm_settings() {
45
+ global $cntctfrm_options;
46
+
47
+ $cntctfrm_option_defaults = array(
48
+ 'cntctfrm_user_email' => 'admin',
49
+ 'cntctfrm_custom_email' => '',
50
+ 'cntctfrm_select_email' => 'user',
51
+ );
52
+
53
+ if( ! get_option( 'cntctfrm_options' ) )
54
+ add_option( 'cntctfrm_options', $cntctfrm_option_defaults, '', 'yes' );
55
+
56
+ $cntctfrm_options = get_option( 'cntctfrm_options' );
57
+
58
+ $cntctfrm_options = array_merge( $cntctfrm_option_defaults, $cntctfrm_options );
59
+ }
60
+ }
61
+
62
+ // Add settings page in admin area
63
+ if( ! function_exists( 'cntctfrm_settings_page' ) ) {
64
+ function cntctfrm_settings_page() {
65
+ global $cntctfrm_options;
66
+ $error = "";
67
+ // Save data for settings page
68
+ if( isset( $_REQUEST['cntctfrm_form_submit'] ) ) {
69
+ $cntctfrm_options_submit['cntctfrm_user_email'] = $_REQUEST['cntctfrm_user_email'];
70
+ $cntctfrm_options_submit['cntctfrm_custom_email'] = $_REQUEST['cntctfrm_custom_email'];
71
+ $cntctfrm_options_submit['cntctfrm_select_email'] = $_REQUEST['cntctfrm_select_email'];
72
+ $cntctfrm_options = array_merge( $cntctfrm_options, $cntctfrm_options_submit );
73
+ if( 'user' == $cntctfrm_options_submit['cntctfrm_select_email'] ) {
74
+ if( false !== get_userdatabylogin( $cntctfrm_options_submit['cntctfrm_user_email'] ) )
75
+ {
76
+ update_option( 'cntctfrm_options', $cntctfrm_options, '', 'yes' );
77
+ $message = "Options saved.";
78
+ }
79
+ else {
80
+ $error = "Such user is not exist. Settings are not saved.";
81
+ }
82
+ }
83
+ else {
84
+ if( $cntctfrm_options_submit['cntctfrm_custom_email'] != "" && preg_match( "/^(?:[a-z0-9]+(?:[-_\.]?[a-z0-9]+)?@[a-z0-9]+(?:\.?[a-z0-9]+)?\.[a-z]{2,5})$/i", trim( $cntctfrm_options_submit['cntctfrm_custom_email'] ) ) ) {
85
+ update_option( 'cntctfrm_options', $cntctfrm_options, '', 'yes' );
86
+ $message = "Options saved.";
87
+ }
88
+ else {
89
+ $error = "Please input correct email. Settings are not saved.";
90
+ }
91
+ }
92
+ }
93
+ // Display form on the setting page
94
+ ?>
95
+ <div class="wrap">
96
+ <div class="icon32" id="icon-options-general"><br></div>
97
+ <h2>Contact Form Options</h2>
98
+ <div class="updated fade" <?php if( ! isset( $_REQUEST['cntctfrm_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div>
99
+ <div class="error" <?php if( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div>
100
+ <form method="post" action="options-general.php?page=contact-form-plugin/contact_form.php">
101
+ <span style="border-bottom:1px dashed;margin-bottom:15px;">
102
+ <p>If you would like to add a Contact Form to your website, just copy and put this shortcode onto your post or page: [contact_form]</p>
103
+ If information in the below fields are empty then the message will be send to an address which was specified during registration.
104
+ </span>
105
+ <table class="form-table">
106
+ <tr valign="top">
107
+ <th scope="row" style="width:195px;">Use email of wordpress user: </th>
108
+ <td>
109
+ <input type="radio" name="cntctfrm_select_email" value="user" <?php if($cntctfrm_options['cntctfrm_select_email'] == 'user') echo "checked=\"checked\" "; ?>/>
110
+ </td>
111
+ <td>
112
+ <input type="text" name="cntctfrm_user_email" value="<?php echo $cntctfrm_options['cntctfrm_user_email']; ?>" />
113
+ <span style="color: rgb(136, 136, 136); font-size: 10px;clear:both;">Set a name of user wo will get messages from a contact form.</span>
114
+ </td>
115
+ </tr>
116
+ <tr valign="top">
117
+ <th scope="row" style="width:195px;">Use this email: </th>
118
+ <td>
119
+ <input type="radio" name="cntctfrm_select_email" value="custom" <?php if($cntctfrm_options['cntctfrm_select_email'] == 'custom') echo "checked=\"checked\" "; ?>/>
120
+ </td>
121
+ <td>
122
+ <input type="text" name="cntctfrm_custom_email" value="<?php echo $cntctfrm_options['cntctfrm_custom_email']; ?>" />
123
+ <span style="color: rgb(136, 136, 136); font-size: 10px;clear:both;">Set an email address which will be used for messages receiving.</span>
124
+ </td>
125
+ </tr>
126
+ </tr>
127
+ </table>
128
+ <input type="hidden" name="cntctfrm_form_submit" value="submit" />
129
+ <p class="submit">
130
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
131
+ </p>
132
+ </form>
133
+ </div>
134
+ <?php
135
+ }
136
+ }
137
+
138
+ // Display contact form in front end - page or post
139
+ if( ! function_exists( 'cntctfrm_display_form' ) ) {
140
+ function cntctfrm_display_form() {
141
+ global $error_message;
142
+ $content = "";
143
+
144
+ $result = "";
145
+ // If contact form submited
146
+ $name = isset( $_REQUEST['cntctfrm_contact_name'] ) ? $_REQUEST['cntctfrm_contact_name'] : "";
147
+ $email = isset( $_REQUEST['cntctfrm_contact_emai'] ) ? $_REQUEST['cntctfrm_contact_emai'] : "";
148
+ $subject = isset( $_REQUEST['cntctfrm_contact_subject'] ) ? $_REQUEST['cntctfrm_contact_subject'] : "";
149
+ $message = isset( $_REQUEST['cntctfrm_contact_message'] ) ? $_REQUEST['cntctfrm_contact_message'] : "";
150
+ if( isset( $_REQUEST['cntctfrm_contact_action'] ) )
151
+ {
152
+ // Check all input data
153
+ $result = cntctfrm_check_form();
154
+ }
155
+ // If it is good
156
+ if( true === $result ) {
157
+ $content .= __( "Thank you for contact.", "cmntfrm" );
158
+ }
159
+ else if( false === $result )
160
+ {
161
+ // If email not be delivered
162
+ $error_message['error_form'] = __( "Sorry, your e-mail could not be delivered.", "cmntfrm" );
163
+ }
164
+ else {
165
+ // Output form
166
+ $content .= '<form method="post" id="cntctfrm_contact_form" action="" enctype="multipart/form-data">';
167
+ if( isset( $error_message['error_form'] ) ) {
168
+ $content .= '<div style="text-align: left; color: red;">'.$error_message['error_form'].'</div>';
169
+ }
170
+ $content .= '<div style="text-align: left; padding-top: 5px;">
171
+ <label for="cntctfrm_contact_name">Name:<span class="required"> *</span></label>
172
+ </div>';
173
+ if( isset( $error_message['error_name'] ) ) {
174
+ $content .= '<div style="text-align: left; color: red;">'.$error_message['error_name'].'</div>';
175
+ }
176
+ $content .= '<div style="text-align: left;">
177
+ <input class="text" type="text" size="40" value="'.$name.'" name="cntctfrm_contact_name" id="cntctfrm_contact_name" style="text-align: left; margin: 0;">
178
+ </div>
179
+
180
+ <div style="text-align: left;">
181
+ <label for="cntctfrm_contact_email">E-Mail Address:<span class="required"> *</span></label>
182
+ </div>';
183
+ if( isset( $error_message['error_email'] ) ) {
184
+ $content .= '<div style="text-align: left; color: red;">'.$error_message['error_email'].'</div>';
185
+ }
186
+ $content .= '<div style="text-align: left;">
187
+ <input class="text" type="text" size="40" value="'.$email.'" name="cntctfrm_contact_emai" id="cntctfrm_contact_email" style="text-align: left; margin: 0;">
188
+ </div>
189
+
190
+ <div style="text-align: left;">
191
+ <label for="cntctfrm_contact_subject1">Subject:<span class="required"> *</span></label>
192
+ </div>';
193
+ if( isset( $error_message['error_subject'] ) ) {
194
+ $content .= '<div style="text-align: left; color: red;">'.$error_message['error_subject'].'</div>';
195
+ }
196
+ $content .= '<div style="text-align: left;">
197
+ <input class="text" type="text" size="40" value="'.$subject.'" name="cntctfrm_contact_subject" id="cntctfrm_contact_subject" style="text-align: left; margin: 0;">
198
+ </div>
199
+
200
+ <div style="text-align: left;">
201
+ <label for="cntctfrm_contact_message">Message:<span class="required"> *</span></label>
202
+ </div>';
203
+ if( isset( $error_message['error_message'] ) ) {
204
+ $content .= '<div style="text-align: left; color: red;">'.$error_message['error_message'].'</div>';
205
+ }
206
+ $content .= '<div style="text-align: left;">
207
+ <textarea rows="10" cols="30" name="cntctfrm_contact_message" id="cntctfrm_contact_message1">'.$message.'</textarea>
208
+ </div>';
209
+ $content .= apply_filters( 'cntctfrm_display_captcha' , $error_message );
210
+
211
+ $content .= '<div style="text-align: left; padding-top: 8px;">
212
+ <input type="hidden" value="send" name="cntctfrm_contact_action">
213
+ <input type="submit" value="Submit" style="cursor: pointer; margin: 0pt; text-align: center;margin-bottom:10px;">
214
+ </div>
215
+ </form>';
216
+ return $content ;
217
+ }
218
+ }
219
+ }
220
+
221
+ // Check all input data
222
+ if( ! function_exists( 'cntctfrm_check_form' ) ) {
223
+ function cntctfrm_check_form() {
224
+ global $error_message;
225
+ $result = "";
226
+ // Error messages array
227
+ $error_message = array();
228
+ $error_message['error_name'] = __( "Your name is required.", "cmntfrm" );
229
+ $error_message['error_email'] = __( "A proper e-mail address is required.", "cmntfrm" );
230
+ $error_message['error_subject'] = __( "Subject text is required.", "cmntfrm" );
231
+ $error_message['error_message'] = __( "Message text is required.", "cmntfrm" );
232
+ $error_message['error_form'] = __( "Please make corrections below and try again.", "cmntfrm" );
233
+ // Check information wich was input in fields
234
+ if( "" != $_REQUEST['cntctfrm_contact_name'] )
235
+ unset( $error_message['error_name'] );
236
+ if( "" != $_REQUEST['cntctfrm_contact_emai'] && preg_match( "/^(?:[a-z0-9]+(?:[-_\.]?[a-z0-9]+)?@[a-z0-9]+(?:\.?[a-z0-9]+)?\.[a-z]{2,5})$/i", trim( $_REQUEST['cntctfrm_contact_emai'] ) ) )
237
+ unset( $error_message['error_email'] );
238
+ if( "" != $_REQUEST['cntctfrm_contact_subject'] )
239
+ unset( $error_message['error_subject'] );
240
+ if( "" != $_REQUEST['cntctfrm_contact_message'] )
241
+ unset( $error_message['error_message'] );
242
+ // If captcha plugin exists
243
+ if( ! apply_filters( 'cntctfrm_check_form', $_REQUEST ) )
244
+ $error_message['error_captcha'] = __( "Please complete the CAPTCHA.", "cmntfrm" );
245
+ if( 1 == count( $error_message ) ) {
246
+ unset( $error_message['error_form'] );
247
+ // If all is good - send mail
248
+ $result = cntctfrm_send_mail();
249
+ }
250
+ return $result;
251
+ }
252
+ }
253
+
254
+ // Send mail function
255
+ if( ! function_exists( 'cntctfrm_send_mail' ) ) {
256
+ function cntctfrm_send_mail() {
257
+ global $cntctfrm_options;
258
+ $to = "";
259
+ if($cntctfrm_options['cntctfrm_select_email'] == 'user') {
260
+ if( false !== $user = get_userdatabylogin($cntctfrm_options_submit['cntctfrm_user_email'] ) )
261
+ $to = $user['user_email'];
262
+ }
263
+ else {
264
+ $to = $cntctfrm_options['cntctfrm_custom_email'];
265
+ }
266
+ if( "" == $to ) {
267
+ // If email options are not certain choose admin email
268
+ $to = get_option("admin_email");
269
+ }
270
+ if( "" != $to ) {
271
+ // subject
272
+ $subject = $_REQUEST['cntctfrm_contact_subject'];
273
+ // message
274
+ $message = '
275
+ <html>
276
+ <head>
277
+ <title>Contact from'.get_bloginfo('name').'</title>
278
+ </head>
279
+ <body>
280
+ <table>
281
+ <tr>
282
+ <td width="160">Name</td><td>'.$_REQUEST['cntctfrm_contact_name'].'</td>
283
+ </tr>
284
+ <tr>
285
+ <td>Email</td><td>'.$_REQUEST['cntctfrm_contact_emai'].'</td>
286
+ </tr>
287
+ <tr>
288
+ <td>Subject</td><td>'.$_REQUEST['cntctfrm_contact_subject'].'</td>
289
+ </tr>
290
+ <tr>
291
+ <td>Message</td><td>'.$_REQUEST['cntctfrm_contact_message'].'</td>
292
+ </tr>
293
+ </table>
294
+ </body>
295
+ </html>
296
+ ';
297
+
298
+ // To send HTML mail, the Content-type header must be set
299
+ $headers = 'MIME-Version: 1.0' . "\r\n";
300
+ $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
301
+
302
+ // Additional headers
303
+ $headers .= 'From: '.$_REQUEST['cntctfrm_contact_emai']. "\r\n";
304
+
305
+ // Mail it
306
+ return @mail($to, $subject, $message, $headers);
307
+ }
308
+ return false;
309
+ }
310
+ }
311
+
312
+ // Add the link on setting page in the plugin activation page
313
+ if( ! function_exists( contact_settings ) ) {
314
+ function contact_settings( $links, $file ) {
315
+ $base = plugin_basename( __FILE__ );
316
+ if ( $file == $base ) {
317
+ $links[] = '<a href="options-general.php?page=contact-form-plugin/contact_form.php">' . __( 'Settings', 'Settings' ) . '</a>';
318
+ }
319
+ return $links;
320
+ }
321
+ }
322
+
323
+ add_filter( 'plugin_row_meta', 'contact_settings', 10, 2 );
324
+ add_shortcode( 'contact_form', 'cntctfrm_display_form' );
325
+ add_action( 'admin_menu', 'cntctfrm_admin_menu' );
326
+
327
+ ?>
contact_form_style.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ #cntctfrm_contact_form input.text {width:320px;}
2
+ #cntctfrm_contact_form textarea {width:320px;}
readme.txt ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Contact Form ===
2
+ Contributors: bestwebsoft
3
+ Contributors: bestwebsoft
4
+ Donate link: http://bestwebsoft.com/
5
+ Tags: Contact Form, text, contact, form
6
+ Requires at least: 2.9
7
+ Tested up to: 3.1.3
8
+ Stable tag: 2011.05.27
9
+
10
+ Add Contact Form to your WordPress website.
11
+
12
+ == Description ==
13
+
14
+ Contact Form allows you to add a feedback form easilly and simply to a post or a page.
15
+
16
+ == Installation ==
17
+
18
+ 1. Upload `Contact Form` folder to the `/wp-content/plugins/` directory.
19
+ 2. Activate the plugin through the 'Plugins' menu in your WordPress admin panel.
20
+ 3. You can adjust necessary settings through your WordPress admin panel in "Settings" > "Contact Form".
21
+ 4. Create a page or a post and insert shortcode [contact_form] to the text.
22
+
23
+ == Frequently Asked Questions ==
24
+
25
+ = Where I can find settings to adjust work of the plugin after activation? =
26
+
27
+ 1. In the 'Plugin' menu you can find a link to the settings page.
28
+
29
+ = After plugin installation I haven't adjust the settings. What is default email address which will be used for a contact via the form? =
30
+
31
+ 1. Default address which was specified during WordPress installation will be used for the Contact Form plugin as default email address.
32
+
33
+ = How can I add Contact Form to my website? =
34
+
35
+ 1. You need to put a [contact_form] shortcode into your page or some post.
36
+
37
+ = After user choosen via plugin settings page I got this error: "Such user is not exist. Settings are not saved." =
38
+
39
+ 1. It means that such user is not exist or you have made a syntactical error.
40
+
41
+ == Screenshots ==
42
+
43
+ 1. Contact Form dislaying.
44
+
45
+ 2. Plugin settings in the WordPress admin panel.
46
+
47
+
48
+ == Changelog ==
49
+
50
+ = 1.01 =
51
+ *Contact form position bug is fixed.
52
+
53
+ = 1.00 =
54
+ *Ability to add Contact Form into a post. Ability to display form via shortcode.
55
+
56
+ == Upgrade Notice ==
57
+
58
+ = 1.01 =
59
+ Contact form position bug is fixed. Upgrade immediately.
60
+
61
+ = 1.00 =
62
+ Upgrade immediately.
screenshot-1.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file