本文整理汇总了PHP中FrmField类的典型用法代码示例。如果您正苦于以下问题:PHP FrmField类的具体用法?PHP FrmField怎么用?PHP FrmField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FrmField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
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;
}
示例2: _check_imported_repeating_fields
public function _check_imported_repeating_fields($f, &$fields_tested)
{
if (!FrmField::is_repeating_field($f)) {
return;
}
$fields_tested++;
self::_check_form_select($f, 'rep_sec_form');
}
示例3: get_all_field_types_for_form_key
function get_all_field_types_for_form_key($form_key, $expected_field_num, $type)
{
$form_id = $this->factory->form->get_id_by_key($form_key);
$fields = FrmField::get_all_types_in_form($form_id, $type);
$actual_field_num = count($fields);
$this->assertEquals($actual_field_num, $expected_field_num, $actual_field_num . ' ' . $type . ' fields were retrieved for ' . $form_key . ' form, but ' . $expected_field_num . ' were expected. This could mean that certain fields were not imported correctly.');
return $fields;
}
示例4: test_getAll
/**
* @covers FrmField::getAll
*/
function test_getAll()
{
$form_id = $this->factory->form->get_id_by_key($this->contact_form_key);
$fields = FrmField::getAll(array('fi.form_id' => (int) $form_id));
$this->assertNotEmpty($fields);
$this->assertTrue(count($fields) >= 7);
foreach ($fields as $field) {
}
}
示例5: get_all_fields_for_form_key
function get_all_fields_for_form_key($form_key)
{
$field_totals = array($this->all_fields_form_key => 44, $this->create_post_form_key => 10, $this->contact_form_key => 8, $this->repeat_sec_form_key => 3);
$expected_field_num = isset($field_totals[$form_key]) ? $field_totals[$form_key] : 0;
$form_id = $this->factory->form->get_id_by_key($form_key);
$fields = FrmField::get_all_for_form($form_id, '', 'include');
$actual_field_num = count($fields);
$this->assertEquals($actual_field_num, $expected_field_num, $actual_field_num . ' fields were retrieved for ' . $form_key . ' form, but ' . $expected_field_num . ' were expected. This could mean that certain fields were not imported correctly.');
return $fields;
}
示例6: _get_dynamic_entry_ids
function _get_dynamic_entry_ids($form_key, $where_field_key, $args)
{
// Get where_field
$where_field = FrmField::getOne($where_field_key);
// Get all entry IDs for form
$form_id = $this->factory->form->get_id_by_key($form_key);
$entry_ids = FrmEntry::getAll(array('it.form_id' => $form_id), '', '', false, false);
// Prepare the args
self::_do_prepare_where_args($args, $where_field, $entry_ids);
// Set new where_val
self::_do_prepare_dfe_text($args, $where_field);
return $args['where_val'];
}
示例7: wpfg_lookup_formidable
function wpfg_lookup_formidable($form_id)
{
if (!class_exists('FrmField')) {
return false;
}
$form = FrmField::get_all_for_form($form_id);
if (is_array($form)) {
$form = reset($form);
}
if (isset($form->form_name) && $form->form_name) {
return $form->form_name;
}
return false;
}
示例8: _set_up_field_object
function _set_up_field_object($test, &$expected_cats, $key)
{
// Parent categories
$args = array('hide_empty' => false, 'taxonomy' => 'category', 'parent' => 0);
$parent_cats = get_categories($args);
// Get the correct parent ID(s) for the current test
$parent_cat_id = self::_get_parent_cat_id($test, $parent_cats, $expected_cats);
$this->assertNotFalse($parent_cat_id, 'Check if there are at least two parent categories with children and two with no children. Needed for the ' . $test . ' test.');
// Child field
$field_id = $this->factory->field->get_id_by_key('child-dynamic-taxonomy');
$field = FrmField::getOne($field_id);
$field->field_options['hide_opt'][$key] = $parent_cat_id;
return $field;
}
示例9: _check_updated_values
function _check_updated_values($form_id)
{
$fields = FrmField::get_all_for_form($form_id);
// Compare to posted values
foreach ($fields as $field) {
// Check default value
$posted_val = $_POST['item_meta'][$field->id];
$actual_val = $field->default_value;
$this->assertEquals($posted_val, $actual_val, 'The default value was not updated correctly for field ' . $field->field_key . '.');
// Check calculations
$posted_val = $_POST['field_options']['use_calc_' . $field->id];
$actual_val = $field->field_options['use_calc'];
$this->assertEquals($posted_val, $actual_val, 'The calculation was not updated correctly for field ' . $field->field_key . '.');
}
}
示例10: _check_if_form_select_updates
function _check_if_form_select_updates($old_form_id, $new_form_id)
{
// Get all repeating sections in both forms
$old_repeating_sections = FrmField::get_all_types_in_form($old_form_id, 'divider');
$new_repeating_sections = FrmField::get_all_types_in_form($new_form_id, 'divider');
if (!$old_repeating_sections) {
return;
}
foreach ($old_repeating_sections as $key => $section) {
if (!FrmField::is_repeating_field($section)) {
continue;
}
$old_form_select = $section->field_options['form_select'];
$new_form_select = $new_repeating_sections[$key]->field_options['form_select'];
$this->assertNotEquals($old_form_select, $new_form_select, 'A form was duplicated, but the form_select was not updated for the repeating section :/');
}
}
示例11: test_stats_shortcode
function test_stats_shortcode()
{
$forms_to_test = array($this->all_fields_form_key => array('493ito', 'p3eiuk', 'uc580i', '4t3qo4', '54tffk', 'endbcl', 'repeating-text'));
foreach ($forms_to_test as $form_key => $fields) {
foreach ($fields as $field_key) {
$field = FrmField::getOne($field_key);
$value = do_shortcode('[frm-stats id=' . $field->id . ' type=count]');
$this->assertNotEmpty($value, 'Field ' . $field_key . ' has no saved values');
if (!empty($field->options)) {
$first_option = array_filter($field->options);
$first_option = reset($first_option);
$filter_by_value = do_shortcode('[frm-stats id=' . $field->id . ' type=count value="' . $first_option . '"]');
$this->assertNotEmpty($filter_by_value, 'Field ' . $field_key . ' has no saved values for "' . $first_option . '"');
}
}
}
}
示例12: test_get_all_for_form
/**
* @covers FrmField::get_all_for_form
*/
function test_get_all_for_form()
{
$forms = array('basic_test' => array('form_key' => $this->contact_form_key, 'count' => 8), 'repeat' => array('form_key' => $this->all_fields_form_key, 'count' => 33 + 3), 'no_repeat_or_embed' => array('form_key' => $this->all_fields_form_key, 'count' => 33), 'repeat_and_embed' => array('form_key' => $this->all_fields_form_key, 'count' => 33 + 3 + 8));
foreach ($forms as $test => $args) {
$form_id = FrmForm::getIdByKey($args['form_key']);
if ($test == 'no_repeat_or_embed') {
$fields = FrmField::get_all_for_form($form_id, '', 'exclude', 'exclude');
} else {
if ($test == 'repeat_and_embed') {
$fields = FrmField::get_all_for_form($form_id, '', 'include', 'include');
} else {
$fields = FrmField::get_all_for_form($form_id);
}
}
$this->assertNotEmpty($fields);
$this->assertEquals($args['count'], count($fields), 'An incorrect number of fields are retrieved with FrmField::get_all_for_form.');
}
}
示例13: test_create
/**
* @covers FrmFieldsController::create
*/
public function test_create()
{
wp_set_current_user($this->user_id);
$this->assertTrue(is_numeric($this->form_id));
$_POST = array('action' => 'frm_insert_field', 'nonce' => wp_create_nonce('frm_ajax'), 'form_id' => $this->form_id, 'field' => 'text');
try {
$this->_handleAjax('frm_insert_field');
} catch (WPAjaxDieContinueException $e) {
unset($e);
}
global $wpdb;
$this->field_id = $wpdb->insert_id;
$this->assertTrue(is_numeric($this->field_id));
$this->assertNotEmpty($this->field_id);
// make sure the field exists
$field = FrmField::getOne($this->field_id);
$this->assertTrue(is_object($field));
}
示例14: update_entry_metas
public static function update_entry_metas($entry_id, $values)
{
global $wpdb;
$prev_values = FrmDb::get_col($wpdb->prefix . 'frm_item_metas', array('item_id' => $entry_id, 'field_id !' => 0), 'field_id');
foreach ($values as $field_id => $meta_value) {
$field = false;
if (!empty($field_id)) {
$field = FrmField::getOne($field_id);
}
// set the value for the file upload field and add new tags (in Pro version)
$meta_value = apply_filters('frm_prepare_data_before_db', $meta_value, $field_id, $entry_id, compact('field'));
if ($prev_values && in_array($field_id, $prev_values)) {
if (is_array($meta_value) && empty($meta_value) || !is_array($meta_value) && trim($meta_value) == '') {
// remove blank fields
unset($values[$field_id]);
} else {
// if value exists, then update it
self::update_entry_meta($entry_id, $field_id, '', $meta_value);
}
} else {
// if value does not exist, then create it
self::add_entry_meta($entry_id, $field_id, '', $meta_value);
}
}
if (empty($prev_values)) {
return;
}
$prev_values = array_diff($prev_values, array_keys($values));
if (empty($prev_values)) {
return;
}
// prepare the query
$where = array('item_id' => $entry_id, 'field_id' => $prev_values);
FrmDb::get_where_clause_and_values($where);
// Delete any leftovers
$wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values']));
self::clear_cache();
}
示例15: migrate_to_6
private function migrate_to_6()
{
global $wpdb;
$no_save = array_merge(FrmField::no_save_fields(), array('form', 'hidden', 'user_id'));
$fields = FrmDb::get_results($this->fields, array('type NOT' => $no_save), 'id, field_options');
$default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
<label class="frm_pos_[label_position]">[field_name]
<span class="frm_required">[required_label]</span>
</label>
[input]
[if description]<div class="frm_description">[description]</div>[/if description]
</div>
DEFAULT_HTML;
$old_default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
<label class="frm_pos_[label_position]">[field_name]
<span class="frm_required">[required_label]</span>
</label>
[input]
[if description]<p class="frm_description">[description]</p>[/if description]
</div>
DEFAULT_HTML;
$new_default_html = FrmFieldsHelper::get_default_html('text');
foreach ($fields as $field) {
$field->field_options = maybe_unserialize($field->field_options);
if (!FrmField::is_option_empty($field, 'custom_html') || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html) {
$field->field_options['custom_html'] = $new_default_html;
$wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array('id' => $field->id));
}
unset($field);
}
unset($default_html, $old_default_html, $fields);
}