function update($id, $values) { global $wpdb, $frmprodb, $frm_field; $new_values = array(); $values['display_key'] = isset($values['display_key']) ? $values['display_key'] : $values['name']; $new_values['display_key'] = FrmAppHelper::get_unique_key($values['display_key'], $frmprodb->displays, 'display_key', $id); $new_values['param'] = isset($values['param']) ? sanitize_title_with_dashes($values['param']) : ''; $fields = array('name', 'description', 'content', 'dyncontent', 'insert_loc', 'type', 'show_count', 'form_id', 'entry_id', 'post_id'); foreach ($fields as $field) { $new_values[$field] = $values[$field]; } $new_values['entry_id'] = isset($values['entry_id']) ? (int) $values['entry_id'] : 0; if (isset($values['options'])) { $new_values['options'] = array(); foreach ($values['options'] as $key => $value) { $new_values['options'][$key] = $value; } $new_values['options'] = maybe_serialize($new_values['options']); } $query_results = $wpdb->update($frmprodb->displays, $new_values, array('id' => $id)); if ($query_results) { wp_cache_delete($id, 'frm_display'); do_action('frm_update_display', $id, $values); } return $query_results; }
public static function validate($values, $exclude = false) { global $wpdb; FrmEntry::sanitize_entry_post($values); $errors = array(); if (!isset($values['form_id']) || !isset($values['item_meta'])) { $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable'); return $errors; } if (FrmAppHelper::is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry_' . $values['form_id']]) || !wp_verify_nonce($values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce'))) { $errors['form'] = __('You do not have permission to do that', 'formidable'); } if (!isset($values['item_key']) || $values['item_key'] == '') { $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key'); } $where = apply_filters('frm_posted_field_ids', array('fi.form_id' => $values['form_id'])); // Don't get subfields $where['fr.parent_form_id'] = array(null, 0); // Don't get excluded fields (like file upload fields in the ajax validation) if (!empty($exclude)) { $where['fi.type not'] = $exclude; } $posted_fields = FrmField::getAll($where, 'field_order'); // Pass exclude value to validate_field function so it can be used for repeating sections $args = array('exclude' => $exclude); foreach ($posted_fields as $posted_field) { self::validate_field($posted_field, $errors, $values, $args); unset($posted_field); } // check for spam self::spam_check($exclude, $values, $errors); $errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude')); return $errors; }
function update($id, $values) { global $wpdb; if (isset($values['field_key'])) { $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id); } if (isset($values['required'])) { $values['required'] = (int) $values['required']; } if (isset($values['default_value']) and is_array($values['default_value'])) { $values['default_value'] = serialize($values['default_value']); } if (isset($values['field_options']) and is_array($values['field_options'])) { $values['field_options'] = serialize($values['field_options']); } if (isset($values['options']) and is_array($values['options'])) { $values['options'] = serialize($values['options']); } $query_results = $wpdb->update($wpdb->prefix . 'frm_fields', $values, array('id' => $id)); if (isset($values['form_id'])) { $form_id = $values['form_id']; } else { $field = $this->getOne($id); if ($field) { $form_id = $field->form_id; } unset($field); } unset($values); if ($query_results) { wp_cache_delete($id, 'frm_field'); delete_transient('frm_all_form_fields_' . $form_id); } return $query_results; }
function get_default_field_opts($type, $field, $limit = false) { $field_options = array('size' => '', 'max' => '', 'label' => '', 'blank' => '', 'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0, 'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '', 'custom_html' => ''); if ($limit) { return $field_options; } global $frmdb, $frm_app_helper, $frm_settings; $form_id = is_numeric($field) ? $field : $field->form_id; $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key') : $field->field_key; $field_count = $frm_app_helper->getRecordCount("form_id='{$form_id}'", $frmdb->fields); return array('name' => __('Untitled', 'formidable'), 'description' => '', 'field_key' => $key, 'type' => $type, 'options' => '', 'default_value' => '', 'field_order' => $field_count + 1, 'required' => false, 'blank' => __('This field cannot be blank', 'formidable'), 'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id, 'field_options' => $field_options); }
function update($id, $values) { global $wpdb, $frmdb; if (isset($values['field_key'])) { $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $frmdb->fields, 'field_key', $id); } if (isset($values['field_options']) and is_array($values['field_options'])) { $values['field_options'] = serialize($values['field_options']); } $query_results = $wpdb->update($frmdb->fields, $values, array('id' => $id)); unset($values); if ($query_results) { wp_cache_delete($id, 'frm_field'); } return $query_results; }
public static function fill_field(&$values, $field, $form_id, $new_key = '') { global $wpdb; $values['field_key'] = FrmAppHelper::get_unique_key($new_key, $wpdb->prefix . 'frm_fields', 'field_key'); $values['form_id'] = $form_id; $values['options'] = maybe_serialize($field->options); $values['default_value'] = maybe_serialize($field->default_value); foreach (array('name', 'description', 'type', 'field_order', 'field_options', 'required') as $col) { $values[$col] = $field->{$col}; } }
/** * Used when a form is created */ public static function setup_new_vars($values = array()) { global $wpdb; if (!empty($values)) { $post_values = $values; } else { $values = array(); $post_values = isset($_POST) ? $_POST : array(); } foreach (array('name' => '', 'description' => '') as $var => $default) { if (!isset($values[$var])) { $values[$var] = FrmAppHelper::get_param($var, $default); } } $values['description'] = FrmAppHelper::use_wpautop($values['description']); foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0, 'status' => 'draft', 'parent_form_id' => 0) as $var => $default) { if (!isset($values[$var])) { $values[$var] = FrmAppHelper::get_param($var, $default); } } if (!isset($values['form_key'])) { $values['form_key'] = $post_values && isset($post_values['form_key']) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_forms', 'form_key'); } $values = self::fill_default_opts($values, false, $post_values); if ($post_values && isset($post_values['options']['custom_style'])) { $values['custom_style'] = $post_values['options']['custom_style']; } else { $frm_settings = FrmAppHelper::get_settings(); $values['custom_style'] = $frm_settings->load_style != 'none'; } return apply_filters('frm_setup_new_form_vars', $values); }
if ($form){ $form_id = $form->id; $frm_form->update($form_id, $values ); $form_fields = $frm_field->getAll(array('fi.form_id' => $form_id)); if (!empty($form_fields)){ foreach ($form_fields as $field) $frm_field->destroy($field->id); } }else $form_id = $frm_form->create( $values ); <?php foreach ($fields as $field) { $field->field_options = maybe_unserialize($field->field_options); $new_key = FrmAppHelper::get_unique_key($field->field_key, $frmdb->fields, 'field_key'); ?> $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars('<?php echo $field->type; ?> ', $form_id)); $field_values['field_key'] = '<?php echo $new_key; ?> '; <?php foreach (array('name', 'description', 'type', 'default_value', 'options', 'required', 'field_order') as $col) { ?> $field_values['<?php echo $col;
function __construct($factory = null) { parent::__construct($factory); global $wpdb; $this->default_generation_definitions = array('item_key' => FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key'), 'name' => new WP_UnitTest_Generator_Sequence('Entry name %s')); }
/** * Package the entry data for updating * * @since 2.0.16 * @param int $id * @param array $values * @return array $new_values */ private static function package_entry_to_update($id, $values) { global $wpdb; $new_values = array('name' => self::get_new_entry_name($values), 'form_id' => self::get_form_id($values), 'is_draft' => self::get_is_draft_value($values), 'updated_at' => current_time('mysql', 1), 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : get_current_user_id()); if (isset($values['post_id'])) { $new_values['post_id'] = (int) $values['post_id']; } if (isset($values['item_key'])) { $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id); } if (isset($values['parent_item_id'])) { $new_values['parent_item_id'] = (int) $values['parent_item_id']; } if (isset($values['frm_user_id']) && is_numeric($values['frm_user_id'])) { $new_values['user_id'] = $values['frm_user_id']; } $new_values = apply_filters('frm_update_entry', $new_values, $id); return $new_values; }
function create_post_entry($id = false, $post_id = false) { if (!$id) { $id = $_POST['id']; } if (!$post_id) { $post_id = $_POST['post_id']; } if (!is_numeric($id) or !is_numeric($post_id)) { return; } $post = get_post($post_id); global $frmdb, $wpdb, $frm_field; $values = array('description' => __('Copied from Post', 'formidable'), 'form_id' => $id, 'created_at' => $post->post_date_gmt, 'name' => $post->post_title, 'item_key' => FrmAppHelper::get_unique_key($post->post_name, $frmdb->entries, 'item_key'), 'user_id' => $post->post_author, 'post_id' => $post->ID); $results = $wpdb->insert($frmdb->entries, $values); unset($values); if ($results) { $entry_id = $wpdb->insert_id; $user_id_field = $frm_field->getAll(array('fi.type' => 'user_id', 'fi.form_id' => $id), '', 1); if ($user_id_field) { $new_values = array('meta_value' => $post->post_author, 'item_id' => $entry_id, 'field_id' => $user_id_field->id, 'created_at' => current_time('mysql', 1)); $wpdb->insert($frmdb->entry_metas, $new_values); } } die; }
public static function create_post_entry($id = false, $post_id = false) { if (!$id) { $id = $_POST['id']; } if (!$post_id) { $post_id = $_POST['post_id']; } if (!is_numeric($id) or !is_numeric($post_id)) { return; } $post = get_post($post_id); global $wpdb; $values = array('description' => __('Copied from Post', 'formidable'), 'form_id' => $id, 'created_at' => $post->post_date_gmt, 'name' => $post->post_title, 'item_key' => FrmAppHelper::get_unique_key($post->post_name, $wpdb->prefix . 'frm_items', 'item_key'), 'user_id' => $post->post_author, 'post_id' => $post->ID); $results = $wpdb->insert($wpdb->prefix . 'frm_items', $values); unset($values); if (!$results) { die; } $entry_id = $wpdb->insert_id; $frm_field = new FrmField(); $user_id_field = $frm_field->getAll(array('fi.type' => 'user_id', 'fi.form_id' => $id), '', 1); unset($frm_field); if ($user_id_field) { $new_values = array('meta_value' => $post->post_author, 'item_id' => $entry_id, 'field_id' => $user_id_field->id, 'created_at' => current_time('mysql', 1)); $wpdb->insert($wpdb->prefix . 'frm_item_metas', $new_values); } global $frmpro_display; $display = $frmpro_display->get_auto_custom_display(array('form_id' => $id, 'entry_id' => $entry_id)); if ($display) { update_post_meta($post->ID, 'frm_display_id', $display->ID); } die; }
function duplicate() { global $frmdb, $frm_field, $frm_app_helper, $frm_ajax_url; $copy_field = $frm_field->getOne($_POST['field_id']); if (!$copy_field) { return; } $values = array(); $values['field_key'] = FrmAppHelper::get_unique_key('', $frmdb->fields, 'field_key'); $values['field_options'] = maybe_unserialize($copy_field->field_options); $values['form_id'] = $copy_field->form_id; foreach (array('name', 'description', 'type', 'default_value', 'options', 'required') as $col) { $values[$col] = $copy_field->{$col}; } $field_count = $frm_app_helper->getRecordCount("form_id='{$copy_field->form_id}'", $frmdb->fields); $values['field_order'] = $field_count + 1; $field_id = $frm_field->create($values); if ($field_id) { $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id)); $field_name = "item_meta[{$field_id}]"; $id = $field['form_id']; require FRM_VIEWS_PATH . '/frm-forms/add_field.php'; require FRM_VIEWS_PATH . '/frm-forms/new-field-js.php'; } die; }
public static function setup_new_vars($values = array()) { global $wpdb, $frmdb, $frm_settings; if (!empty($values)) { $post_values = $values; } else { $values = array(); $post_values = isset($_POST) ? $_POST : array(); } foreach (array('name' => '', 'description' => '') as $var => $default) { if (!isset($values[$var])) { $values[$var] = FrmAppHelper::get_param($var, $default); } } if (apply_filters('frm_use_wpautop', true)) { $values['description'] = wpautop(str_replace('<br>', '<br />', $values['description'])); } foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default) { if (!isset($values[$var])) { $values[$var] = FrmAppHelper::get_param($var, $default); } } if (!isset($values['form_key'])) { $values['form_key'] = ($post_values and isset($post_values['form_key'])) ? $post_values['form_key'] : FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_forms', 'form_key'); } $values = self::fill_default_opts($values, false, $post_values); $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $post_values['options']['custom_style'] : $frm_settings->load_style != 'none'; $values['before_html'] = FrmFormsHelper::get_default_html('before'); $values['after_html'] = FrmFormsHelper::get_default_html('after'); $values['submit_html'] = FrmFormsHelper::get_default_html('submit'); return apply_filters('frm_setup_new_form_vars', $values); }
function update($id, $values, $create_link = false) { global $wpdb, $frmdb, $frm_field, $frm_settings; if ($create_link or isset($values['options']) or isset($values['item_meta']) or isset($values['field_options'])) { $values['status'] = 'published'; } if (isset($values['form_key'])) { $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $frmdb->forms, 'form_key', $id); } $form_fields = array('form_key', 'name', 'description', 'status', 'prli_link_id'); $new_values = array(); if (isset($values['options'])) { $options = array(); $defaults = FrmFormsHelper::get_default_opts(); foreach ($defaults as $var => $default) { $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default; } $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); $options = apply_filters('frm_form_options_before_update', $options, $values); $new_values['options'] = serialize($options); } foreach ($values as $value_key => $value) { if (in_array($value_key, $form_fields)) { $new_values[$value_key] = $value; } } if (!empty($new_values)) { $query_results = $wpdb->update($frmdb->forms, $new_values, array('id' => $id)); if ($query_results) { wp_cache_delete($id, 'frm_form'); } } else { $query_results = true; } $all_fields = $frm_field->getAll(array('fi.form_id' => $id)); if ($all_fields and (isset($values['options']) or isset($values['item_meta']) or isset($values['field_options']))) { if (!isset($values['item_meta'])) { $values['item_meta'] = array(); } $existing_keys = array_keys($values['item_meta']); foreach ($all_fields as $fid) { if (!in_array($fid->id, $existing_keys)) { $values['item_meta'][$fid->id] = ''; } } foreach ($values['item_meta'] as $field_id => $default_value) { $field = $frm_field->getOne($field_id); if (!$field) { continue; } $field_options = maybe_unserialize($field->field_options); if (isset($values['options']) or isset($values['field_options']['custom_html_' . $field_id])) { //updating the settings page if (isset($values['field_options']['custom_html_' . $field_id])) { $field_options['custom_html'] = isset($values['field_options']['custom_html_' . $field_id]) ? $values['field_options']['custom_html_' . $field_id] : (isset($field_options['custom_html']) ? $field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type)); $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); $frm_field->update($field_id, array('field_options' => $field_options)); } else { if ($field->type == 'hidden') { $prev_opts = $field_options; $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); if ($prev_opts != $field_options) { $frm_field->update($field_id, array('field_options' => $field_options)); } unset($prev_opts); } } } else { //updating the form foreach (array('size', 'max', 'label', 'invalid', 'required_indicator', 'blank', 'classes') as $opt) { $field_options[$opt] = isset($values['field_options'][$opt . '_' . $field_id]) ? trim($values['field_options'][$opt . '_' . $field_id]) : ''; } $field_options['separate_value'] = isset($values['field_options']['separate_value_' . $field_id]) ? trim($values['field_options']['separate_value_' . $field_id]) : 0; $field_options = apply_filters('frm_update_field_options', $field_options, $field, $values); $default_value = maybe_serialize($values['item_meta'][$field_id]); $field_key = isset($values['field_options']['field_key_' . $field_id]) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; $field_type = isset($values['field_options']['type_' . $field_id]) ? $values['field_options']['type_' . $field_id] : $field->type; $field_description = isset($values['field_options']['description_' . $field_id]) ? $values['field_options']['description_' . $field_id] : $field->description; $frm_field->update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field_options, 'description' => $field_description)); } } } if (isset($values['form_key']) && class_exists('PrliLink')) { $form = $this->getOne($id); global $prli_link; $prlink = $prli_link->getOne($form->prli_link_id); if ($prlink) { $prli = array(); $prli['url'] = FrmFormsHelper::get_direct_link($values['form_key']); $prli['slug'] = $prlink->slug; $prli['name'] = $prlink->name; $prli['param_forwarding'] = $prlink->param_forwarding; $prli['param_struct'] = $prlink->param_struct; $prli['redirect_type'] = $prlink->redirect_type; $prli['description'] = $prlink->description; $prli['track_me'] = $prlink->track_me; $prli['nofollow'] = $prlink->nofollow; $prli['group_id'] = $prlink->group_id; $prli_link->update($form->prli_link_id, $prli); //update target url } else { if ($create_link && $form->is_template != 1) { $link_id = prli_create_pretty_link(FrmFormsHelper::get_direct_link($values['form_key']), $values['form_key'], $form->name, $form->description, $group_id = ''); $wpdb->update($frmdb->forms, array('prli_link_id' => $link_id), array('id' => $id)); } } } do_action('frm_update_form', $id, $values); do_action('frm_update_form_' . $id, $values); return $query_results; }
public static function duplicate() { global $wpdb; $frm_field = new FrmField(); $copy_field = $frm_field->getOne($_POST['field_id']); if (!$copy_field) { return; } $values = array(); $values['field_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_fields', 'field_key'); $values['options'] = maybe_serialize($copy_field->options); $values['default_value'] = maybe_serialize($copy_field->default_value); $values['form_id'] = $copy_field->form_id; foreach (array('name', 'description', 'type', 'field_options', 'required') as $col) { $values[$col] = $copy_field->{$col}; } $field_count = FrmAppHelper::getRecordCount(array('form_id' => $copy_field->form_id), $wpdb->prefix . 'frm_fields'); $values['field_order'] = $field_count + 1; $field_id = $frm_field->create($values); if ($field_id) { $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id)); $field_name = "item_meta[{$field_id}]"; $id = $field['form_id']; if ($field['type'] == 'html') { $field['stop_filter'] = true; } require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php'; } die; }
public static function create_post_entry($id = false, $post_id = false) { if (FrmAppHelper::doing_ajax()) { check_ajax_referer('frm_ajax', 'nonce'); } if (!$id) { $id = (int) $_POST['id']; } if (!$post_id) { $post_id = (int) $_POST['post_id']; } if (!is_numeric($id) || !is_numeric($post_id)) { return; } $post = get_post($post_id); global $wpdb; $values = array('description' => __('Copied from Post', 'formidable'), 'form_id' => $id, 'created_at' => $post->post_date_gmt, 'name' => $post->post_title, 'item_key' => FrmAppHelper::get_unique_key($post->post_name, $wpdb->prefix . 'frm_items', 'item_key'), 'user_id' => $post->post_author, 'post_id' => $post->ID); $results = $wpdb->insert($wpdb->prefix . 'frm_items', $values); unset($values); if (!$results) { wp_die(); } $entry_id = $wpdb->insert_id; $user_id_field = FrmField::get_all_types_in_form($id, 'user_id', 1); if ($user_id_field) { $new_values = array('meta_value' => $post->post_author, 'item_id' => $entry_id, 'field_id' => $user_id_field->id, 'created_at' => current_time('mysql', 1)); $wpdb->insert($wpdb->prefix . 'frm_item_metas', $new_values); } $display = FrmProDisplay::get_auto_custom_display(array('form_id' => $id, 'entry_id' => $entry_id)); if ($display) { update_post_meta($post->ID, 'frm_display_id', $display->ID); } wp_die(); }
/** * @return int|boolean */ public static function update($id, $values, $create_link = false) { global $wpdb; if (!isset($values['status']) && ($create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']))) { $values['status'] = 'published'; } if (isset($values['form_key'])) { $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id); } $form_fields = array('form_key', 'name', 'description', 'status', 'parent_form_id'); $new_values = self::set_update_options(array(), $values); foreach ($values as $value_key => $value) { if (in_array($value_key, $form_fields)) { $new_values[$value_key] = $value; } } if (isset($values['new_status']) && !empty($values['new_status'])) { $new_values['status'] = $values['new_status']; } if (!empty($new_values)) { $query_results = $wpdb->update($wpdb->prefix . 'frm_forms', $new_values, array('id' => $id)); if ($query_results) { self::clear_form_cache(); } } else { $query_results = true; } unset($new_values); $values = self::update_fields($id, $values); do_action('frm_update_form', $id, $values); do_action('frm_update_form_' . $id, $values); return $query_results; }
public static function update($id, $values) { global $wpdb; $id = absint($id); if (isset($values['field_key'])) { $values['field_key'] = FrmAppHelper::get_unique_key($values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id); } if (isset($values['required'])) { $values['required'] = (int) $values['required']; } self::preserve_phone_format_backslashes($values); // serialize array values foreach (array('default_value', 'field_options', 'options') as $opt) { if (isset($values[$opt]) && is_array($values[$opt])) { $values[$opt] = serialize($values[$opt]); } } $query_results = $wpdb->update($wpdb->prefix . 'frm_fields', $values, array('id' => $id)); $form_id = 0; if (isset($values['form_id'])) { $form_id = absint($values['form_id']); } else { $field = self::getOne($id); if ($field) { $form_id = $field->form_id; } unset($field); } unset($values); if ($query_results) { wp_cache_delete($id, 'frm_field'); if ($form_id) { self::delete_form_transient($form_id); } } return $query_results; }
function validate($values, $exclude = false) { global $wpdb, $frmdb, $frm_field, $frm_entry_meta; $errors = array(); if (!isset($values['form_id']) or !isset($values['item_meta'])) { $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable'); return $errors; } if (!isset($values['item_key']) or $values['item_key'] == '') { $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $frmdb->entries, 'item_key'); } $where = apply_filters('frm_posted_field_ids', 'fi.form_id=' . (int) $values['form_id']); if ($exclude) { $where .= " and fi.type not in ('" . implode("','", $exclude) . "')"; } $posted_fields = $frm_field->getAll($where, 'fi.field_order'); foreach ($posted_fields as $posted_field) { $posted_field->field_options = maybe_unserialize($posted_field->field_options); $value = ''; if (isset($values['item_meta'][$posted_field->id])) { $value = $values['item_meta'][$posted_field->id]; } if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value) { $_POST['item_meta'][$posted_field->id] = $value = ''; } if ($posted_field->type == 'rte' and trim($value) == '<br>') { $value = ''; } if ($posted_field->required == '1' and !is_array($value) and trim($value) == '') { $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? __('This field cannot be blank', 'formidable') : $posted_field->field_options['blank']; } else { if ($posted_field->type == 'text' and !isset($_POST['name'])) { $_POST['name'] = $value; } } if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])) { global $frm_settings; if (!function_exists('recaptcha_check_answer')) { require_once FRM_PATH . '/classes/recaptchalib.php'; } $response = recaptcha_check_answer($frm_settings->privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$response->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errors['captcha-' . $response->error] = $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid']; } } $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value); } global $wpcom_api_key; if (isset($values['item_meta']) and !empty($values['item_meta']) and empty($errors) and function_exists('akismet_http_post') and (get_option('wordpress_api_key') or $wpcom_api_key) and $this->akismet($values)) { global $frm_form; $form = $frm_form->getOne($values['form_id']); $form->options = maybe_unserialize($form->options); if (isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' or !is_user_logged_in())) { $errors['spam'] = __('Your entry appears to be spam!', 'formidable'); } } return apply_filters('frm_validate_entry', $errors, $values); }
function validate($values, $exclude = false) { global $wpdb, $frm_field, $frm_entry_meta, $frm_settings; $errors = array(); if (!isset($values['form_id']) || !isset($values['item_meta'])) { $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable'); return $errors; } if (is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry_' . $values['form_id']]) || !wp_verify_nonce($values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce'))) { $errors['form'] = __('You do not have permission to do that', 'formidable'); } if (!isset($values['item_key']) or $values['item_key'] == '') { $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key'); } $where = apply_filters('frm_posted_field_ids', 'fi.form_id=' . (int) $values['form_id']); if ($exclude) { $where .= " and fi.type not in ('" . implode("','", array_filter($exclude, 'esc_sql')) . "')"; } $posted_fields = $frm_field->getAll($where, 'field_order'); foreach ($posted_fields as $posted_field) { $posted_field->field_options = maybe_unserialize($posted_field->field_options); $value = ''; if (isset($values['item_meta'][$posted_field->id])) { $value = $values['item_meta'][$posted_field->id]; } if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value) { $value = ''; } if (is_array($value) and count($value) === 1) { $value = reset($value); } if ($posted_field->type == 'rte' and !is_array($value) and trim($value) == '<br>') { $value = ''; } if ($posted_field->required == '1' and !is_array($value) and trim($value) == '') { $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $posted_field->field_options['blank']; } else { if ($posted_field->type == 'text' and !isset($_POST['name'])) { $_POST['name'] = $value; } } $_POST['item_meta'][$posted_field->id] = $value; if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])) { global $frm_settings; if (!function_exists('recaptcha_check_answer')) { require FrmAppHelper::plugin_path() . '/classes/recaptchalib.php'; } $response = recaptcha_check_answer($frm_settings->privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$response->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errors['captcha-' . $response->error] = $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid']; } } $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value); } // check for spam if (empty($exclude) && isset($values['item_meta']) && !empty($values['item_meta']) && empty($errors)) { global $wpcom_api_key; if ((function_exists('akismet_http_post') || is_callable('Akismet::http_post')) && (get_option('wordpress_api_key') || $wpcom_api_key) && $this->akismet($values)) { $frm_form = new FrmForm(); $form = $frm_form->getOne($values['form_id']); if (isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' || !is_user_logged_in())) { $errors['spam'] = __('Your entry appears to be spam!', 'formidable'); } } // check for blacklist keys if ($this->blacklist_check($values)) { $errors['spam'] = __('Your entry appears to be spam!', 'formidable'); } } $errors = apply_filters('frm_validate_entry', $errors, $values); return $errors; }
function setup_new_vars() { global $frmdb, $frm_settings; $values = array(); foreach (array('name' => __('Untitled Form', 'formidable'), 'description' => '') as $var => $default) { $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default)); } if (apply_filters('frm_use_wpautop', true)) { $values['description'] = wpautop($values['description']); } foreach (array('form_id' => '', 'logged_in' => '', 'editable' => '', 'default_template' => 0, 'is_template' => 0) as $var => $default) { $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default)); } $values['form_key'] = ($_POST and isset($_POST['form_key'])) ? $_POST['form_key'] : FrmAppHelper::get_unique_key('', $frmdb->forms, 'form_key'); $defaults = FrmFormsHelper::get_default_opts(); foreach ($defaults as $var => $default) { $values[$var] = ($_POST and isset($_POST['options'][$var])) ? $_POST['options'][$var] : $default; } $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->load_style != 'none'; $values['before_html'] = FrmFormsHelper::get_default_html('before'); $values['after_html'] = FrmFormsHelper::get_default_html('after'); return apply_filters('frm_setup_new_form_vars', $values); }
public static function update($id, $values) { global $wpdb, $frm_vars; if (isset($frm_vars['saved_entries']) && is_array($frm_vars['saved_entries']) && in_array((int) $id, (array) $frm_vars['saved_entries'])) { return; } $values = apply_filters('frm_pre_update_entry', $values, $id); $user_ID = get_current_user_id(); $item_name = self::get_new_entry_name($values); $new_values = array('name' => $item_name, 'form_id' => isset($values['form_id']) ? (int) $values['form_id'] : null, 'is_draft' => isset($values['frm_saving_draft']) && $values['frm_saving_draft'] == 1 || isset($values['is_draft']) && $values['is_draft'] == 1 ? 1 : 0, 'updated_at' => current_time('mysql', 1), 'updated_by' => isset($values['updated_by']) ? $values['updated_by'] : $user_ID); if (isset($values['post_id'])) { $new_values['post_id'] = (int) $values['post_id']; } if (isset($values['item_key'])) { $new_values['item_key'] = FrmAppHelper::get_unique_key($values['item_key'], $wpdb->prefix . 'frm_items', 'item_key', $id); } if (isset($values['parent_item_id'])) { $new_values['parent_item_id'] = (int) $values['parent_item_id']; } if (isset($values['frm_user_id']) && is_numeric($values['frm_user_id'])) { $new_values['user_id'] = $values['frm_user_id']; } $new_values = apply_filters('frm_update_entry', $new_values, $id); $query_results = $wpdb->update($wpdb->prefix . 'frm_items', $new_values, compact('id')); if ($query_results) { self::clear_cache(); } if (!isset($frm_vars['saved_entries'])) { $frm_vars['saved_entries'] = array(); } $frm_vars['saved_entries'][] = (int) $id; if (isset($values['item_meta'])) { FrmEntryMeta::update_entry_metas($id, $values['item_meta']); } do_action('frm_after_update_entry', $id, $new_values['form_id']); do_action('frm_after_update_entry_' . $new_values['form_id'], $id); return $query_results; }
function update($id, $values, $create_link = false) { global $wpdb, $frm_field, $frm_settings; if ($create_link || isset($values['options']) || isset($values['item_meta']) || isset($values['field_options'])) { $values['status'] = 'published'; } if (isset($values['form_key'])) { $values['form_key'] = FrmAppHelper::get_unique_key($values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id); } $form_fields = array('form_key', 'name', 'description', 'status', 'prli_link_id'); $new_values = array(); if (isset($values['options'])) { $options = array(); $defaults = FrmFormsHelper::get_default_opts(); foreach ($defaults as $var => $default) { if ($var == 'notification' && !defined('WP_IMPORTING')) { $options[$var] = isset($values[$var]) ? $values[$var] : $default; } else { $options[$var] = isset($values['options'][$var]) ? $values['options'][$var] : $default; } } $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); $options['submit_html'] = isset($values['options']['submit_html']) && $values['options']['submit_html'] != '' ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); $options = apply_filters('frm_form_options_before_update', $options, $values); $new_values['options'] = serialize($options); } foreach ($values as $value_key => $value) { if (in_array($value_key, $form_fields)) { $new_values[$value_key] = $value; } } if (!empty($new_values)) { $query_results = $wpdb->update($wpdb->prefix . 'frm_forms', $new_values, array('id' => $id)); if ($query_results) { wp_cache_delete($id, 'frm_form'); } } else { $query_results = true; } $all_fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order'); if ($all_fields && (isset($values['options']) || isset($values['item_meta']) || isset($values['field_options']))) { if (!isset($values['item_meta'])) { $values['item_meta'] = array(); } $existing_keys = array_keys($values['item_meta']); foreach ($all_fields as $fid) { if (!in_array($fid->id, $existing_keys) && (isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted'])) || isset($values['options'])) { $values['item_meta'][$fid->id] = ''; } } foreach ($values['item_meta'] as $field_id => $default_value) { $field = $frm_field->getOne($field_id); if (!$field) { continue; } $field_options = maybe_unserialize($field->field_options); if (isset($values['options']) || isset($values['field_options']['custom_html_' . $field_id])) { //updating the settings page if (isset($values['field_options']['custom_html_' . $field_id])) { $field_options['custom_html'] = isset($values['field_options']['custom_html_' . $field_id]) ? $values['field_options']['custom_html_' . $field_id] : (isset($field_options['custom_html']) ? $field_options['custom_html'] : FrmFieldsHelper::get_default_html($field->type)); $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); $frm_field->update($field_id, array('field_options' => $field_options)); } else { if ($field->type == 'hidden' || $field->type == 'user_id') { $prev_opts = $field_options; $field_options = apply_filters('frm_update_form_field_options', $field_options, $field, $values); if ($prev_opts != $field_options) { $frm_field->update($field_id, array('field_options' => $field_options)); } unset($prev_opts); } } } if (!isset($values['options']) && !isset($values['field_options']['custom_html_' . $field_id]) || defined('WP_IMPORTING')) { //updating the form foreach (array('size', 'max', 'label', 'invalid', 'blank', 'classes') as $opt) { $field_options[$opt] = isset($values['field_options'][$opt . '_' . $field_id]) ? trim($values['field_options'][$opt . '_' . $field_id]) : ''; } $field_options['required_indicator'] = isset($values['field_options']['required_indicator_' . $field_id]) ? trim($values['field_options']['required_indicator_' . $field_id]) : '*'; $field_options['separate_value'] = isset($values['field_options']['separate_value_' . $field_id]) ? trim($values['field_options']['separate_value_' . $field_id]) : 0; $field_options = apply_filters('frm_update_field_options', $field_options, $field, $values); $default_value = maybe_serialize($values['item_meta'][$field_id]); $field_key = isset($values['field_options']['field_key_' . $field_id]) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; $required = isset($values['field_options']['required_' . $field_id]) ? $values['field_options']['required_' . $field_id] : false; $field_type = isset($values['field_options']['type_' . $field_id]) ? $values['field_options']['type_' . $field_id] : $field->type; $field_description = isset($values['field_options']['description_' . $field_id]) ? $values['field_options']['description_' . $field_id] : $field->description; $frm_field->update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field_options, 'description' => $field_description, 'required' => $required)); } } } do_action('frm_update_form', $id, $values); do_action('frm_update_form_' . $id, $values); return $query_results; }