Beispiel #1
0
 public static function validate($params, $fields, $form, $title, $description)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     if (($_POST && isset($_POST['frm_page_order_' . $form->id]) || FrmProFormsHelper::going_to_prev($form->id)) && !FrmProFormsHelper::saving_draft()) {
         $errors = '';
         $fields = FrmFieldsHelper::get_form_fields($form->id);
         $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         add_filter('frm_continue_to_create', '__return_false');
     } else {
         if ($form->editable && isset($form->options['single_entry']) && $form->options['single_entry'] && $form->options['single_entry_type'] == 'user') {
             $user_ID = get_current_user_id();
             if ($user_ID) {
                 $entry = FrmEntry::getAll(array('it.user_id' => $user_ID, 'it.form_id' => $form->id), '', 1, true);
                 if ($entry) {
                     $entry = reset($entry);
                 }
             } else {
                 $entry = false;
             }
             if ($entry && !empty($entry) && (!isset($frm_vars['created_entries'][$form->id]) || !isset($frm_vars['created_entries'][$form->id]['entry_id']) || $entry->id != $frm_vars['created_entries'][$form->id]['entry_id'])) {
                 FrmProEntriesController::show_responses($entry, $fields, $form, $title, $description);
             } else {
                 $record = $frm_vars['created_entries'][$form->id]['entry_id'];
                 $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
                 if (FrmProFormsHelper::saving_draft()) {
                     $saved_message = isset($form->options['draft_msg']) ? $form->options['draft_msg'] : __('Your draft has been saved.', 'formidable');
                 }
                 $saved_message = apply_filters('frm_content', $saved_message, $form, $record ? $record : false);
                 $message = wpautop(do_shortcode($record ? $saved_message : $frm_settings->failed_msg));
                 $message = '<div class="frm_message" id="message">' . $message . '</div>';
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
             }
             add_filter('frm_continue_to_create', '__return_false');
         } else {
             if (FrmProFormsHelper::saving_draft()) {
                 $record = isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
                 if (!$record) {
                     return;
                 }
                 $saved_message = '';
                 FrmProFormsHelper::save_draft_msg($saved_message, $form, $record);
                 $message = FrmFormsHelper::get_success_message(array('message' => $saved_message, 'form' => $form, 'entry_id' => $record, 'class' => 'frm_message'));
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
                 add_filter('frm_continue_to_create', '__return_false');
             }
         }
     }
 }
Beispiel #2
0
            if ($values['custom_style']) {
                $frm_vars['load_css'] = true;
            }
            if ((!isset($frm_vars['css_loaded']) || !$frm_vars['css_loaded']) && $frm_vars['load_css']) {
                echo FrmAppController::footer_js('header');
                $frm_vars['css_loaded'] = true;
            }
            ?>
<div class="frm_forms<?php 
            echo $values['custom_style'] ? ' with_frm_style' : '';
            ?>
" id="frm_form_<?php 
            echo $form->id;
            ?>
_container"><?php 
            require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
            ?>
</div>
<?php 
        }
    } else {
        do_action('frm_success_action', $conf_method, $form, $form->options, $created);
    }
    do_action('frm_after_entry_processed', array('entry_id' => $created, 'form' => $form));
} else {
    do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
    if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])) {
        $values = FrmEntriesHelper::setup_new_vars($fields, $form);
        require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
    }
}
 function get_new_vars($errors = '', $form = '', $message = '')
 {
     global $frm_form, $frm_field, $frm_entry, $frm_settings, $frm_next_page;
     $title = true;
     $description = true;
     $fields = FrmFieldsHelper::get_form_fields($form->id, !empty($errors));
     $values = FrmEntriesHelper::setup_new_vars($fields, $form);
     $submit = isset($frm_next_page[$form->id]) ? $frm_next_page[$form->id] : (isset($values['submit_value']) ? $values['submit_value'] : $frm_settings->submit_value);
     require_once FRMPRO_VIEWS_PATH . '/frmpro-entries/new.php';
 }
