Example #1
0
/**
 * Insert the shortcode after the form title.
 *
 * @since	1.0
 * @param	obj		$post		The WP_Post object.
 * @return	str
 */
function kbs_form_edit_form_after_title()
{
    global $post;
    if ('kbs_form' == get_post_type()) {
        ?>
    	<?php 
        $kbs_form = new KBS_Form($post->ID);
        ?>
		<input type="text" readonly="readonly" size="25" onclick="this.focus(); this.select()" id="kbs-form-shortcode" name="kbs_form_shortcode" value='<?php 
        echo $kbs_form->get_shortcode();
        ?>
' title="<?php 
        _e('To copy the shortcode, click here then press Ctrl + C (PC) or Cmd + C (Mac).', 'kb-support');
        ?>
" />
	<?php 
    }
}
Example #2
0
/**
 * Returns all available mappings.
 *
 * @since	1.0
 * @param	int	form_id		Form post ID.
 * @return	arr
 */
function kbs_get_available_mappings($form_id)
{
    $kbs_form = new KBS_Form($form_id);
    $mappings = kbs_get_mappings();
    foreach ($mappings as $key => $value) {
        if ($kbs_form->has_mapping($key)) {
            unset($mappings[$key]);
        }
    }
    return $mappings;
}
 public function show_form_data()
 {
     if (empty($this->form_data)) {
         return;
     }
     $form = new KBS_Form($this->form_data['id']);
     $ignore = kbs_form_ignore_fields();
     $output = '<h2>' . sprintf(__('Form: %s', 'kb-support'), get_the_title($this->form_data['id'])) . '</h2>';
     foreach ($this->form_data['data'] as $field => $value) {
         $form_field = kbs_get_field_by('name', $field);
         if (empty($form_field)) {
             continue;
         }
         $settings = $form->get_field_settings($form_field->ID);
         $value = apply_filters('kbs_show_form_data', $value, $form_field->ID, $settings);
         $output .= '<p><strong>' . get_the_title($form_field->ID) . '</strong>: ' . $value;
     }
     return apply_filters('kbs_show_form_data', $output);
 }
/**
 * Adds a new ticket from a form submission.
 *
 * @since	1.0
 * @param	int		$form_id	Form ID
 * @param	arr		$form_data	Array of ticket data.
 * @return	mixed	Ticket ID on success, false on failure.
 */
function kbs_add_ticket_from_form($form_id, $form_data)
{
    $kbs_form = new KBS_Form($form_id);
    $fields = $kbs_form->fields;
    $data = array();
    $ticket_data = array('user_info' => array(), 'attachments' => array(), 'form_data' => array('id' => $form_id, 'data' => $form_data));
    foreach ($fields as $field) {
        $settings = $kbs_form->get_field_settings($field->ID);
        if ('file_upload' == $settings['type'] && !empty($_FILES[$field->post_name])) {
            $ticket_data['attachments'] = $_FILES[$field->post_name];
            continue;
        }
        if (empty($form_data[$field->post_name])) {
            continue;
        }
        if (!empty($settings['mapping'])) {
            if ('customer_first' == $settings['mapping']) {
                $ticket_data['user_info']['first_name'] = ucfirst(sanitize_text_field($form_data[$field->post_name]));
            } elseif ('customer_last' == $settings['mapping']) {
                $ticket_data['user_info']['last_name'] = ucfirst(sanitize_text_field($form_data[$field->post_name]));
            } elseif ('customer_email' == $settings['mapping']) {
                $ticket_data['user_info']['email'] = strtolower($form_data[$field->post_name]);
                $ticket_data['user_email'] = $ticket_data['user_info']['email'];
            } else {
                $ticket_data[$settings['mapping']] = $form_data[$field->post_name];
            }
        } else {
            $ticket_data[$field->post_name] = array($field->post_title, strip_tags(addslashes($form_data[$field->post_name])));
            $data[] = '<strong>' . $field->post_title . '</strong><br />' . $form_data[$field->post_name];
        }
    }
    $ticket_data = apply_filters('kbs_add_ticket_from_form_data', $ticket_data, $form_id, $form_data);
    $ticket_id = kbs_add_ticket($ticket_data);
    if ($ticket_id) {
        $kbs_form->increment_submissions();
        return $ticket_id;
    }
    return false;
}
Example #5
0
/**
 * Validate a ticket submission form.
 *
 * @since	1.0
 * @return	void
 */
function kbs_ajax_validate_form_submission()
{
    $form = new KBS_Form($_POST['kbs_form_id']);
    $error = false;
    $agree_to_terms = kbs_get_option('show_agree_to_terms', false);
    foreach ($form->get_fields() as $field) {
        $settings = $form->get_field_settings($field->ID);
        if (!empty($settings['required']) && empty($_POST[$field->post_name])) {
            $error = kbs_form_submission_errors($field->ID, 'required');
            $field = $field->post_name;
        } elseif ('email' == $settings['type'] || 'customer_email' == $settings['mapping']) {
            if (!is_email($_POST[$field->post_name])) {
                $error = kbs_form_submission_errors($field->ID, 'invalid_email');
                $field = $field->post_name;
            }
        }
        if ($error) {
            wp_send_json(array('error' => $error, 'field' => $field));
        }
    }
    if ($agree_to_terms && empty($_POST['kbs_agree_terms'])) {
        wp_send_json(array('error' => kbs_form_submission_errors(0, 'agree_to_terms'), 'field' => 'kbs_agree_terms'));
    }
    wp_send_json_success(array('error' => $error));
}