1, 'element_half' => 0.5, 'element_fourth' => 0.25, 'element_third' => 0.3, 'element_two_third' => 0.6, 'element_three_fourth' => 0.75); /*overwrite the send function*/ var $execute = ""; /*error message that can be displayed in front of form*/ var $error_msg; /** * Constructor * * The constructor sets up the default params * @param array $params array with default form information such as submit button label, heading and success message */ function __construct($params) { add_filter('avf_safe_string_trans', array(&$this,'remove_invalid_chars'), 10, 3); $this->form_params = $params; $this->formID = avia_form::$form_id ++; $this->form_params['avia_formID'] = $this->formID; $this->id_sufix = isset($params['multiform']) ? "_".$this->formID : ""; $this->placeholder = !empty($params['placeholder']) ? true : false; $extraClass = isset($params['form_class']) ? $params['form_class'] : ""; $redirect = isset($params['redirect']) ? "data-avia-redirect='".$params['redirect']."'" : ""; $form_class = apply_filters('avf_ajax_form_class', 'ajax_form', $this->formID, $this->form_params); $form_class .= $this->placeholder ? " av-form-labels-hidden " : " av-form-labels-visible "; $form_data = ""; if(isset($this->form_params['form_data'])) { foreach($this->form_params['form_data'] as $datakey => $dataval) { $form_data .= " data-{$datakey}='{$dataval}'" ; } } $this->output = '
'.$success; if($return) { return $this->output; } else { echo $this->output; } } /** * html * * The html method creates custom html output for descriptions headings etc * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function html($id, $element) { if(!empty($element['content'])) { $this->elements_html .= "'; $this->button_html .= ''; $this->button_html .= 'submit_attr.' data-sending-label="'.__('Sending','avia_framework').'"/>'; $this->button_html .= '
'; if($id) { $this->elements_html .= $this->button_html; } else { return $this->button_html; } } function number($id, $element) { $this->text($id, $element, 'number'); } /** * text * * The text method creates input elements with type text, and prefills them with $_POST values if available. * The method also checks against various input validation cases * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function text($id, $element, $type = 'text') { $p_class = $required = $element_class = $value = $extra = ""; // if($element['check'] == "is_email") $type = 'email'; //cant use this because of ie8 + 9 if(!empty($element['check'])) { $extra = "*"; $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } if(isset($_POST[$id])) { $value = esc_html(urldecode($_POST[$id])); } else if( !empty( $element['value'] ) ) { $value = $element['value']; } $this->elements_html .= ""; $label = ''; $placeholder = ""; if($this->placeholder) { $label = ""; $placeholder = " placeholder='".$element['label'].$extra."'" ; } $form_el = ' '; if(isset($this->form_params['label_first'])) { $this->elements_html .= $label.$form_el; } else { $this->elements_html .= $form_el.$label; } $this->elements_html .= "
"; } /** * datepicker * * The text method creates input elements with type datepicker, and prefills them with $_POST values if available. * The method also checks against various input validation cases * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function datepicker($id, $element) { global $wp_locale; $p_class = $required = $element_class = $value = $extra = ""; $date_format = apply_filters('avf_datepicker_dateformat', 'dd / mm / yy'); $placeholder_text = 'DD / MM / YY'; if( ! empty($element['check'] ) ) { $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } if(isset($_POST[$id])) { $value = esc_html(urldecode($_POST[$id])); } else if( ! empty( $element['value'] ) ) { $value = $element['value']; } if( $this->placeholder ) { // empty label - keep default placeholder if( ! empty( $element['label'] ) ) { $placeholder_text = $element['label']; } if( ! empty( $element['check'] ) ) { $extra = "*"; } } $placeholder = apply_filters('avf_datepicker_date_placeholder', $placeholder_text.$extra); $this->elements_html .= ""; $form_el = ' '; $label = ''; if($this->placeholder) { $label = ""; } if(isset($this->form_params['label_first'])) { $this->elements_html .= $label.$form_el; } else { $this->elements_html .= $form_el.$label; } $this->elements_html .= "
"; // wp_enqueue_style('jquery-ui-datepicker'); <-- removed and added own styling to frontend css styles wp_enqueue_script('jquery-ui-datepicker'); $args = array( 'closeText' => __( 'Close', 'avia_framework' ), 'currentText' => __( 'Today', 'avia_framework' ), 'nextText' => __( 'Next', 'avia_framework' ), 'prevText' => __( 'Prev', 'avia_framework' ), 'monthNames' => $this->helper_strip_array_indices( $wp_locale->month ), 'monthNamesShort' => $this->helper_strip_array_indices( $wp_locale->month_abbrev ), 'dayNames' => $this->helper_strip_array_indices( $wp_locale->weekday ), 'dayNamesShort' => $this->helper_strip_array_indices( $wp_locale->weekday_abbrev ), 'dayNamesMin' => $this->helper_strip_array_indices( $wp_locale->weekday_initial ), 'dateFormat' => $date_format, 'firstDay' => get_option( 'start_of_week' ), 'isRTL' => $wp_locale->is_rtl() ); wp_localize_script( 'jquery-ui-datepicker', 'AviaDatepickerTranslation', $args ); add_action('wp_footer', array(&$this, 'helper_print_datepicker_script')); } function helper_print_datepicker_script() { echo "\n\n"; } function helper_strip_array_indices( $ArrayToStrip ) { foreach( $ArrayToStrip as $objArrayItem) { $NewArray[] = $objArrayItem; } return( $NewArray ); } /** * checkbox * * The text method creates input elements with type checkbox, and prefills them with $_POST values if available. * The method also checks against various input validation cases * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function checkbox($id, $element) { $p_class = $required = $element_class = $checked = ""; if( ! empty( $element['av_contact_preselect'] ) ) { $checked = 'checked="checked"'; } else if(!empty($element['check'])) { if(!empty($_POST[$id])) $checked = 'checked="checked"'; $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } if(empty($_POST[$id])) $_POST[$id] = "false"; $this->elements_html .= ""; $this->elements_html .= ' '; $this->elements_html .= "
"; } /** * Select * * The select method creates a dropdown element with type select, and prefills them with $_POST values if available. * The method also checks against various input validation cases * * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function select( $id, $element ) { if(empty($element['options'])) return; if(!is_array($element['options'])) { $element['options'] = str_replace( array( "\,", ',,' ), ",", $element['options'] ); $element['options'] = explode(',',$element['options'] ); } $p_class = $required = $element_class = $prefilled_value = $select = $extra = ""; if(!empty($element['check'])) { $extra = "*"; $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } if(isset($_POST[$id])) { $prefilled_value = esc_html(urldecode($_POST[$id])); } else if( !empty( $element['value'] ) ) { $prefilled_value = $element['value']; } if($this->placeholder) { $label = array( $element['label'].$extra."|" ); $element['options'] = array_merge($label,$element['options']); } foreach($element['options'] as $option) { $key = $value = trim($option); $suboptions = explode('|',$option); if(is_array($suboptions) && isset($suboptions[1])) { $key = trim($suboptions[1]); $value = trim($suboptions[0]); } $active = $value == $prefilled_value ? "selected='selected'" : ""; $select .= ""; } $multi = ""; if(!empty($element['multi_select'])) { $multi = "multiple"; $element_class .= " av-multi-select"; } $this->elements_html .= ""; $form_el = ' '; $label = ''; if($this->placeholder) $label = ""; if(isset($this->form_params['label_first'])) { $this->elements_html .= $label.$form_el; } else { $this->elements_html .= $form_el.$label; } $this->elements_html .= "
"; } /** * textarea * * The textarea method creates textarea elements, and prefills them with $_POST values if available. * The method also checks against various input validation cases * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function textarea($id, $element) { $p_class = $required = $element_class = $value = $extra = ""; if(!empty($element['check'])) { $extra = "*"; $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } if(isset($_POST[$id])) { $value = esc_html(urldecode($_POST[$id])); } else if( !empty( $element['value'] ) ) { $value = $element['value']; } $label = ' '; $placeholder = ""; if($this->placeholder) { $label = ""; $placeholder = " placeholder='".$element['label'].$extra."'" ; } $this->elements_html .= ""; $this->elements_html .= $label; $this->elements_html .= ' '; $this->elements_html .= "
"; } /** * decoy * * The decoy method creates input elements with type text but with an extra class that hides them * The method is used to fool bots into filling the form element. Upon submission we check if the element contains any value, if so we dont submit the form * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function decoy($id, $element) { $p_class = $required = $element_class = ""; if(!empty($element['check'])) { $this->check_element($id, $element); } $this->elements_html .= ''; } /** * Captcha * * The captcha method creates input element that needs to be filled correctly to send the form * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function captcha($id, $element) { $p_class = $required = $element_class = $value = $valueVer = ""; if(!empty($element['check'])) { $required = ' *'; $element_class = $element['check']; $p_class = $this->check_element($id, $element); } $p_class = $this-> auto_width(); if(!empty($_POST[$id])) $value = esc_html(urldecode($_POST[$id])); if(!empty($_POST[$id.'_verifier'])) $valueVer = esc_html(urldecode($_POST[$id.'_verifier'])); if(!$valueVer) $valueVer = str_replace('0','4', str_replace('9','7', rand(123456789, 999999999))); $reverse = strrev( $valueVer ); $enter = $valueVer[$reverse[0]]; $number_1 = rand(0, $enter); $number_2 = $enter - $number_1; $this->elements_html .= ""; $this->elements_html .= " $number_1 + $number_2 = ?"; $this->elements_html .= ' '; $form_el = ' '; $label =''; if(isset($this->form_params['label_first'])) { $this->elements_html .= $label.$form_el; } else { $this->elements_html .= $form_el.$label; } $this->elements_html .= "
"; } /** * hidden * * The hidden method creates input elements with type hidden, and prefills them with values if available. * @param string $id holds the key of the element * @param array $element data array of the element that should be created */ function hidden($id, $element) { $this->elements_html .= ''; } /** * Send the form * * The send method tries to send the form. It builds the necessary email and submits it via wp_mail */ function send( $self_instance ) { $new_post = array(); foreach ($_POST as $key => $post) { $new_post[str_replace('avia_','',$key)] = $post; } $mymail = empty($this->form_params['myemail']) ? $new_post['myemail'] : $this->form_params['myemail']; $myblogname = empty($this->form_params['myblogname']) ? $new_post['myblogname'] : $this->form_params['myblogname']; if(empty($new_post['subject_'.$this->formID]) && !empty($this->form_params['subject'])) $new_post['subject_'.$this->formID] = $this->form_params['subject']; $subject = empty($new_post['subject_'.$this->formID]) ? __("New Message", 'avia_framework') . " (".__('sent by contact form at','avia_framework')." ".$myblogname.")" : $new_post['subject_'.$this->formID]; $default_from = parse_url(home_url()); //hook to stop execution here and do something different with the data $proceed = apply_filters( 'avf_form_send', true, $new_post, $this->form_params, $this ); if( ! $proceed ) { if( is_null( $proceed ) ) { return false; } else { return true; } } //set the email adress $from = "no-reply@wp-message.com"; $usermail = false; if(!empty($default_from['host'])) $from = "no-reply@".$default_from['host']; if(!empty($this->autoresponder[0])) { $from = $_POST[$this->autoresponder[0]]; $usermail = true; } else { $email_variations = array( 'e-mail', 'email', 'mail' ); foreach($email_variations as $key) { foreach ($new_post as $current_key => $current_post) { if( strpos($current_key, $key) !== false) { $from = $new_post[$current_key]; $usermail = true; break; } } if($usermail == true) break; } } $to = urldecode( $mymail ); $delimiter = ","; if(strpos($to, ',') === false && strpos($to, ' ') !== false) $delimiter = " "; $to = array_filter(array_map('trim', explode($delimiter, $to))); $to = apply_filters("avf_form_sendto", $to, $new_post, $this->form_params); $from = urldecode( $from ); $from = apply_filters("avf_form_from", $from, $new_post, $this->form_params); $subject = urldecode( $subject ); $subject = apply_filters("avf_form_subject", $subject, $new_post, $this->form_params); $message = ""; $iterations = 0; foreach($this->form_elements as $key => $element) { if(isset($element['id'])) $key = $element['id']; $key = avia_backend_safe_string($key, '_', true); if(empty($key) || !empty($this->form_params['numeric_names']) ) { $iterations++; $key = $iterations; } // substract 5 characters from the string length because we removed the avia_ prefix with 5 characters at the beginning of the send() function $key = avia_backend_truncate($key, $this->length - 5, "_", "", false, '', false); $key .= $this->id_sufix; if(!empty($new_post[$key])) { if($element['type'] != 'hidden' && $element['type'] != 'decoy') { if($element['type'] == 'textarea') $message .= "