Beispiel #4
0
 function validate($params, $fields, $form, $title, $description)
 {
     global $frm_entry, $frm_settings, $frm_vars;
     if (($_POST and isset($_POST['frm_page_order_' . $form->id]) or FrmProFormsHelper::going_to_prev($form->id)) and !FrmProFormsHelper::saving_draft($form->id)) {
         $errors = '';
         $fields = FrmFieldsHelper::get_form_fields($form->id);
         $form_name = $form->name;
         $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         add_filter('frm_continue_to_create', '__return_false');
     } else {
         if ($form->editable and isset($form->options['single_entry']) and $form->options['single_entry'] and $form->options['single_entry_type'] == 'user') {
             $user_ID = get_current_user_id();
             if ($user_ID) {
                 $entry = $frm_entry->getAll(array('it.user_id' => $user_ID, 'it.form_id' => $form->id), '', 1, true);
                 if ($entry) {
                     $entry = reset($entry);
                 }
             } else {
                 $entry = false;
             }
             if ($entry and !empty($entry) and (!isset($frm_vars['created_entries'][$form->id]) or !isset($frm_vars['created_entries'][$form->id]['entry_id']) or $entry->id != $frm_vars['created_entries'][$form->id]['entry_id'])) {
                 FrmProEntriesController::show_responses($entry, $fields, $form, $title, $description);
             } else {
                 $record = $frm_vars['created_entries'][$form->id]['entry_id'];
                 $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
                 if (FrmProFormsHelper::saving_draft($form->id)) {
                     global $frmpro_settings;
                     $saved_message = isset($form->options['draft_msg']) ? $form->options['draft_msg'] : $frmpro_settings->draft_msg;
                 }
                 $saved_message = apply_filters('frm_content', $saved_message, $form, $record ? $record : false);
                 $message = wpautop(do_shortcode($record ? $saved_message : $frm_settings->failed_msg));
                 $message = '<div class="frm_message" id="message">' . $message . '</div>';
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message, '', $form->options);
             }
             add_filter('frm_continue_to_create', '__return_false');
         } else {
             if (FrmProFormsHelper::saving_draft($form->id)) {
                 global $frmpro_settings;
                 $record = (isset($frm_vars['created_entries']) and isset($frm_vars['created_entries'][$form->id])) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
                 if ($record) {
                     $saved_message = isset($form->options['draft_msg']) ? $form->options['draft_msg'] : $frmpro_settings->draft_msg;
                     $saved_message = apply_filters('frm_content', $saved_message, $form, $record);
                     $message = '<div class="frm_message" id="message">' . wpautop(do_shortcode($saved_message)) . '</div>';
                     FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message, '', $form->options);
                     add_filter('frm_continue_to_create', '__return_false');
                 }
             }
         }
     }
 }
 public static function get_form_contents($form, $title, $description, $atts)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
     $user_ID = get_current_user_id();
     $params = FrmForm::get_params($form);
     $message = $errors = '';
     if ($params['posted_form_id'] == $form->id && $_POST) {
         $errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
     }
     $include_form_tag = apply_filters('frm_include_form_tag', true, $form);
     $fields = FrmFieldsHelper::get_form_fields($form->id, isset($errors) && !empty($errors));
     if ($params['action'] != 'create' || $params['posted_form_id'] != $form->id || !$_POST) {
         do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
         if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])) {
             $values = FrmEntriesHelper::setup_new_vars($fields, $form);
             include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         }
         return;
     }
     if (!empty($errors)) {
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         return;
     }
     do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
     if (!apply_filters('frm_continue_to_create', true, $form->id)) {
         return;
     }
     $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
     $created = isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
     $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
     if ($created && is_numeric($created) && $conf_method != 'message') {
         do_action('frm_success_action', $conf_method, $form, $form->options, $created);
         do_action('frm_after_entry_processed', array('entry_id' => $created, 'form' => $form));
         return;
     }
     if ($created && is_numeric($created)) {
         $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
         $class = 'frm_message';
     } else {
         $message = $frm_settings->failed_msg;
         $class = 'frm_error_style';
     }
     $message = FrmFormsHelper::get_success_message(array('message' => $message, 'form' => $form, 'entry_id' => $created, 'class' => $class));
     $message = apply_filters('frm_main_feedback', $message, $form, $created);
     if (!isset($form->options['show_form']) || $form->options['show_form']) {
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
     } else {
         global $frm_vars;
         self::maybe_load_css($form, $values['custom_style'], $frm_vars['load_css']);
         $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class($values);
         include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
     }
     do_action('frm_after_entry_processed', array('entry_id' => $created, 'form' => $form));
 }
 public static function get_new_vars($errors = array(), $form = false, $message = '')
 {
     global $frm_vars;
     $description = true;
     $title = false;
     $form = apply_filters('frm_pre_display_form', $form);
     if (!$form) {
         wp_die(__('You are trying to access an entry that does not exist.', 'formidable'));
         return;
     }
     $fields = FrmFieldsHelper::get_form_fields($form->id, !empty($errors));
     $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
     $frm_settings = FrmAppHelper::get_settings();
     $submit = isset($frm_vars['next_page'][$form->id]) ? $frm_vars['next_page'][$form->id] : (isset($values['submit_value']) ? $values['submit_value'] : $frm_settings->submit_value);
     if (is_object($submit)) {
         $submit = $submit->name;
     }
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-entries/new.php';
 }
 function validate($params, $fields, $form, $title, $description)
 {
     global $user_ID, $frm_entry_meta, $frm_entry, $frm_settings, $frmpro_settings, $frmpro_entries_controller, $frmdb;
     $form_options = stripslashes_deep(maybe_unserialize($form->options));
     $can_submit = true;
     if (isset($form_options['single_entry']) and $form_options['single_entry']) {
         if ($form_options['single_entry_type'] == 'cookie' and isset($_COOKIE['frm_form' . $form->id . '_' . COOKIEHASH])) {
             $can_submit = false;
         } else {
             if ($form_options['single_entry_type'] == 'ip') {
                 $prev_entry = $frm_entry->getAll(array('it.ip' => $_SERVER['REMOTE_ADDR']), '', 1);
                 if ($prev_entry) {
                     $can_submit = false;
                 }
             } else {
                 if ($form_options['single_entry_type'] == 'user' and !$form->editable) {
                     $meta = $frmdb->get_var($frmdb->entries, array('user_id' => $user_ID, 'form_id' => $form->id));
                     if ($meta) {
                         $can_submit = false;
                     }
                 } else {
                     if (is_numeric($form_options['single_entry_type'])) {
                         $field_id = $form_options['single_entry_type'];
                         $meta = $frm_entry_meta->getAll("meta_value='" . $_POST['item_meta'][$field_id] . "' and fi.id='{$field_id}' and fi.form_id='{$form->id}'", '', ' LIMIT 1');
                         if ($meta) {
                             $can_submit = false;
                         }
                     }
                 }
             }
         }
         if (!$can_submit) {
             echo stripslashes($frmpro_settings->already_submitted);
             //TODO: DO SOMETHING IF USER CANNOT RESUBMIT FORM
             add_filter('frm_continue_to_create', create_function('', 'return false;'));
             return;
         }
     }
     if (isset($_POST) and isset($_POST['frm_page_order_' . $form->id])) {
         global $frm_next_page;
         $errors = '';
         $fields = FrmFieldsHelper::get_form_fields($form->id);
         $form_name = $form->name;
         $submit = isset($form_options['submit_value']) ? $form_options['submit_value'] : $frm_settings->submit_value;
         $values = FrmEntriesHelper::setup_new_vars($fields, $form);
         require FRM_VIEWS_PATH . '/frm-entries/new.php';
         add_filter('frm_continue_to_create', create_function('', 'return false;'));
     } else {
         if ($form->editable and isset($form_options['single_entry']) and $form_options['single_entry']) {
             $saved_message = isset($form_options['success_msg']) ? $form_options['success_msg'] : $frm_settings->success_msg;
             $entry = $frm_entry->getAll(array('it.user_id' => $user_ID, 'it.form_id' => $form->id), '', 1, true);
             if ($entry and !empty($entry)) {
                 $message = stripslashes($frmpro_settings->already_submitted);
                 $frmpro_entries_controller->show_responses(reset($entry), $fields, $form, $title, $description, $message);
             } else {
                 $record = $frm_entry->create($_POST);
                 $message = $record ? $saved_message : $frm_settings->failed_msg;
                 $frmpro_entries_controller->show_responses($record, $fields, $form, $title, $description, $message, '', $form_options);
             }
             add_filter('frm_continue_to_create', create_function('', 'return false;'));
         }
     }
 }
 public static function repeat_field_set($field_name, $args = array())
 {
     $defaults = array('i' => 0, 'entry_id' => false, 'form' => false, 'fields' => array(), 'errors' => array(), 'parent_field' => 0, 'repeat' => 0, 'row_count' => false, 'value' => '', 'field_name' => '');
     $args = wp_parse_args($args, $defaults);
     if (empty($args['parent_field'])) {
         return;
     }
     if (is_numeric($args['parent_field'])) {
         $args['parent_field'] = (array) FrmField::getOne($args['parent_field']);
         $args['parent_field']['format'] = isset($args['parent_field']['field_options']['format']) ? $args['parent_field']['field_options']['format'] : '';
     }
     FrmForm::maybe_get_form($args['form']);
     if (empty($args['fields'])) {
         $args['fields'] = FrmField::get_all_for_form($args['form']->id);
     }
     $values = array();
     if ($args['fields']) {
         // Get the ID of the form that houses the embedded form or repeating section
         $parent_form_id = $args['parent_field']['form_id'];
         if (empty($args['entry_id'])) {
             $values = FrmEntriesHelper::setup_new_vars($args['fields'], $args['form'], false, array('parent_form_id' => $parent_form_id));
         } else {
             $entry = FrmEntry::getOne($args['entry_id'], true);
             if ($entry && $entry->form_id == $args['form']->id) {
                 $values = FrmAppHelper::setup_edit_vars($entry, 'entries', $args['fields'], false, array(), array('parent_form_id' => $parent_form_id));
             } else {
                 return;
             }
         }
     }
     $format = isset($args['parent_field']['format']) ? $args['parent_field']['format'] : '';
     $end = false;
     $count = 0;
     foreach ($values['fields'] as $subfield) {
         if ('end_divider' == $subfield['type']) {
             $end = $subfield;
         } else {
             if (!in_array($subfield['type'], array('hidden', 'user_id'))) {
                 if (isset($subfield['conf_field']) && $subfield['conf_field']) {
                     $count = $count + 2;
                 } else {
                     $count++;
                 }
             }
         }
         unset($subfield);
     }
     if ($args['repeat']) {
         $count++;
     }
     $classes = array(2 => 'half', 3 => 'third', 4 => 'fourth', 5 => 'fifth', 6 => 'sixth', 7 => 'seventh', 8 => 'eighth');
     $field_class = !empty($format) && isset($classes[$count]) ? $classes[$count] : '';
     echo '<div id="frm_section_' . $args['parent_field']['id'] . '-' . $args['i'] . '" class="frm_repeat_' . (empty($format) ? 'sec' : $format) . ' frm_repeat_' . $args['parent_field']['id'] . ($args['row_count'] === 0 ? ' frm_first_repeat' : '') . '">' . "\n";
     self::add_hidden_repeat_entry_id($args);
     self::add_default_item_meta_field($args);
     $label_pos = 'top';
     $field_num = 1;
     foreach ($values['fields'] as $subfield) {
         $subfield_name = $field_name . '[' . $args['i'] . '][' . $subfield['id'] . ']';
         $subfield_plus_id = '-' . $args['i'];
         $subfield_id = $subfield['id'] . '-' . $args['parent_field']['id'] . $subfield_plus_id;
         if ($args['parent_field'] && !empty($args['parent_field']['value']) && isset($args['parent_field']['value']['form']) && isset($args['parent_field']['value'][$args['i']]) && isset($args['parent_field']['value'][$args['i']][$subfield['id']])) {
             // this is a posted value from moving between pages, so set the POSTed value
             $subfield['value'] = $args['parent_field']['value'][$args['i']][$subfield['id']];
         }
         if (!empty($field_class)) {
             if (1 == $field_num) {
                 $subfield['classes'] .= ' frm_first frm_' . $field_class;
             } else {
                 $subfield['classes'] .= ' frm_' . $field_class;
             }
         }
         $field_num++;
         if ('top' == $label_pos && in_array($subfield['label'], array('top', 'hidden', ''))) {
             // add placeholder label if repeating
             $label_pos = 'hidden';
         }
         $field_args = array('field_name' => $subfield_name, 'field_id' => $subfield_id, 'field_plus_id' => $subfield_plus_id, 'section_id' => $args['parent_field']['id']);
         if (apply_filters('frm_show_normal_field_type', true, $subfield['type'])) {
             echo FrmFieldsHelper::replace_shortcodes($subfield['custom_html'], $subfield, $args['errors'], $args['form'], $field_args);
         } else {
             do_action('frm_show_other_field_type', $subfield, $args['form'], $field_args);
         }
         unset($subfield_name, $subfield_id);
         do_action('frm_get_field_scripts', $subfield, $args['form'], $args['parent_field']['form_id']);
     }
     if (!$args['repeat']) {
         // Close frm_repeat div
         echo '</div>' . "\n";
         return;
     }
     $args['format'] = $format;
     $args['label_pos'] = $label_pos;
     $args['field_class'] = $field_class;
     echo self::repeat_buttons($args, $end);
     // Close frm_repeat div
     echo '</div>' . "\n";
 }