PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/media/zoo/elements/supercontact/contact_form.php

https://gitlab.com/vnsoftdev/amms
PHP | 239 lines | 174 code | 20 blank | 45 comment | 31 complexity | a38992fbea936e29dea6a4c25516690f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0, GPL-2.0
  1. <?php
  2. /**
  3. * @package com_zoo
  4. * @author Mustaq Sheikh http://herdboy.com * Form Developed by Jason Lau http://jasonlau.biz/
  5. * @copyright Copyright (C) 2011 HerdBoy Web Design cc
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. /**
  9. * @version 1.0.0
  10. */
  11. // joomla constant to disable direct access to this file
  12. defined('_JEXEC') or die('Restricted access');
  13. // Authorization cookie contents. Don't change this unless you know what you're doing.
  14. define("AUTHORIZATION_CODE", md5($_SERVER["HTTP_HOST"] . $_SERVER["REMOTE_ADDR"] . $_SERVER["HTTP_USER_AGENT"] . date("M d, Y") . base64_encode(EMAIL_TO)));
  15. // Add a random aspect to the auth code
  16. $rand = rand(100,1000);
  17. $auth_code = AUTHORIZATION_CODE.$rand;
  18. // Assemble cookie content, encode variables.
  19. $cookie_content = $auth_code. "," . base64_encode(EMAIL_TO) . "," . base64_encode(EMAIL_SUBJECT) . "," . base64_encode(SUCCESS_MESSAGE) . "," . base64_encode(PAGE_PATH) . "," . base64_encode(INCLUDE_FOOTER);
  20. // Set the form submission authorization cookie. This ensures the user of the form and the user of send.php are the same.
  21. setcookie("scauth", $cookie_content, time()+60*60, '/', $_SERVER["HTTP_HOST"]);
  22. ?>
  23. <script type="text/javascript">
  24. <!--
  25. (function($){
  26. // increase the default animation speed to exaggerate the effect
  27. $.fx.speeds._default = 1000;
  28. $(function() {
  29. // initiate the overlay
  30. $("#dialog<?php echo $rand; ?>").dialog({
  31. autoOpen: false,
  32. show: "<?php echo DIALOG_ANIMATION_IN; ?>",
  33. hide: "<?php echo DIALOG_ANIMATION_OUT; ?>",
  34. modal: true,
  35. width: "<?php echo DIALOG_WIDTH; ?>"
  36. });
  37. // set the action for the overlay opener
  38. $(".super_contact<?php echo $rand; ?>").each(function(){
  39. $(this).bind('click',function(){
  40. $("#dialog<?php echo $rand; ?>").dialog("open");
  41. });
  42. });
  43. // set the action for the reset button
  44. $("#reset<?php echo $rand; ?>").click(function(){
  45. // clear all values and error classes
  46. $("#name_first<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  47. $("#name_last<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  48. $("#email<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  49. $("#email2<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  50. $("#tele<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  51. $("#message<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  52. $("#cc<?php echo $rand; ?>").val('').removeClass('ui-state-error');
  53. // clear html and class for paragraphs whose id attribute contains the text "helper"
  54. $('p[id*="helper<?php echo $rand; ?>"]').each(function(){
  55. $(this).html('').removeClass('ui-state-highlight');
  56. });
  57. });
  58. // set the action for the submit button. require mouse-up action.
  59. $("#sub-button<?php echo $rand; ?>").mouseup(function(){
  60. // set the variables, trim the whitespace from the values, and validate the form fields
  61. var pass = true,
  62. first_name = (!$("#name_first<?php echo $rand; ?>").val()) ? '' : trim($("#name_first<?php echo $rand; ?>").val()),
  63. last_name = (!$("#name_last<?php echo $rand; ?>").val()) ? '' : trim($("#name_last<?php echo $rand; ?>").val()),
  64. email = (!$("#email<?php echo $rand; ?>").val()) ? '' : trim($("#email<?php echo $rand; ?>").val()),
  65. email2 = (!$("#email2<?php echo $rand; ?>").val()) ? '' : trim($("#email2<?php echo $rand; ?>").val()),
  66. tele = (!$("#tele<?php echo $rand; ?>").val()) ? '' : trim($("#tele<?php echo $rand; ?>").val()),
  67. message = (!$("#message<?php echo $rand; ?>").val()) ? '' : trim($("#message<?php echo $rand; ?>").val());
  68. // valid characters for first and last name
  69. var validNameChars = /^( |[^\s])+$/; /* Regular expression changed by Constantin Rack 2011-10-09, was /^[a-zA-Z\'\- ]+$/ */
  70. if(first_name == '' || !first_name.match(validNameChars)){
  71. // first name is empty or contains illegal characters
  72. pass = false;
  73. $("#name_first-helper<?php echo $rand; ?>").html('<?php echo ERROR_INVALID_NAME; ?>').addClass('ui-state-highlight');
  74. $("#name_first<?php echo $rand; ?>").addClass('ui-state-error');
  75. } else {
  76. // first name passed
  77. $("#name_first-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  78. $("#name_first<?php echo $rand; ?>").removeClass('ui-state-error');
  79. }
  80. if(last_name == '' || !last_name.match(validNameChars)){
  81. // last name is empty or contains illegal characters
  82. pass = false;
  83. $("#name_last-helper<?php echo $rand; ?>").html('<?php echo ERROR_INVALID_NAME; ?>').addClass('ui-state-highlight');
  84. $("#name_last<?php echo $rand; ?>").addClass('ui-state-error');
  85. } else {
  86. // last name passed
  87. $("#name_last-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  88. $("#name_last<?php echo $rand; ?>").removeClass('ui-state-error');
  89. }
  90. // validate email address
  91. if(email == '' || !checkEmail($("#email<?php echo $rand; ?>"),/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i)){
  92. // email is empty or invalid
  93. pass = false;
  94. $("#email-helper<?php echo $rand; ?>").html('<?php echo ERROR_INVALID_EMAIL; ?>').addClass('ui-state-highlight');
  95. $("#email<?php echo $rand; ?>").addClass('ui-state-error');
  96. } else {
  97. // email passed
  98. $("#email-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  99. $("#email<?php echo $rand; ?>").removeClass('ui-state-error');
  100. }
  101. if(email2 == ''){
  102. // confirm email is empty or invalid
  103. pass = false;
  104. $("#email2-helper<?php echo $rand; ?>").html('<?php echo ERROR_INVALID_CONFIRM_EMAIL; ?>').addClass('ui-state-highlight');
  105. $("#email2<?php echo $rand; ?>").addClass('ui-state-error');
  106. } else {
  107. // confirm email passed check if email and confirm email match
  108. if(email != email2){
  109. // confirm email and email did not match
  110. pass = false;
  111. $("#email2-helper<?php echo $rand; ?>").html('<?php echo ERROR_EMAIL_FIELDS_DONT_MATCH; ?>').addClass('ui-state-highlight');
  112. $("#email2<?php echo $rand; ?>").addClass('ui-state-error');
  113. } else {
  114. // confirm email and email match - continue submission
  115. $("#email2-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  116. $("#email2<?php echo $rand; ?>").removeClass('ui-state-error');
  117. }
  118. }
  119. if(tele == ''){
  120. // message is empty - fail
  121. pass = true;
  122. $("#message-helper<?php echo $rand; ?>").html('<?php echo $error_message_required; ?>').addClass('ui-state-highlight');
  123. $("#message<?php echo $rand; ?>").addClass('ui-state-error');
  124. } else {
  125. // message passed
  126. $("#message-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  127. $("#message<?php echo $rand; ?>").removeClass('ui-state-error');
  128. }
  129. if(message == ''){
  130. // message is empty - fail
  131. pass = false;
  132. $("#message-helper<?php echo $rand; ?>").html('<?php echo $error_message_required; ?>').addClass('ui-state-highlight');
  133. $("#message<?php echo $rand; ?>").addClass('ui-state-error');
  134. } else {
  135. // message passed
  136. $("#message-helper<?php echo $rand; ?>").html('').removeClass('ui-state-highlight');
  137. $("#message<?php echo $rand; ?>").removeClass('ui-state-error');
  138. }
  139. // All fields passed - ajax the data to send.php
  140. if(pass){
  141. $.post('<?php echo PATH_TO_PROCESSING_SCRIPT; ?>?r=<?php echo $rand; ?>&nocache=' + Math.floor(Math.random()*1000), {name:first_name+' '+last_name,email:email,email2:email2,tele:tele,message:message,cc:$("#cc<?php echo $rand; ?>").val(),scauth:'<?php echo $auth_code; ?>'},
  142. function(data){
  143. // place the returned data in the results div
  144. $("#results<?php echo $rand; ?>").html(data);
  145. // div#response is returned by send.php. if the submission was successful, div#response will have the class ui-state-highlight. otherwise, the submission failed. Hide the form on success.
  146. if($("#response").hasClass('ui-state-highlight')){
  147. $('#c-form<?php echo $rand; ?>').hide('slow');
  148. }
  149. });
  150. }
  151. });
  152. });
  153. // function to validate the email
  154. function checkEmail(o,regexp) {
  155. if ( !( regexp.test( o.val() ) ) ) {
  156. o.addClass('ui-state-error');
  157. return false;
  158. } else {
  159. o.removeClass('ui-state-error');
  160. return true;
  161. }
  162. }
  163. // function to remove whitespace from both ends of a string
  164. function trim(str, chars) {
  165. var result = false;
  166. try{
  167. result = ltrim(rtrim(str, chars), chars);
  168. } catch(e){}
  169. if(result){
  170. return result;
  171. }
  172. }
  173. // function to remove whitespace from the beginning of a string
  174. function ltrim(str, chars) {
  175. chars = chars || "\\s";
  176. return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  177. }
  178. // function to remove whitespace from the end of a string
  179. function rtrim(str, chars) {
  180. chars = chars || "\\s";
  181. return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
  182. }
  183. })(jQuery);
  184. -->
  185. </script>
  186. <div id="contact-form<?php echo $rand; ?>">
  187. <div id="dialog<?php echo $rand; ?>" title="<?php echo $dialog_title; ?>" style="display: none;" class="popup-contact">
  188. <div id="results<?php echo $rand; ?>"></div>
  189. <fieldset id="c-form<?php echo $rand; ?>">
  190. <label for="name_first"><?php echo $first_name_label; ?></label>
  191. <input type="name" id="name_first<?php echo $rand; ?>" placeholder="<?php echo $first_name_placeholder; ?>" title="<?php echo $first_name_title; ?>" class="required" />
  192. <p class="helper" id="name_first-helper<?php echo $rand; ?>"></p>
  193. <label for="name_last"><?php echo $last_name_label; ?></label>
  194. <input type="name" id="name_last<?php echo $rand; ?>" placeholder="<?php echo $last_name_placeholder; ?>" title="<?php echo $last_name_title; ?>" class="required" />
  195. <p class="helper" id="name_last-helper<?php echo $rand; ?>"></p>
  196. <label for="email"><?php echo $email_label; ?></label>
  197. <input type="email" id="email<?php echo $rand; ?>" placeholder="<?php echo $email_placeholder; ?>" title="<?php echo $email_title; ?>" class="required email" />
  198. <p class="helper" id="email-helper<?php echo $rand; ?>"></p>
  199. <label for="email2"><?php echo $confirm_email_label; ?></label>
  200. <input type="email" id="email2<?php echo $rand; ?>" placeholder="<?php echo $confirm_email_placeholder; ?>" title="<?php echo $confirm_email_title; ?>" class="required email" />
  201. <p class="helper" id="email2-helper<?php echo $rand; ?>"></p>
  202. <label for="tele"><?php echo $tele_label; ?></label>
  203. <input type="tel" id="tele<?php echo $rand; ?>" placeholder="<?php echo $tele_placeholder; ?>" title="<?php echo $tele_title; ?>" />
  204. <p class="helper" id="email2-helper<?php echo $rand; ?>"></p>
  205. <label for="message"><?php echo $message_label; ?></label>
  206. <textarea id="message<?php echo $rand; ?>"></textarea>
  207. <p class="helper" id="message-helper<?php echo $rand; ?>"></p>
  208. <label for="cc"><?php echo $carbon_copy_label; ?></label>
  209. <select size="1" id="cc<?php echo $rand; ?>" title="<?php echo $carbon_copy_title; ?>">
  210. <option value="yes" selected="selected"><?php echo $carbon_copy_yes; ?></option>
  211. <option value="no"><?php echo $carbon_copy_no; ?></option>
  212. </select>
  213. <p class="helper"></p>
  214. <button class="quote-send-btn btn input" id="sub-button<?php echo $rand; ?>"><?php echo $submit_button_label; ?></button>
  215. <input id="reset<?php echo $rand; ?>" class="quote-reset-btn btn input" type="reset" value="<?php echo $reset_button_label; ?>" />
  216. </fieldset>
  217. </div>
  218. </div>
  219. <button class="tall <?php echo $button_color; ?> btn super_contact<?php echo $rand; ?>" id="opener<?php echo $rand; ?>"><?php echo $opener_label; ?></button>