本文整理汇总了PHP中FrmField::create方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmField::create方法的具体用法?PHP FrmField::create怎么用?PHP FrmField::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmField
的用法示例。
在下文中一共展示了FrmField::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import_xml_fields
/**
* Import all fields for a form
* @since 2.0.13
*
* TODO: Cut down on params
*/
private static function import_xml_fields($xml_fields, $form_id, $this_form, &$form_fields, &$imported, &$repeat_fields)
{
foreach ($xml_fields as $field) {
$f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'hidden', 'password', 'tag', 'image'))) {
if (count($f['default_value']) === 1) {
$f['default_value'] = '[' . reset($f['default_value']) . ']';
} else {
$f['default_value'] = reset($f['default_value']);
}
}
$f = apply_filters('frm_duplicated_field', $f);
if (!empty($this_form)) {
// check for field to edit by field id
if (isset($form_fields[$f['id']])) {
FrmField::update($f['id'], $f);
$imported['updated']['fields']++;
unset($form_fields[$f['id']]);
//unset old field key
if (isset($form_fields[$f['field_key']])) {
unset($form_fields[$f['field_key']]);
}
} else {
if (isset($form_fields[$f['field_key']])) {
// check for field to edit by field key
unset($f['id']);
FrmField::update($form_fields[$f['field_key']], $f);
$imported['updated']['fields']++;
unset($form_fields[$form_fields[$f['field_key']]]);
//unset old field id
unset($form_fields[$f['field_key']]);
//unset old field key
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
// if no matching field id or key in this form, create the field
$imported['imported']['fields']++;
}
}
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
$imported['imported']['fields']++;
}
unset($field, $new_id);
}
}
示例2: create_object
function create_object($args)
{
$field_values = FrmFieldsHelper::setup_new_vars($args['type'], $args['form_id']);
return FrmField::create($field_values);
}
示例3: duplicate
public static function duplicate()
{
check_ajax_referer('frm_ajax', 'nonce');
global $wpdb;
$field_id = FrmAppHelper::get_post_param('field_id', 0, 'absint');
$form_id = FrmAppHelper::get_post_param('form_id', 0, 'absint');
$copy_field = FrmField::getOne($field_id);
if (!$copy_field) {
wp_die();
}
do_action('frm_duplicate_field', $copy_field, $form_id);
do_action('frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id);
$values = array('id' => $form_id);
FrmFieldsHelper::fill_field($values, $copy_field, $form_id);
$field_count = FrmDb::get_count($wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array('or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id));
$values['field_order'] = $field_count + 1;
if (!($field_id = FrmField::create($values))) {
wp_die();
}
self::include_single_field($field_id, $values);
wp_die();
}
示例4: import_xml_forms
public static function import_xml_forms($forms, $imported)
{
$frm_form = new FrmForm();
$frm_field = new FrmField();
foreach ($forms as $item) {
$form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
// if template, allow to edit if form keys match, otherwise, creation date must also match
$edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
if (!$form['is_template']) {
$edit_query['created_at'] = $form['created_at'];
}
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
$this_form = $frm_form->getAll($edit_query, '', 1);
unset($edit_query);
if (!empty($this_form)) {
$form_id = $this_form->id;
$frm_form->update($form_id, $form);
$imported['updated']['forms']++;
$form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
$old_fields = array();
foreach ($form_fields as $f) {
$old_fields[$f->id] = $f;
$old_fields[$f->field_key] = $f->id;
unset($f);
}
$form_fields = $old_fields;
unset($old_fields);
} else {
//form does not exist, so create it
if ($form_id = $frm_form->create($form)) {
$imported['imported']['forms']++;
}
}
foreach ($item->field as $field) {
$f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag'))) {
if (count($f['default_value']) === 1) {
$f['default_value'] = '[' . reset($f['default_value']) . ']';
} else {
$f['default_value'] = reset($f['default_value']);
}
}
$f = apply_filters('frm_duplicated_field', $f);
if ($this_form) {
// check for field to edit by field id
if (isset($form_fields[$f['id']])) {
$frm_field->update($f['id'], $f);
$imported['updated']['fields']++;
unset($form_fields[$f['id']]);
//unset old field key
if (isset($form_fields[$f['field_key']])) {
unset($form_fields[$f['field_key']]);
}
} else {
if (isset($form_fields[$f['field_key']])) {
// check for field to edit by field key
unset($f['id']);
$frm_field->update($form_fields[$f['field_key']], $f);
$imported['updated']['fields']++;
unset($form_fields[$form_fields[$f['field_key']]]);
//unset old field id
unset($form_fields[$f['field_key']]);
//unset old field key
} else {
if ($frm_field->create($f)) {
// if no matching field id or key in this form, create the field
$imported['imported']['fields']++;
}
}
}
} else {
if ($frm_field->create($f)) {
$imported['imported']['fields']++;
}
}
unset($field);
}
// Delete any fields attached to this form that were not included in the template
if (isset($form_fields) && !empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
$frm_field->destroy($field->id);
}
unset($field);
}
unset($form_fields);
}
// Update field ids/keys to new ones
do_action('frm_after_duplicate_form', $form_id, $form);
$imported['forms'][(int) $item->id] = $form_id;
unset($form);
unset($item);
}
unset($frm_form);
unset($frm_field);
return $imported;
}
示例5: import_xml_forms
public static function import_xml_forms($forms, $imported)
{
// Keep track of repeating sections that are created
$repeat_fields = array();
foreach ($forms as $item) {
$form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at)));
$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
// if template, allow to edit if form keys match, otherwise, creation date must also match
$edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']);
if (!$form['is_template']) {
$edit_query['created_at'] = $form['created_at'];
}
if (!empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']])) {
// replace the old parent id with the new one
$form['parent_form_id'] = $imported['forms'][$form['parent_form_id']];
}
$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
$this_form = FrmForm::getAll($edit_query, '', 1);
unset($edit_query);
if (!empty($this_form)) {
$old_id = $form_id = $this_form->id;
FrmForm::update($form_id, $form);
$imported['updated']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'updated';
$form_fields = FrmField::get_all_for_form($form_id);
$old_fields = array();
foreach ($form_fields as $f) {
$old_fields[$f->id] = $f;
$old_fields[$f->field_key] = $f->id;
unset($f);
}
$form_fields = $old_fields;
unset($old_fields);
} else {
$old_id = false;
//form does not exist, so create it
$form_id = FrmForm::create($form);
if ($form_id) {
$imported['imported']['forms']++;
// Keep track of whether this specific form was updated or not
$imported['form_status'][$form_id] = 'imported';
}
}
foreach ($item->field as $field) {
$f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options));
if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'hidden', 'password', 'tag', 'image'))) {
if (count($f['default_value']) === 1) {
$f['default_value'] = '[' . reset($f['default_value']) . ']';
} else {
$f['default_value'] = reset($f['default_value']);
}
}
$f = apply_filters('frm_duplicated_field', $f);
if (!empty($this_form)) {
// check for field to edit by field id
if (isset($form_fields[$f['id']])) {
FrmField::update($f['id'], $f);
$imported['updated']['fields']++;
unset($form_fields[$f['id']]);
//unset old field key
if (isset($form_fields[$f['field_key']])) {
unset($form_fields[$f['field_key']]);
}
} else {
if (isset($form_fields[$f['field_key']])) {
// check for field to edit by field key
unset($f['id']);
FrmField::update($form_fields[$f['field_key']], $f);
$imported['updated']['fields']++;
unset($form_fields[$form_fields[$f['field_key']]]);
//unset old field id
unset($form_fields[$f['field_key']]);
//unset old field key
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
// if no matching field id or key in this form, create the field
$imported['imported']['fields']++;
}
}
} else {
$new_id = FrmField::create($f);
if ($new_id == false) {
continue;
}
self::track_repeating_fields($f, $new_id, $repeat_fields);
$imported['imported']['fields']++;
}
unset($field, $new_id);
}
// Delete any fields attached to this form that were not included in the template
if (isset($form_fields) && !empty($form_fields)) {
foreach ($form_fields as $field) {
if (is_object($field)) {
FrmField::destroy($field->id);
}
//.........这里部分代码省略.........
示例6: maybe_create_end_section
/**
* Create end section field if it doesn't exist. This is for migration from < 2.0
* Fix any ordering that may be messed up
*/
public static function maybe_create_end_section(&$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no')
{
if (!$open) {
return;
}
$end_section_values['field_order'] = $field->field_order + 1;
FrmField::create($end_section_values);
if ($move == 'move') {
// bump the order of current field unless we're at the end of the form
FrmField::update($field->id, array('field_order' => $field->field_order + 2));
}
$add_order += 2;
$open = false;
$reset_fields = true;
}
示例7: create_imported_field
/**
* Create an imported field
*
* @since 2.0.25
* @param array $f
* @param array $imported
*/
private static function create_imported_field($f, &$imported)
{
$new_id = FrmField::create($f);
if ($new_id != false) {
$imported['imported']['fields']++;
do_action('frm_after_field_is_imported', $f, $new_id);
}
}
示例8: duplicate_section
public static function duplicate_section($section_field, $form_id)
{
check_ajax_referer('frm_ajax', 'nonce');
global $wpdb;
if (isset($_POST['children'])) {
$children = array_filter((array) $_POST['children'], 'is_numeric');
$fields = FrmField::getAll(array('fi.id' => $children), 'field_order');
} else {
$fields = array();
}
array_unshift($fields, $section_field);
$field_count = FrmDb::get_count($wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array('or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id));
$ended = false;
if (isset($section_field->field_options['repeat']) && $section_field->field_options['repeat']) {
// create the repeatable form
$new_form_id = FrmProField::create_repeat_form(0, array('parent_form_id' => $form_id, 'field_name' => $section_field->name));
} else {
$new_form_id = $form_id;
}
foreach ($fields as $field) {
// keep the current form id or give it the id of the newly created form
$this_form_id = $field->form_id == $form_id ? $form_id : $new_form_id;
$values = array();
FrmFieldsHelper::fill_field($values, $field, $this_form_id);
if (FrmField::is_repeating_field($field)) {
$values['field_options']['form_select'] = $new_form_id;
}
$field_count++;
$values['field_order'] = $field_count;
$field_id = FrmField::create($values);
if (!$field_id) {
continue;
}
if ('end_divider' == $field->type) {
$ended = true;
}
$values['id'] = $this_form_id;
FrmFieldsController::include_single_field($field_id, $values);
}
if (!$ended) {
//make sure the section is ended
self::create_multiple_fields((array) $section_field, $form_id);
}
// Prevent the function in the free version from completing
wp_die();
}
示例9: duplicate
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;
}
示例10: validate
public static function validate($errors, $values)
{
/*
if (isset($values['item_meta'])){
foreach( $values['item_meta'] as $key => $value ) {
$field = FrmField::getOne($key);
if ($field && $field->type == 'hidden' and empty($value))
$errors[] = __( 'Hidden fields must have a value.', 'formidable' );
}
}
*/
// add a user id field if the form requires one
if (isset($values['logged_in']) || isset($values['editable']) || isset($values['single_entry']) && isset($values['options']['single_entry_type']) && $values['options']['single_entry_type'] == 'user' || isset($values['options']['save_draft']) && $values['options']['save_draft'] == 1) {
$form_id = $values['id'];
$user_field = FrmField::get_all_types_in_form($form_id, 'user_id', 1);
if (!$user_field) {
$new_values = FrmFieldsHelper::setup_new_vars('user_id', $form_id);
$new_values['name'] = __('User ID', 'formidable');
FrmField::create($new_values);
}
}
if (isset($values['options']['auto_responder'])) {
if (!isset($values['options']['ar_email_message']) || $values['options']['ar_email_message'] == '') {
$errors[] = __('Please insert a message for your auto responder.', 'formidable');
}
if (isset($values['options']['ar_reply_to']) && !is_email(trim($values['options']['ar_reply_to']))) {
$errors[] = __('That is not a valid reply-to email address for your auto responder.', 'formidable');
}
}
return $errors;
}