本文整理汇总了PHP中FrmFormsHelper::setup_edit_vars方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmFormsHelper::setup_edit_vars方法的具体用法?PHP FrmFormsHelper::setup_edit_vars怎么用?PHP FrmFormsHelper::setup_edit_vars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmFormsHelper
的用法示例。
在下文中一共展示了FrmFormsHelper::setup_edit_vars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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) {
//.........这里部分代码省略.........
示例2: setup_edit_vars
/**
* Editing a Form or Entry
* @param string $table
* @return bool|array
*/
public static function setup_edit_vars($record, $table, $fields = '', $default = false, $post_values = array())
{
if (!$record) {
return false;
}
global $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] = self::get_param($var, $default_val);
unset($var, $default_val);
}
$values['description'] = self::use_wpautop($values['description']);
$frm_settings = self::get_settings();
$is_form_builder = self::is_admin_page('formidable');
foreach ((array) $fields as $field) {
// Make sure to filter default values (for placeholder text), but not on the form builder page
if (!$is_form_builder) {
$field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true);
}
self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings'));
}
self::fill_form_opts($record, $table, $post_values, $values);
if ($table == 'entries') {
$values = FrmEntriesHelper::setup_edit_vars($values, $record);
} else {
if ($table == 'forms') {
$values = FrmFormsHelper::setup_edit_vars($values, $record, $post_values);
}
}
return $values;
}
示例3: 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] == '') {
//.........这里部分代码省略.........