array('type' => 'text', 'label' => esc_html__('Name', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => true), //'surname' => array('type' => 'text', 'label' => esc_html__('Surname', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => true), // email field is required 'email' => array('type' => 'text', 'label' => esc_html__('Email address', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => true), 'message' => array('type' => 'textarea', 'label' => esc_html__('Message', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => true), // example fields //'radio' => array('type' => 'radio', 'label' => esc_html__('Radio', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => false, 'options' => array('radio 1', 'radio 2', 'radio 3')), //'select' => array('type' => 'select', 'label' => esc_html__('Select', 'amadeo-free'), 'required' => true, 'regex' => false, 'hint' => false, 'hide-label' => false, 'options' => array('select 1', 'select 2', 'select 3')), ); } public function amadeoContactFormScripts(){ wp_enqueue_style('amadeo-cf-css', $this->amadeoPluginDirUrl() . '/css/contact-form.css'); wp_enqueue_script('amadeo-cf-js', $this->amadeoPluginDirUrl() . '/js/contact-form.js', array('amadeo-jquery-js')); wp_localize_script('amadeo-cf-js', 'amadeo_cf_l10n', array( 'ajax_url' => admin_url('admin-ajax.php') )); } protected function amadeoPluginDirUrl(){ return strstr(content_url(), 'wp-content', TRUE) . strstr( __DIR__ , 'wp-content'. DIRECTORY_SEPARATOR); } // display contact form method public static function amadeoRenderContactForm(){ require_once('views/form.php'); } // send contact form method public function amadeoContactFormSend(){ if(defined('DOING_AJAX') && DOING_AJAX){ /* * prepare array $arrayFormInputs * * 'field_name' => 'value' * eg. * 'name' => 'Jan' * 'surname' => 'Kowalski' * 'email' => 'j.kowalski@example.com' * 'message' => 'your message' * etc. * */ foreach($_REQUEST['amadeoContactFormInputs'] as $field){ $arrayFormInputs[$field['name']] = $field['value']; } if(!$this->amadeoInvalidFields($arrayFormInputs)): if(filter_var($arrayFormInputs['email'], FILTER_VALIDATE_EMAIL)): $email = get_bloginfo('admin_email'); $siteName = get_bloginfo('name'); $bodyMessage = ''; foreach(self::$inputFields as $name => $field){ $bodyMessage .= $field['label'] .': '. esc_html($arrayFormInputs[$name]) ." \n"; } $headerEncoding = "MIME-Version: 1.0\r\n"; $headerEncoding .= "Content-type: text/plain; charset=utf-8;"; $headerEncoding .= "Content-Transfer-Encoding: 8bit;"; $header = "From: ". sanitize_email($arrayFormInputs['email']) ."\r\n"; $header .= $headerEncoding; if(@mail(sanitize_email($email), esc_html__('Message from ', 'amadeo-free') . esc_html($siteName), $bodyMessage, $header)): ?>