• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP form_set_value函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中form_set_value函数的典型用法代码示例。如果您正苦于以下问题:PHP form_set_value函数的具体用法?PHP form_set_value怎么用?PHP form_set_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了form_set_value函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: elementValidate

 /**
  * {@inheritdoc}
  */
 public function elementValidate($element, FormStateInterface $form_state, $form)
 {
     $auto_create = $this->getSelectionHandlerSetting('auto_create');
     // If a value was entered into the autocomplete.
     $value = NULL;
     if (!empty($element['#value'])) {
         // Take "label (entity id)', match the id from parenthesis.
         // @todo: Lookup the entity type's ID data type and use it here.
         // https://drupal.org/node/2107249
         if ($this->isContentReferenced() && preg_match("/.+\\((\\d+)\\)/", $element['#value'], $matches)) {
             $value = $matches[1];
         } elseif (preg_match("/.+\\(([\\w.]+)\\)/", $element['#value'], $matches)) {
             $value = $matches[1];
         }
         if ($value === NULL) {
             // Try to get a match from the input string when the user didn't use the
             // autocomplete but filled in a value manually.
             $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
             $value = $handler->validateAutocompleteInput($element['#value'], $element, $form_state, $form, !$auto_create);
         }
         if (!$value && $auto_create && count($this->getSelectionHandlerSetting('target_bundles')) == 1) {
             // Auto-create item. See
             // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
             $value = array('target_id' => NULL, 'entity' => $this->createNewEntity($element['#value'], $element['#autocreate_uid']), '_weight' => $element['#weight']);
             // Change the element['#parents'], so in form_set_value() we
             // populate the correct key.
             array_pop($element['#parents']);
         }
     }
     form_set_value($element, $value, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:AutocompleteWidget.php


示例2: validateName

 /**
  * Form element validation handler for 'name' in form_test_validate_form().
  */
 public function validateName(&$element, FormStateInterface $form_state)
 {
     $triggered = FALSE;
     if ($form_state->getValue('name') == 'element_validate') {
         // Alter the form element.
         $element['#value'] = '#value changed by #element_validate';
         // Alter the submitted value in $form_state.
         form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
         $triggered = TRUE;
     }
     if ($form_state->getValue('name') == 'element_validate_access') {
         $form_state->set('form_test_name', $form_state->getValue('name'));
         // Alter the form element.
         $element['#access'] = FALSE;
         $triggered = TRUE;
     } elseif ($form_state->has('form_test_name')) {
         // To simplify this test, just take over the element's value into $form_state.
         form_set_value($element, $form_state->get('form_test_name'), $form_state);
         $triggered = TRUE;
     }
     if ($triggered) {
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
         // Trigger a form validation error to see our changes.
         $form_state->setErrorByName('');
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:30,代码来源:Callbacks.php


示例3: validateName

 /**
  * Form element validation handler for 'name' in form_test_validate_form().
  */
 public function validateName(&$element, &$form_state)
 {
     $triggered = FALSE;
     if ($form_state['values']['name'] == 'element_validate') {
         // Alter the form element.
         $element['#value'] = '#value changed by #element_validate';
         // Alter the submitted value in $form_state.
         form_set_value($element, 'value changed by form_set_value() in #element_validate', $form_state);
         $triggered = TRUE;
     }
     if ($form_state['values']['name'] == 'element_validate_access') {
         $form_state['storage']['form_test_name'] = $form_state['values']['name'];
         // Alter the form element.
         $element['#access'] = FALSE;
         $triggered = TRUE;
     } elseif (!empty($form_state['storage']['form_test_name'])) {
         // To simplify this test, just take over the element's value into $form_state.
         form_set_value($element, $form_state['storage']['form_test_name'], $form_state);
         $triggered = TRUE;
     }
     if ($triggered) {
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state['values']['name'])));
         // Trigger a form validation error to see our changes.
         form_set_error('', $form_state);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:Callbacks.php


示例4: da_vinci_form_system_theme_settings_submit

/**
 * Form submit for da_vinci_form_system_theme_settings_alter().
 */
function da_vinci_form_system_theme_settings_submit($form, &$form_state)
{
    $exclude_css = array_filter(array_map('trim', explode("\n", $form_state['values']['css_exclude'])));
    $exclude_js = array_filter(array_map('trim', explode("\n", $form_state['values']['js_exclude'])));
    form_set_value(array('#parents' => array('css_exclude')), $exclude_css, $form_state);
    form_set_value(array('#parents' => array('js_exclude')), $exclude_js, $form_state);
}
开发者ID:nikasha,项目名称:refugiolahiguera,代码行数:10,代码来源:theme-settings.php


示例5: entityreference_prepopulate_providers_validate

/**
 * Element validate; Set the value of the providers.
 */
function entityreference_prepopulate_providers_validate($element, &$form_state)
{
    $value = $form_state['values']['instance']['settings']['behaviors']['prepopulate']['providers']['enabled'];
    // Sort the value by the weight.
    uasort($value, 'drupal_sort_weight');
    form_set_value($element, $value, $form_state);
}
开发者ID:drupdateio,项目名称:teca,代码行数:10,代码来源:EntityReferencePrepopulateInstanceBehavior.class.php


示例6: multipleValidate

 /**
  * Element validation helper.
  */
 public static function multipleValidate($element, FormStateInterface $form_state)
 {
     $values = array_map('trim', explode(',', $element['#value']));
     $items = array();
     foreach ($values as $value) {
         $items[] = array('value' => $value);
     }
     form_set_value($element, $items, $form_state);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:12,代码来源:TestFieldWidgetMultiple.php


示例7: drupalexp_form_system_theme_settings_validate

function drupalexp_form_system_theme_settings_validate(&$form, &$form_state)
{
    $drupalexp_layouts = '';
    $i = 0;
    while (isset($form_state['input']['dexp_layout_' . $i])) {
        $drupalexp_layouts .= $form_state['input']['dexp_layout_' . $i];
        $i++;
    }
    form_set_value($form['layout_settings']['drupalexp_layouts'], $drupalexp_layouts, $form_state);
}
开发者ID:nevetS,项目名称:flame,代码行数:10,代码来源:theme-settings.php


示例8: edit_form_validate

 /**
  * @todo
  */
 function edit_form_validate(&$form, &$form_state)
 {
     parent::edit_form_validate($form, $form_state);
     $values = $form_state['values'];
     if ($values['parent'] == '_none') {
         form_set_value(array('#parents' => array('parent')), '', $form_state);
     } else {
         form_set_value(array('#parents' => array('mode')), DELTA_PRESERVE, $form_state);
     }
 }
开发者ID:ehazell,项目名称:AWBA,代码行数:13,代码来源:delta_export_ui.class.php


示例9: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     if ($form_state['values']['name'] == 'validate') {
         // Alter the form element.
         $form['name']['#value'] = '#value changed by #validate';
         // Alter the submitted value in $form_state.
         form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state);
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name'])));
         // Trigger a form validation error to see our changes.
         form_set_error('', $form_state);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:16,代码来源:FormTestValidateForm.php


示例10: alpha_theme_settings_validate_primary

/**
 * Form element validation handler for validating the primary region setting for zones.
 */
function alpha_theme_settings_validate_primary(&$element, &$form_state)
{
    if ($element['#value'] != '_none') {
        $values = $form_state['values'];
        if ($values['alpha_region_' . $element['#value'] . '_zone'] != $element['#zone']) {
            form_set_value($element, NULL, $form_state);
        } else {
            $sum = 0;
            foreach ($form_state['regions'] as $region => $item) {
                if ($values['alpha_region_' . $region . '_zone'] == $element['#zone']) {
                    $sum += $values['alpha_region_' . $region . '_columns'];
                    $sum += $values['alpha_region_' . $region . '_prefix'];
                    $sum += $values['alpha_region_' . $region . '_suffix'];
                }
            }
            if ($sum > $values['alpha_zone_' . $element['#zone'] . '_columns']) {
                form_error($element, t('You have specified the %region region as the primary region for the %zone zone but the summed region width is greater than the number of available columns for that zone.', array('%region' => $form_state['regions'][$element['#value']]['name'], '%zone' => $form_state['zones'][$element['#zone']]['name'])));
            }
        }
    }
}
开发者ID:imshuffling,项目名称:david7,代码行数:24,代码来源:theme-settings.php


示例11: elementValidate

 /**
  * {@inheritdoc}
  */
 public function elementValidate($element, &$form_state, $form)
 {
     $value = array();
     // If a value was entered into the autocomplete.
     $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
     $bundles = entity_get_bundles($this->getFieldSetting('target_type'));
     $auto_create = $this->getSelectionHandlerSetting('auto_create');
     if (!empty($element['#value'])) {
         $value = array();
         foreach (Tags::explode($element['#value']) as $input) {
             $match = FALSE;
             // Take "label (entity id)', match the ID from parenthesis when it's a
             // number.
             if (preg_match("/.+\\((\\d+)\\)/", $input, $matches)) {
                 $match = $matches[1];
             } elseif (preg_match("/.+\\(([\\w.]+)\\)/", $input, $matches)) {
                 $match = $matches[1];
             } else {
                 // Try to get a match from the input string when the user didn't use
                 // the autocomplete but filled in a value manually.
                 $match = $handler->validateAutocompleteInput($input, $element, $form_state, $form, !$auto_create);
             }
             if ($match) {
                 $value[] = array('target_id' => $match);
             } elseif ($auto_create && (count($this->getSelectionHandlerSetting('target_bundles')) == 1 || count($bundles) == 1)) {
                 // Auto-create item. See
                 // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
                 $value[] = array('target_id' => NULL, 'entity' => $this->createNewEntity($input, $element['#autocreate_uid']));
             }
         }
     }
     // Change the element['#parents'], so in form_set_value() we
     // populate the correct key.
     array_pop($element['#parents']);
     form_set_value($element, $value, $form_state);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:39,代码来源:AutocompleteTagsWidget.php


示例12: validateElement

 /**
  * Form validation handler for widget elements.
  *
  * @param array $element
  *   The form element.
  * @param array $form_state
  *   The form state.
  */
 public static function validateElement(array $element, array &$form_state)
 {
     if ($element['#required'] && $element['#value'] == '_none') {
         \Drupal::formBuilder()->setError($element, $form_state, t('!name field is required.', array('!name' => $element['#title'])));
     }
     // Massage submitted form values.
     // Drupal\Core\Field\WidgetBase::submit() expects values as
     // an array of values keyed by delta first, then by column, while our
     // widgets return the opposite.
     if (is_array($element['#value'])) {
         $values = array_values($element['#value']);
     } else {
         $values = array($element['#value']);
     }
     // Filter out the 'none' option. Use a strict comparison, because
     // 0 == 'any string'.
     $index = array_search('_none', $values, TRUE);
     if ($index !== FALSE) {
         unset($values[$index]);
     }
     // Transpose selections from field => delta to delta => field.
     $items = array();
     foreach ($values as $value) {
         $items[] = array($element['#key_column'] => $value);
     }
     form_set_value($element, $items, $form_state);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:35,代码来源:OptionsWidgetBase.php


示例13: devis_user_profile_form_validate

function devis_user_profile_form_validate($form, &$form_state)
{
    // This is a check in case the javascript is disabled for whatever reason.
    if (isset($form['profile_budget_profile']['field_active_regions_belgium'])) {
        $belgium = FALSE;
        $count = 0;
        // Check if Belgium is selected among the choices.
        $lang = $form['profile_budget_profile']['field_active_regions_belgium']['#language'];
        foreach ($form_state['values']['profile_budget_profile']['field_active_regions_belgium'][$lang] as $k => $val) {
            $count++;
            if ($val['value'] == 'BEL') {
                $belgium = TRUE;
            }
        }
        // If Belgium is selected, then asign only Belgium as the value.
        if ($belgium && $count > 1) {
            $new_value = array($lang => array(0 => array('value' => 'BEL')));
            $value['#parents'] = array('profile_budget_profile', 'field_active_regions_belgium');
            form_set_value($value, $new_value, $form_state);
        }
    }
    if (isset($form_state['values']['mail'])) {
        // E-mail check for duplicate user.
        $user_check = user_load_by_mail($form_state['values']['mail']);
        if ($user_check && $form['#user']->uid != $user_check->uid) {
            $site_name = variable_get('site_name', '3devis.be');
            form_set_error('mail', t('The specified email is already registered in !site_name.', array('!site_name' => $site_name)));
        }
        // E-mail check.
        if (!valid_email_address($form_state['values']['mail'])) {
            form_set_error('mail', t('The specified email is not a valid email.'));
        }
    }
    devis_field_phone_belgium_validate($form, $form_state);
    devis_field_tva_validate($form, $form_state);
}
开发者ID:daniosoriov,项目名称:devis,代码行数:36,代码来源:template.php


示例14: validate

 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     form_set_value($form['id'], $this->targetEntityTypeId . '.' . $form_state['values']['id'], $form_state);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:8,代码来源:EntityDisplayModeAddForm.php


示例15: _agency_1_theme_settings_map

function _agency_1_theme_settings_map($form, &$form_state)
{
    $validators = array('file_validate_is_image' => array());
    $file = file_save_upload('background_file', $validators);
    $map_file = file_save_upload('footer_contact_us_map_image', $validators);
    //Map image
    if (isset($map_file)) {
        // File upload was attempted.
        if ($map_file) {
            // Move the file, into the Drupal file system
            if ($map_filename = file_unmanaged_copy($map_file->uri, 'public://background_images', FILE_EXISTS_RENAME)) {
                //resize, if necessary
                $map_resized = image_load($map_file->uri);
                list($map_width, $map_height) = getimagesize($map_file->uri);
                if ($map_width > 150 || $map_height > 150) {
                    if ($map_width / $map_height >= 1) {
                        image_scale($map_resized, 150);
                    } else {
                        image_scale($map_resized, null, 150);
                    }
                    image_save($map_resized, $map_filename, FILE_EXISTS_RENAME);
                    $map_resized->status = FILE_STATUS_PERMANENT;
                    drupal_set_message('Uploaded image was greater than 150px.  Image has been resized.');
                }
                //end resize
                unset($form['footer_contact_us']['settings']['footer_contact_us_map_path']);
                $form['footer_contact_us']['settings']['footer_contact_us_map_path']['#value'] = $map_filename;
                $form['footer_contact_us_map_path']['#parents'] = array('footer_contact_us_map_path');
                form_set_value($form['footer_contact_us_map_path'], file_create_url($map_filename), $form_state);
                watchdog('Theme Settings', 'New Footer Map Image uploaded: ' . file_create_url($map_filename));
                drupal_set_message('Map Image uploaded.  URL: ' . file_create_url($map_filename));
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            // File upload failed.
            form_set_error('background_file', t('The image could not be uploaded.'));
        }
    }
}
开发者ID:ehazell,项目名称:AZDWR,代码行数:40,代码来源:theme-settings.php


示例16: fillValues

 /**
  * Fill value in any field of the form. It first checks if corresponding key
  * exists in the form array. If yes, it finds out its #tree value and that of
  * its parents and sets form_state appropriately. If it doesn't find the key
  * in the form array, then it sets the values in form_state at the top level.
  *
  * @param string|array $field_name
  *   Field name if it is present at top-level form element. If it is not at
  *   the top-level form element, then provide an array.
  * @param string|int|array $values
  *   Value that needs to be filled.
  *
  * @return Response
  *   Response object.
  */
 public function fillValues($field_name, $values)
 {
     if (is_string($field_name)) {
         $field_name = array($field_name);
     }
     $response = $this->getTreeKeys($field_name);
     if (!$response->getSuccess()) {
         $element['#parents'] = $field_name;
     } else {
         $element['#parents'] = $response->getVar();
     }
     form_set_value($element, $values, $this->form_state);
     return new Response(TRUE, $values, "");
 }
开发者ID:vishalred,项目名称:redtest-core-pw,代码行数:29,代码来源:Form.php


示例17: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Check for empty front page path.
     if ($form_state->isValueEmpty('site_frontpage')) {
         // Set to default "user".
         form_set_value($form['front_page']['site_frontpage'], 'user', $form_state);
     } else {
         // Get the normal path of the front page.
         form_set_value($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')), $form_state);
     }
     // Validate front page path.
     if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
         $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage'))));
     }
     // Get the normal paths of both error pages.
     if (!$form_state->isValueEmpty('site_403')) {
         form_set_value($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403')), $form_state);
     }
     if (!$form_state->isValueEmpty('site_404')) {
         form_set_value($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')), $form_state);
     }
     // Validate 403 error path.
     if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
         $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403'))));
     }
     // Validate 404 error path.
     if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) {
         $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404'))));
     }
     parent::validateForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:SiteInformationForm.php


示例18: edit_form_validate

 function edit_form_validate(&$form, &$form_state)
 {
     $export_key = $this->plugin['export']['key'];
     // When adding a machine name, the entity/bundle are left off so the user
     // does not have to deal with it. We put it back here behind the scenes.
     $name = $form_state['values'][$export_key];
     form_set_value($form['info'][$export_key], implode(':', array($this->entity_handler->entity_type, $this->entity_bundle, $name)), $form_state);
 }
开发者ID:rexxllabore,项目名称:d7-commons-sanbox,代码行数:8,代码来源:panelizer_defaults_ui.class.php


示例19: _install_settings_form_validate

/**
 * Helper function for install_settings_validate.
 */
function _install_settings_form_validate($database, $settings_file, &$form_state, $form = NULL)
{
    global $databases;
    // Verify the table prefix
    if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['dprefix'])) {
        form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error');
    }
    if (!empty($database['port']) && !is_numeric($database['port'])) {
        form_set_error('db_port', st('Database port must be a number.'));
    }
    // Check database type
    $database_types = drupal_detect_database_types();
    $driver = $database['driver'];
    if (!isset($database_types[$driver])) {
        form_set_error('driver', st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%driver' => $database['driver'])));
    } else {
        if (isset($form)) {
            form_set_value($form['_database'], $database, $form_state);
        }
        $class = "DatabaseInstaller_{$driver}";
        $test = new $class();
        $databases = array('default' => array('default' => $database));
        $return = $test->test();
        if (!$return || $test->error) {
            if (!empty($test->success)) {
                form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($test->success, ', '))));
            } else {
                form_set_error('driver', '');
            }
        }
    }
}
开发者ID:schuyler1d,项目名称:drupal,代码行数:35,代码来源:install.php


示例20: install_settings_form_validate

/**
 * Form API validate for install_settings form.
 */
function install_settings_form_validate($form, &$form_state)
{
    form_set_value($form['_database'], $form_state['values'], $form_state);
    $errors = install_database_errors($form_state['values'], $form_state['values']['settings_file']);
    foreach ($errors as $name => $message) {
        form_set_error($name, $message);
    }
}
开发者ID:blipp,项目名称:drupal,代码行数:11,代码来源:install.php



注:本文中的form_set_value函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP form_start函数代码示例发布时间:2022-05-15
下一篇:
PHP form_set_error函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap