本文整理汇总了PHP中FrmFormsHelper::get_default_opts方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmFormsHelper::get_default_opts方法的具体用法?PHP FrmFormsHelper::get_default_opts怎么用?PHP FrmFormsHelper::get_default_opts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmFormsHelper
的用法示例。
在下文中一共展示了FrmFormsHelper::get_default_opts方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup_new_vars
public static function setup_new_vars($fields, $form = '', $reset = false, $args = array())
{
global $frm_vars;
$values = array();
foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default) {
$values[$var] = FrmAppHelper::get_post_param($var, $default);
}
$values['fields'] = array();
if (empty($fields)) {
return apply_filters('frm_setup_new_entry', $values);
}
foreach ((array) $fields as $field) {
$new_value = self::get_field_value_for_new_entry($field, $reset);
$field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id, 'parent_form_id' => isset($args['parent_form_id']) ? $args['parent_form_id'] : $field->form_id);
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
$opt_defaults['required_indicator'] = '';
$opt_defaults['original_type'] = $field->type;
foreach ($opt_defaults as $opt => $default_opt) {
$field_array[$opt] = isset($field->field_options[$opt]) && $field->field_options[$opt] != '' ? $field->field_options[$opt] : $default_opt;
unset($opt, $default_opt);
}
unset($opt_defaults);
if ($field_array['custom_html'] == '') {
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
}
$field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
$field_array = array_merge($field->field_options, $field_array);
$values['fields'][] = $field_array;
if (!$form || !isset($form->id)) {
$form = FrmForm::getOne($field->form_id);
}
}
$form->options = maybe_unserialize($form->options);
if (is_array($form->options)) {
foreach ($form->options as $opt => $value) {
$values[$opt] = FrmAppHelper::get_post_param($opt, $value);
unset($opt, $value);
}
}
$form_defaults = FrmFormsHelper::get_default_opts();
$frm_settings = FrmAppHelper::get_settings();
$form_defaults['custom_style'] = $frm_settings->load_style != 'none';
$values = array_merge($form_defaults, $values);
return apply_filters('frm_setup_new_entry', $values);
}
示例2: fill_form_defaults
/**
* Set to POST value or default
*/
private static function fill_form_defaults($post_values, array &$values)
{
$form_defaults = FrmFormsHelper::get_default_opts();
foreach ($form_defaults as $opt => $default) {
if (!isset($values[$opt]) || $values[$opt] == '') {
$values[$opt] = $post_values && isset($post_values['options'][$opt]) ? $post_values['options'][$opt] : $default;
}
unset($opt, $defaut);
}
if (!isset($values['custom_style'])) {
$frm_settings = self::get_settings();
$values['custom_style'] = $post_values && isset($post_values['options']['custom_style']) ? absint($_POST['options']['custom_style']) : $frm_settings->load_style != 'none';
}
foreach (array('before', 'after', 'submit') as $h) {
if (!isset($values[$h . '_html'])) {
$values[$h . '_html'] = isset($post_values['options'][$h . '_html']) ? $post_values['options'][$h . '_html'] : FrmFormsHelper::get_default_html($h);
}
unset($h);
}
}
示例3: setup_new_vars
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);
}
示例4: setup_edit_vars
function setup_edit_vars($record, $table, $fields = '', $default = false)
{
if (!$record) {
return false;
}
global $frm_entry_meta, $frm_form, $frm_settings, $frm_sidebar_width;
$values = array();
$values['id'] = $record->id;
foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val) {
$values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val));
}
if (apply_filters('frm_use_wpautop', true)) {
$values['description'] = wpautop($values['description']);
}
$values['fields'] = array();
if ($fields) {
foreach ($fields as $field) {
$field->field_options = stripslashes_deep(maybe_unserialize($field->field_options));
if ($default) {
$meta_value = $field->default_value;
} else {
if ($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']) {
$meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
} else {
if (isset($record->metas)) {
$meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
} else {
$meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id);
}
}
}
$field_type = isset($_POST['field_options']['type_' . $field->id]) ? $_POST['field_options']['type_' . $field->id] : $field->type;
$new_value = isset($_POST['item_meta'][$field->id]) ? $_POST['item_meta'][$field->id] : $meta_value;
$new_value = maybe_unserialize($new_value);
if (is_array($new_value)) {
$new_value = stripslashes_deep($new_value);
}
$field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => stripslashes_deep(maybe_unserialize($field->default_value)), 'name' => stripslashes($field->name), 'description' => stripslashes($field->description), 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), 'options' => stripslashes_deep(maybe_unserialize($field->options)), 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id);
/*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){
foreach((array)$field_array['options'] as $opt_key => $opt){
if(!is_array($opt))
$field_array['options'][$opt_key] = array('label' => $opt);
unset($opt);
unset($opt_key);
}
}*/
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
foreach ($opt_defaults as $opt => $default_opt) {
$field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt . '_' . $field->id])) ? $_POST['field_options'][$opt . '_' . $field->id] : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
if ($opt == 'blank' and $field_array[$opt] == '') {
$field_array[$opt] = __('This field cannot be blank', 'formidable');
} else {
if ($opt == 'invalid' and $field_array[$opt] == '') {
if ($field_type == 'captcha') {
$field_array[$opt] = $frm_settings->re_msg;
} else {
$field_array[$opt] = $field_array['name'] . ' ' . __('is invalid', 'formidable');
}
}
}
}
unset($opt_defaults);
if ($field_array['custom_html'] == '') {
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
}
if ($field_array['size'] == '') {
$field_array['size'] = $frm_sidebar_width;
}
$values['fields'][] = apply_filters('frm_setup_edit_fields_vars', stripslashes_deep($field_array), $field, $values['id']);
unset($field);
}
}
if ($table == 'entries') {
$form = $frm_form->getOne($record->form_id);
} else {
if ($table == 'forms') {
$form = $frm_form->getOne($record->id);
}
}
if ($form) {
$form->options = maybe_unserialize($form->options);
$values['form_name'] = isset($record->form_id) ? $form->name : '';
if (is_array($form->options)) {
foreach ($form->options as $opt => $value) {
$values[$opt] = FrmAppHelper::get_param($opt, $value);
}
}
}
$form_defaults = FrmFormsHelper::get_default_opts();
$form_defaults['email_to'] = '';
//options to allow blank answers
foreach (array('email_to', 'reply_to', 'reply_to_name') as $opt) {
if (!isset($values[$opt])) {
$values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $form_defaults[$opt];
unset($form_defaults[$opt]);
unset($opt);
}
}
//don't allow blank answers
foreach ($form_defaults as $opt => $default) {
//.........这里部分代码省略.........
示例5: fill_default_opts
public static function fill_default_opts($values, $record, $post_values)
{
$defaults = FrmFormsHelper::get_default_opts();
foreach ($defaults as $var => $default) {
if (is_array($default)) {
if (!isset($values[$var])) {
$values[$var] = $record && isset($record->options[$var]) ? $record->options[$var] : array();
}
foreach ($default as $k => $v) {
$values[$var][$k] = $post_values && isset($post_values[$var][$k]) ? $post_values[$var][$k] : ($record && isset($record->options[$var]) && isset($record->options[$var][$k]) ? $record->options[$var][$k] : $v);
if (is_array($v)) {
foreach ($v as $k1 => $v1) {
$values[$var][$k][$k1] = $post_values && isset($post_values[$var][$k][$k1]) ? $post_values[$var][$k][$k1] : ($record && isset($record->options[$var]) && isset($record->options[$var][$k]) && isset($record->options[$var][$k][$k1]) ? $record->options[$var][$k][$k1] : $v1);
unset($k1);
unset($v1);
}
}
unset($k);
unset($v);
}
} else {
$values[$var] = $post_values && isset($post_values['options'][$var]) ? $post_values['options'][$var] : ($record && isset($record->options[$var]) ? $record->options[$var] : $default);
}
unset($var);
unset($default);
}
return $values;
}
示例6: update
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;
//.........这里部分代码省略.........
示例7: setup_edit_vars
public static function setup_edit_vars($record, $table, $fields = '', $default = false, $post_values = array())
{
if (!$record) {
return false;
}
global $frm_entry_meta, $frm_settings, $frm_vars;
if (empty($post_values)) {
$post_values = stripslashes_deep($_POST);
}
$values = array('id' => $record->id, 'fields' => array());
foreach (array('name', 'description') as $var) {
$default_val = isset($record->{$var}) ? $record->{$var} : '';
$values[$var] = FrmAppHelper::get_param($var, $default_val);
unset($var, $default_val);
}
if (apply_filters('frm_use_wpautop', true)) {
$values['description'] = wpautop(str_replace('<br>', '<br />', $values['description']));
}
foreach ((array) $fields as $field) {
if ($default) {
$meta_value = $field->default_value;
} else {
if ($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']) {
if (!isset($field->field_options['custom_field'])) {
$field->field_options['custom_field'] = '';
}
$meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field));
} else {
if (isset($record->metas)) {
$meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false;
} else {
$meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id);
}
}
}
$field_type = isset($post_values['field_options']['type_' . $field->id]) ? $post_values['field_options']['type_' . $field->id] : $field->type;
$new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value;
$field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id);
/*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){
foreach((array)$field_array['options'] as $opt_key => $opt){
if(!is_array($opt))
$field_array['options'][$opt_key] = array('label' => $opt);
unset($opt);
unset($opt_key);
}
}*/
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
foreach ($opt_defaults as $opt => $default_opt) {
$field_array[$opt] = $post_values && isset($post_values['field_options'][$opt . '_' . $field->id]) ? maybe_unserialize($post_values['field_options'][$opt . '_' . $field->id]) : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt);
if ($opt == 'blank' and $field_array[$opt] == '') {
$field_array[$opt] = $frm_settings->blank_msg;
} else {
if ($opt == 'invalid' and $field_array[$opt] == '') {
if ($field_type == 'captcha') {
$field_array[$opt] = $frm_settings->re_msg;
} else {
$field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']);
}
}
}
}
unset($opt_defaults);
if ($field_array['custom_html'] == '') {
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type);
}
if ($field_array['size'] == '') {
$field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
}
$field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']);
if (!isset($field_array['unique']) or !$field_array['unique']) {
$field_array['unique_msg'] = '';
}
foreach ((array) $field->field_options as $k => $v) {
if (!isset($field_array[$k])) {
$field_array[$k] = $v;
}
unset($k);
unset($v);
}
$values['fields'][$field->id] = $field_array;
unset($field);
}
$frm_form = new FrmForm();
$form = $frm_form->getOne($table == 'entries' ? $record->form_id : $record->id);
unset($frm_form);
if ($form) {
$values['form_name'] = isset($record->form_id) ? $form->name : '';
if (is_array($form->options)) {
foreach ($form->options as $opt => $value) {
if (in_array($opt, array('email_to', 'reply_to', 'reply_to_name'))) {
$values['notification'][0][$opt] = isset($post_values["notification[0][{$opt}]"]) ? maybe_unserialize($post_values["notification[0][{$opt}]"]) : $value;
}
$values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value;
}
}
}
$form_defaults = FrmFormsHelper::get_default_opts();
//set to posted value or default
foreach ($form_defaults as $opt => $default) {
if (!isset($values[$opt]) or $values[$opt] == '') {
//.........这里部分代码省略.........
示例8: setup_new_vars
public static function setup_new_vars($fields, $form = '', $reset = false)
{
global $frm_vars;
$values = array();
foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default) {
$values[$var] = FrmAppHelper::get_post_param($var, $default);
}
$values['fields'] = array();
if (empty($fields)) {
return apply_filters('frm_setup_new_entry', $values);
}
foreach ((array) $fields as $field) {
$default = $field->default_value;
$posted_val = false;
$new_value = $default;
if (!$reset && $_POST && isset($_POST['item_meta'][$field->id]) && $_POST['item_meta'][$field->id] != '') {
$new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
$posted_val = true;
} else {
if (FrmField::is_option_true($field, 'clear_on_focus')) {
$new_value = '';
}
}
$is_default = $new_value == $default ? true : false;
//If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
$return_array = FrmField::is_field_with_multiple_values($field);
$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
if (!is_array($new_value)) {
if ($is_default) {
$new_value = $field->default_value;
} else {
if (!$posted_val) {
$new_value = apply_filters('frm_filter_default_value', $new_value, $field);
}
}
$new_value = str_replace('"', '"', $new_value);
}
unset($is_default, $posted_val);
$field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id);
$opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true);
$opt_defaults['required_indicator'] = '';
$opt_defaults['original_type'] = $field->type;
foreach ($opt_defaults as $opt => $default_opt) {
$field_array[$opt] = isset($field->field_options[$opt]) && $field->field_options[$opt] != '' ? $field->field_options[$opt] : $default_opt;
unset($opt, $default_opt);
}
unset($opt_defaults);
if ($field_array['custom_html'] == '') {
$field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type);
}
$field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field);
$field_array = array_merge($field->field_options, $field_array);
$values['fields'][] = $field_array;
if (!$form || !isset($form->id)) {
$form = FrmForm::getOne($field->form_id);
}
}
$form->options = maybe_unserialize($form->options);
if (is_array($form->options)) {
foreach ($form->options as $opt => $value) {
$values[$opt] = FrmAppHelper::get_post_param($opt, $value);
unset($opt, $value);
}
}
$form_defaults = FrmFormsHelper::get_default_opts();
$frm_settings = FrmAppHelper::get_settings();
$form_defaults['custom_style'] = $frm_settings->load_style != 'none';
$values = array_merge($form_defaults, $values);
return apply_filters('frm_setup_new_entry', $values);
}
示例9: update
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;
}