Advertisement
Guest User

Simple Booking Form - Email 3 times issue!

a guest
Oct 31st, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Simple Booking Form
  4. Plugin URI: http://www.romeluv.com/simple-booking-form/
  5. Description: Just insert the [BOOKINGFORM] shorttag in posts or pages of your WordPress site to display a beautiful booking form. The submitted form data will be immediately sent via email both to the site administrator and to the user that submitted the form.
  6. Version: 1.0.1
  7. Author: RomeLuv
  8. Author URI: http://www.romeluv.com
  9. License: GPL v2
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; version 2 of the License.
  14.  
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19.  
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. add_action('wp_head', 'add_js_calendar_for_booking_form');
  33.  
  34.  
  35.  
  36. function add_js_calendar_for_booking_form()
  37. {
  38.  
  39. echo'<script language="JavaScript" src="'.WP_PLUGIN_URL.'/simple-booking-form-wordpress-plugin/date-picker/js/datepicker.js"></script>
  40. <link rel="stylesheet" href="'.WP_PLUGIN_URL.'/simple-booking-form-wordpress-plugin/date-picker/css/datepicker.css">';
  41. //Thanks to Frequency Decoder for the Date Picker Script. http://www.frequency-decoder.com
  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. function CleanStringRomeLuvBookingForm($content)
  70. {return wp_kses($content,'');}
  71.  
  72.  
  73. function sbf_rl_widget() {
  74. echo romeluv_booking_form('');
  75. }
  76.  
  77. register_sidebar_widget("Simple Booking Form", "sbf_rl_widget");
  78.  
  79. add_shortcode('BOOKINGFORM', 'romeluv_booking_form');
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. function romeluv_booking_form($atts)
  87. {
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. $out.='<a name="simple-wp-booking-enquiry-form"></a>';
  100.  
  101.  
  102.  
  103.  
  104. global $_POST;
  105. global $post;
  106. $FormErrors=FALSE;
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. ///VALIDAZIONE FORM, se c'รจ
  119. if ($_POST['submit-enquiry'])
  120.  
  121. { //validazione caso submit step 2
  122. $number_of_guests=CleanStringRomeLuvBookingForm($_POST['number_of_guests']);
  123.  
  124. $contactemail=CleanStringRomeLuvBookingForm($_POST['contactemail']);
  125. $contactname=CleanStringRomeLuvBookingForm($_POST['contactname']);
  126. $telephone=CleanStringRomeLuvBookingForm($_POST['telephone']);
  127. $notes=CleanStringRomeLuvBookingForm($_POST['notes']);
  128. $random_value= CleanStringRomeLuvBookingForm($_POST['random_value']);
  129. $controlusercheck= $_POST[controlusercheck];
  130. $arrivaldate=CleanStringRomeLuvBookingForm($_POST[arrivaldate]);
  131. $departuredate =CleanStringRomeLuvBookingForm($_POST[departuredate]);
  132. $number_of_guests=CleanStringRomeLuvBookingForm($_POST['number_of_guests']);
  133.  
  134.  
  135. //add sicurezza
  136.  
  137.  
  138.  
  139. //valido errori
  140. if ($contactname=="") $FormErrors.="<h2 class='enquiry-form-error-message'>Please fill in the <b>Name</b> field.</h2> ";
  141.  
  142. if ( !is_email($contactemail)) $FormErrors.="<h2 class='enquiry-form-error-message'>Please fill in the <b>Email</b> field with a proper email. </h2>";
  143.  
  144.  
  145.  
  146. if (($number_of_guests=='') ) $FormErrors.="<h2 class='enquiry-form-error-message'>Please enter the number of guests.</h2> ";
  147.  
  148.  
  149. if (($telephone=='') ) $FormErrors.="<h2 class='enquiry-form-error-message'>Please enter your phone number.</h2> ";
  150.  
  151. if (($arrivaldate=='') ) $FormErrors.="<h2 class='enquiry-form-error-message'>Please enter your arrival date.</h2> ";
  152.  
  153. if (($departuredate=='') ) $FormErrors.="<h2 class='enquiry-form-error-message'>Please enter your departure date.</h2> ";
  154.  
  155. if (($controlusercheck!=$random_value+2) ) $FormErrors.="<h2 class='enquiry-form-error-message'>Please answer correctly to the Anti-Spam question.</h2> ";
  156.  
  157.  
  158.  
  159. }
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167. /////MODULO: STEP 1
  168. if (!$_POST OR ($FormErrors&& $_POST['submit-enquiry'] ) )
  169.  
  170.  
  171. {
  172.  
  173. $random_value=rand(0,10);
  174. $out.='
  175.  
  176.  
  177. <!--start of enquiry form--><div class="simple-wp-booking-enquiry-form">
  178. <p>Please note that this is not an actual reservation, but only a request for one. We will contact you for a confirmation shortly after. Thank you!</p>
  179. <small style="color: red;">(ALL fields required)</small>
  180. <form action="'. get_permalink().'?bform=1#simple-wp-booking-enquiry-form" method="post" id="enqform" name="enqform"><input name="pid" id="pid" value="'. $post->id.'" type="hidden" />
  181. <table width="100%" border="0" >
  182. <tbody> <tr>
  183. <td width="25%" >Your dates </td>
  184. <td width="75%" >
  185.  
  186.  
  187. <label for="sd">Check-In Date: <small>(DAY/MONTH/YEAR)</small></label>
  188. <p><input type="text" size="10" class="w8em format-d-m-y highlight-days-67 range-low-today" name="arrivaldate" id="arrivaldate" value="'.$arrivaldate.'" maxlength="10" /></p>
  189.  
  190. <label for="ed">Check-out Date: <small>(DAY/MONTH/YEAR)</small></label>
  191.  
  192. <p class="lastup"><input size="10" type="text" class="w8em format-d-m-y highlight-days-67 range-low-today" name="departuredate" id="departuredate" value="'.$departuredate.'" maxlength="10" /></p>
  193.  
  194.  
  195. </td>
  196.  
  197. </tr>
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. <tr>
  205. <td width="25%" >No of Guests </td>
  206. <td width="75%" >
  207. <select name="number_of_guests" class="csnum">
  208.  
  209. <option value="'.$number_of_guests.'" selected="selected">';
  210.  
  211. if (isset($number_of_guests)) $out.=$number_of_guests; else $out.='Choose...';
  212.  
  213. $out.='</option>
  214.  
  215. ';
  216.  
  217.  
  218. for ($cit=1;$cit<12;$cit++) {
  219. $out.='<option value="'.$cit.'" >'.$cit.'</option>';
  220. }
  221.  
  222. $out.='
  223. </select></td>
  224.  
  225. </tr>
  226.  
  227.  
  228.  
  229.  
  230.  
  231. <tr>
  232. <td width="40%" nowrap>Full name</td>
  233. <td width="60%">
  234. <input name="contactname" class="secondary-bfe-inputs" value="'.$contactname.'" class="cstext" type="text"></td>
  235. </tr>
  236. <tr>
  237. <td><span class="csrequired">Email</span> </td>
  238.  
  239. <td >
  240. <input name="contactemail" class="secondary-bfe-inputs" value="'.$contactemail.'" class="cstext" type="text"></td>
  241. </tr>
  242.  
  243. <tr>
  244. <td>Mobile # </td>
  245. <td>
  246.  
  247.  
  248. <input name="telephone" class="secondary-bfe-inputs" value="'.$telephone.'" class="cstext" type="text"></td>
  249. </tr>
  250.  
  251.  
  252. <tr>
  253. <td> 2+'.$random_value.' = </td>
  254. <td>
  255.  
  256.  
  257. <input name="controlusercheck" class="secondary-bfe-inputs" value="" size="2" class="cstext" type="text"> <small>(Anti-spam question)</small></td>
  258. </tr>
  259.  
  260.  
  261. <tr>
  262. <td style="vertical-align:top">Room Type / Other Notes (Optional)
  263.  
  264. </td>
  265. <td>
  266. <textarea name="notes" class="secondary-bfe-inputs" rows="1" cols="20">'.$notes.'</textarea></td>
  267. </tr>
  268. <tr>
  269.  
  270. <td colspan="2" >';
  271.  
  272. $out.= '<div class="simple-booking-form-errors">'.$FormErrors."</div>";
  273.  
  274. $out.='<input type="hidden" name="random_value" value='.$random_value.'>
  275. <input name="submit-enquiry" value="Submit Reservation" type="submit" />
  276. </td>
  277. </tr>
  278. </tbody></table>
  279.  
  280. </form>
  281. </div>
  282.  
  283.  
  284. <div style="clear: both;"></div>
  285. <!--end of enquiry form-->
  286. ';
  287.  
  288. }
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. global $_POST;
  299. ////STEP 2: CONFERMA e manda mail
  300. if ($_POST['submit-enquiry']&& !$FormErrors)
  301. { $out.='<div class="simple-wp-booking-enquiry-form">
  302.  
  303.  
  304.  
  305.  
  306. <h2 class="success-enquiry">Dear '. $contactname.',
  307. Thank you for your reservation.
  308.  
  309.  
  310.  
  311. <br /><br /> We will get back to you as soon as possible.<br /><br />
  312.  
  313.  
  314.  
  315.  
  316. </h2>
  317. Your reservation details:
  318.  
  319. <table width="100%" border="0" cellpaddding="1">
  320. <tbody>
  321.  
  322.  
  323.  
  324. <tr>
  325. </tr>
  326.  
  327.  
  328. <tr>
  329. <td width="25%" >Arrival date: </td>
  330. <td width="75%" >
  331. '.$arrivaldate.'
  332.  
  333.  
  334. &nbsp;&nbsp;&nbsp;
  335. <small>(DAY/MONTH/YEAR)</small></td>
  336. </tr>
  337.  
  338.  
  339.  
  340. <tr>
  341. <td width="25%" nowrap >Departure date: </td>
  342. <td width="75%" >
  343. '.$departuredate.' &nbsp;&nbsp;&nbsp; <small>(DAY/MONTH/YEAR)</small></td>
  344. </tr>
  345.  
  346.  
  347.  
  348.  
  349.  
  350. <tr>
  351. <td width="25%" >No of Guests:</td>
  352. <td width="75%" >
  353. '.$number_of_guests .' </td>
  354. </tr>
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363. <tr>
  364. <td width="25%" >Name:</td>
  365. <td width="75%" >
  366. '.$_POST['contactname'].'</td>
  367. </tr>
  368. <tr>
  369. <td width="25%" ><span class="csrequired">Email:</span></td>
  370.  
  371. <td width="75%" >
  372. '.$_POST['contactemail'].'</td>
  373. </tr>
  374.  
  375. <tr>
  376. <td width="25%" >Mobile Number: </td>
  377. <td width="75%" >
  378. ' .$_POST['telephone'].'</td>
  379. </tr>
  380. <tr>
  381. <td width="25%" >Room Type / Notes:</td>
  382. <td width="75%" >
  383. '.$_POST['notes'].'</td>
  384. </tr>
  385.  
  386. </tbody></table>
  387. ';
  388.  
  389.  
  390.  
  391. $email_html = $out;
  392.  
  393.  
  394.  
  395. $post_name=get_the_title($post->ID);
  396.  
  397. $permalink = get_permalink($post->ID);
  398. $permalink=substr($permalink,7); //levo Http://
  399.  
  400. $now=date("Y-m-d H:i:s",time()); //data e ora attuale
  401.  
  402. global $_SERVER;
  403. $ipaddress=$_SERVER['REMOTE_ADDR'];
  404.  
  405.  
  406.  
  407.  
  408.  
  409. //send email
  410.  
  411.  
  412. $oggetto .= "Booking request from ". $contactname." | ".get_the_title();
  413.  
  414. $headers = 'MIME-Version: 1.0' . "\r\n";
  415. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  416.  
  417. // Additional headers
  418.  
  419. $headers .= 'From: '.get_option('blogname').' <'.get_option('admin_email').'> ';
  420.  
  421.  
  422.  
  423.  
  424. // Mail it
  425.  
  426. mail($contactemail, $oggetto, $email_html, $headers);
  427.  
  428. mail(get_option('admin_email'), $oggetto, $email_html, $headers);
  429.  
  430.  
  431.  
  432.  
  433. $out.='
  434. </div>';
  435.  
  436.  
  437. }
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459. return $out;
  460.  
  461.  
  462.  
  463. } //end romeluv booking form function
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement