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

PHP form_get_errors函数代码示例

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

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



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

示例1: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $response = new AjaxResponse();
     if (form_get_errors($form_state)) {
         unset($form['#prefix'], $form['#suffix']);
         $status_messages = array('#theme' => 'status_messages');
         $output = drupal_render($form);
         $output = '<div>' . drupal_render($status_messages) . $output . '</div>';
         $response->addCommand(new HtmlCommand('#editor-link-dialog-form', $output));
     } else {
         $response->addCommand(new EditorDialogSave($form_state['values']));
         $response->addCommand(new CloseModalDialogCommand());
     }
     return $response;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:18,代码来源:EditorLinkDialog.php


示例2: testConfigForm

 /**
  * Submit the system_config_form ensure the configuration has expected values.
  */
 public function testConfigForm()
 {
     // Programmatically submit the given values.
     foreach ($this->values as $form_key => $data) {
         $values[$form_key] = $data['#value'];
     }
     $form_state = array('values' => $values);
     drupal_form_submit($this->form, $form_state);
     // Check that the form returns an error when expected, and vice versa.
     $errors = form_get_errors($form_state);
     $valid_form = empty($errors);
     $args = array('%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors));
     $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args));
     foreach ($this->values as $data) {
         $this->assertEqual($data['#value'], \Drupal::config($data['#config_name'])->get($data['#config_key']));
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:20,代码来源:SystemConfigFormTestBase.php


示例3: update

 /**
  * 
  * Do the actual update - passes the update to the plugin's process functions
  */
 function update()
 {
     if (function_exists($this->plugin['process'])) {
         $this->plugin['process']($this);
     }
     // Are there any form errors?
     if ($errors = form_get_errors()) {
         foreach ($errors as $error) {
             // Form errors will apply for all entities
             foreach ($this->entities as $entity) {
                 list($id) = entity_extract_ids($this->entity_type, $entity);
                 $this->set_error($id, $error);
             }
         }
     }
     return $this->get_result();
 }
开发者ID:acquiau-2015,项目名称:acquiau-site,代码行数:21,代码来源:handler.class.php


示例4: submitForm

 /**
  * Helper function used to programmatically submit the form defined in
  * form_test.module with the given values.
  *
  * @param $values
  *   An array of field values to be submitted.
  * @param $valid_input
  *   A boolean indicating whether or not the form submission is expected to
  *   be valid.
  */
 private function submitForm($values, $valid_input)
 {
     // Programmatically submit the given values.
     $form_state = new FormState(array('values' => $values));
     \Drupal::formBuilder()->submitForm('\\Drupal\\form_test\\Form\\FormTestProgrammaticForm', $form_state);
     // Check that the form returns an error when expected, and vice versa.
     $errors = form_get_errors($form_state);
     $valid_form = empty($errors);
     $args = array('%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors));
     $this->assertTrue($valid_input == $valid_form, format_string('Input values: %values<br />Validation handler errors: %errors', $args));
     // We check submitted values only if we have a valid input.
     if ($valid_input) {
         // By fetching the values from $form_state['storage'] we ensure that the
         // submission handler was properly executed.
         $stored_values = $form_state['storage']['programmatic_form_submit'];
         foreach ($values as $key => $value) {
             $this->assertEqual($stored_values[$key], $value, format_string('Submission handler correctly executed: %stored_key is %stored_value', array('%stored_key' => $key, '%stored_value' => print_r($value, TRUE))));
         }
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:30,代码来源:ProgrammaticTest.php


示例5: checkUserNameEmailExists

 /**
  * Check if username and email exists in the drupal db
  *
  * @params $params    array   array of name and mail values
  * @params $errors    array   array of errors
  * @params $emailName string  field label for the 'email'
  *
  * @return void
  */
 static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email')
 {
     $config = CRM_Core_Config::singleton();
     $dao = new CRM_Core_DAO();
     $name = $dao->escape(CRM_Utils_Array::value('name', $params));
     $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
     $errors = form_get_errors();
     if ($errors) {
         // unset drupal messages to avoid twice display of errors
         unset($_SESSION['messages']);
     }
     if (!empty($params['name'])) {
         if ($nameError = user_validate_name($params['name'])) {
             $errors['cms_name'] = $nameError;
         } else {
             $uid = db_query("SELECT uid FROM {users} WHERE name = :name", array(':name' => $params['name']))->fetchField();
             if ((bool) $uid) {
                 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $params['name']));
             }
         }
     }
     if (!empty($params['mail'])) {
         if ($emailError = user_validate_mail($params['mail'])) {
             $errors[$emailName] = $emailError;
         } else {
             $uid = db_query("SELECT uid FROM {users} WHERE mail = :mail", array(':mail' => $params['mail']))->fetchField();
             if ((bool) $uid) {
                 $resetUrl = $config->userFrameworkBaseURL . 'user/password';
                 $errors[$emailName] = ts('The email address %1 is already registered. <a href="%2">Have you forgotten your password?</a>', array(1 => $params['mail'], 2 => $resetUrl));
             }
         }
     }
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:42,代码来源:Drupal.php


示例6: ctools_export_ui_edit_item_wizard_form_validate

/**
 * Validate handler for ctools_export_ui_edit_item_wizard_form.
 */
function ctools_export_ui_edit_item_wizard_form_validate(&$form, &$form_state)
{
    $method = 'edit_form_' . $form_state['step'] . '_validate';
    if (!method_exists($form_state['object'], $method)) {
        $method = 'edit_form_validate';
    }
    $form_state['object']->{$method}($form, $form_state);
    // Additionally, if there were no errors from that, and we're finishing,
    // perform a final validate to make sure everything is ok.
    if (isset($form_state['clicked_button']['#wizard type']) && $form_state['clicked_button']['#wizard type'] == 'finish' && !form_get_errors()) {
        $form_state['object']->edit_finish_validate($form, $form_state);
    }
}
开发者ID:kennygrage,项目名称:dynastyDish,代码行数:16,代码来源:ctools_export_ui.class.php


示例7: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $form_state['handler']->validateOptionsForm($form['options'], $form_state);
     if (form_get_errors($form_state)) {
         $form_state['rerender'] = TRUE;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:10,代码来源:ConfigHandler.php


示例8: asf_ajax_login_callback

function asf_ajax_login_callback($form, &$form_state)
{
    // if errors, return the form
    if (form_get_errors()) {
        $msg = 'Sorry, unrecognized username or password.';
        for ($i = 0; $i < count($_SESSION['messages']['error']); $i++) {
            if (strpos($_SESSION['messages']['error'][$i], $msg) !== false) {
                $_SESSION['messages']['error'][$i] = $msg;
                break;
            }
        }
        $form_state['rebuild'] = TRUE;
        return $form;
    }
    // this performs the actual login
    user_login_submit($form, $form_state);
    // this performs a redirection
    $path = $form_state["redirect"] . "/subscriptions";
    ctools_include('ajax');
    ctools_add_js('ajax-responder');
    $commands[] = ctools_ajax_command_redirect($path);
    print ajax_render($commands);
    exit;
}
开发者ID:petergiesin,项目名称:asfitness,代码行数:24,代码来源:template.php


示例9: tfd_form_get_errors

function tfd_form_get_errors()
{
    $errors = form_get_errors();
    if (!empty($errors)) {
        $newErrors = array();
        foreach ($errors as $key => $error) {
            $newKey = str_replace('submitted][', 'submitted[', $key);
            if ($newKey !== $key) {
                $newKey = $newKey . ']';
            }
            $newErrors[$newKey] = $error;
        }
        $errors = $newErrors;
    }
    return $errors;
}
开发者ID:sulav,项目名称:TFD7,代码行数:16,代码来源:Extension.php


示例10: submitConfigurationForm

 /**
  * {@inheritdoc}
  *
  * Most block plugins should not override this method. To add submission
  * handling for a specific block type, override BlockBase::blockSubmit().
  *
  * @see \Drupal\block\BlockBase::blockSubmit()
  */
 public function submitConfigurationForm(array &$form, array &$form_state)
 {
     // Process the block's submission handling if no errors occurred only.
     if (!form_get_errors($form_state)) {
         $this->configuration['label'] = $form_state['values']['label'];
         $this->configuration['label_display'] = $form_state['values']['label_display'];
         $this->configuration['provider'] = $form_state['values']['provider'];
         $this->configuration['cache'] = $form_state['values']['cache'];
         foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
             // Allow the condition to submit the form.
             $condition_values = array('values' => &$form_state['values']['visibility'][$condition_id]);
             $condition->submitConfigurationForm($form, $condition_values);
         }
         $this->blockSubmit($form, $form_state);
     }
 }
开发者ID:shumer,项目名称:blog,代码行数:24,代码来源:BlockBase.php


示例11: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $response = new AjaxResponse();
     // Convert any uploaded files from the FID values to data-editor-file-uuid
     // attributes.
     if (!empty($form_state['values']['fid'][0])) {
         $file = file_load($form_state['values']['fid'][0]);
         $file_url = file_create_url($file->getFileUri());
         // Transform absolute image URLs to relative image URLs: prevent problems
         // on multisite set-ups and prevent mixed content errors.
         $file_url = file_url_transform_relative($file_url);
         $form_state['values']['attributes']['src'] = $file_url;
         $form_state['values']['attributes']['data-editor-file-uuid'] = $file->uuid();
     }
     if (form_get_errors($form_state)) {
         unset($form['#prefix'], $form['#suffix']);
         $status_messages = array('#theme' => 'status_messages');
         $output = drupal_render($form);
         $output = '<div>' . drupal_render($status_messages) . $output . '</div>';
         $response->addCommand(new HtmlCommand('#editor-image-dialog-form', $output));
     } else {
         $response->addCommand(new EditorDialogSave($form_state['values']));
         $response->addCommand(new CloseModalDialogCommand());
     }
     return $response;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:29,代码来源:EditorImageDialog.php


示例12: checkUserNameEmailExists

 /**
  * Check if username and email exists in the drupal db.
  *
  * @param array $params
  *   Array of name and mail values.
  * @param array $errors
  *   Array of errors.
  * @param string $emailName
  *   Field label for the 'email'.
  */
 public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email')
 {
     $config = CRM_Core_Config::singleton();
     $dao = new CRM_Core_DAO();
     $name = $dao->escape(CRM_Utils_Array::value('name', $params));
     $email = $dao->escape(CRM_Utils_Array::value('mail', $params));
     _user_edit_validate(NULL, $params);
     $errors = form_get_errors();
     if ($errors) {
         if (!empty($errors['name'])) {
             $errors['cms_name'] = $errors['name'];
         }
         if (!empty($errors['mail'])) {
             $errors[$emailName] = $errors['mail'];
         }
         // also unset drupal messages to avoid twice display of errors
         unset($_SESSION['messages']);
     }
     // Do the name check manually.
     $nameError = user_validate_name($params['name']);
     if ($nameError) {
         $errors['cms_name'] = $nameError;
     }
     $sql = "\n      SELECT name, mail\n      FROM {users}\n      WHERE (LOWER(name) = LOWER('{$name}')) OR (LOWER(mail) = LOWER('{$email}'))\n    ";
     $result = db_query($sql);
     $row = db_fetch_array($result);
     if (!$row) {
         return;
     }
     $user = NULL;
     if (!empty($row)) {
         $dbName = CRM_Utils_Array::value('name', $row);
         $dbEmail = CRM_Utils_Array::value('mail', $row);
         if (strtolower($dbName) == strtolower($name)) {
             $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $name));
         }
         if (strtolower($dbEmail) == strtolower($email)) {
             if (empty($email)) {
                 $errors[$emailName] = ts('You cannot create an email account for a contact with no email', array(1 => $email));
             } else {
                 $errors[$emailName] = ts('This email %1 is already registered. Please select another email.', array(1 => $email));
             }
         }
     }
 }
开发者ID:rollox,项目名称:civicrm-core,代码行数:55,代码来源:Drupal6.php


示例13: pressButton

 /**
  * Simulate action of pressing of an Add More button. This function processes
  * the form based on the specified inputs and updates the form with the new
  * values in the cache so that the form's submit button can work correctly.
  *
  * @param string $triggering_element_name
  *   Name of the Add More button or value of Op key.
  * @param array $options
  *   Options array. If key "ajax" is set to TRUE, then
  *   $triggering_element_name is assumed to be name of the Add More button
  *   otherwise it is taken to be the value of Op key.
  *
  * @return Response
  *   Response object.
  */
 public function pressButton($triggering_element_name = NULL, $options = array())
 {
     $options += array('ajax' => FALSE);
     $ajax = $options['ajax'];
     // Make sure that a button with provided name exists.
     if ($ajax && !is_null($triggering_element_name) && !$this->buttonExists($triggering_element_name)) {
         return new Response(FALSE, NULL, "Button {$triggering_element_name} does not exist.");
     }
     if (!$ajax) {
         // If this is not an AJAX request, then the supplied name is the value of
         // Op parameter.
         $response = $this->fillOpValues($triggering_element_name);
         if (!$response->getSuccess()) {
             return $response;
         }
     }
     $this->clearErrors();
     $this->makeUncheckedCheckboxesNull();
     $this->removeFileFieldWeights();
     $old_form_state_values = !empty($this->form_state['values']) ? $this->form_state['values'] : array();
     $this->form_state = form_state_defaults();
     $args = func_get_args();
     // Remove $triggering_element_name from the arguments.
     array_shift($args);
     // Remove $options from the arguments.
     array_shift($args);
     $this->form_state['build_info']['args'] = $args;
     $this->form_state['programmed_bypass_access_check'] = FALSE;
     //$this->form_state['values']['form_build_id'] = $this->form['#build_id'];
     // Add more field button sets $form_state['rebuild'] to TRUE because of
     // which submit handlers are not called. Hence we set it back to FALSE.
     $this->removeKey('input');
     $this->removeKey('triggering_element');
     $this->removeKey('validate_handlers');
     $this->removeKey('submit_handlers');
     $this->removeKey('clicked_button');
     $this->form_state['input'] = $old_form_state_values;
     $this->form_state['input']['form_build_id'] = $this->form['#build_id'];
     if (!is_null($triggering_element_name) && $ajax) {
         $this->form_state['input']['_triggering_element_name'] = $triggering_element_name;
     }
     $this->form_state['no_redirect'] = TRUE;
     $this->form_state['method'] = 'post';
     //$this->form_state['programmed'] = TRUE;
     $this->form = drupal_build_form($this->form_id, $this->form_state);
     if ($ajax && !is_null($triggering_element_name)) {
         unset($this->form_state['values'][$triggering_element_name]);
     }
     // Reset the static cache for validated forms otherwise form won't go
     // through validation function again.
     drupal_static_reset('drupal_validate_form');
     if ($errors = form_get_errors()) {
         $this->errors = $errors;
         return new Response(FALSE, NULL, implode(", ", $this->errors));
     }
     return new Response(TRUE, NULL, "");
 }
开发者ID:vishalred,项目名称:redtest-core-pw,代码行数:72,代码来源:Form.php


示例14: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->validateOptionsForm($form['options'], $form_state);
     if (form_get_errors($form_state)) {
         $form_state['rerender'] = TRUE;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:10,代码来源:Display.php


示例15: form_get_errors

<?php

$messages = form_get_errors();
if (!empty($messages)) {
    foreach ($messages as $message) {
        drupal_set_message($message, 'error');
    }
    print theme('status_messages');
}
print drupal_render_children($form);
开发者ID:GitError404,项目名称:favrskov.dk,代码行数:10,代码来源:user-login.tpl.php


示例16: buildForm


//.........这里部分代码省略.........
         // page.
         $page_entries++;
         $term_deltas[$term->id()] = isset($term_deltas[$term->id()]) ? $term_deltas[$term->id()] + 1 : 0;
         $key = 'tid:' . $term->id() . ':' . $term_deltas[$term->id()];
         // Keep track of the first term displayed on this page.
         if ($page_entries == 1) {
             $form['#first_tid'] = $term->id();
         }
         // Keep a variable to make sure at least 2 root elements are displayed.
         if ($term->parents[0] == 0) {
             $root_entries++;
         }
         $current_page[$key] = $term;
     } while ($term = next($tree));
     // Because we didn't use a pager query, set the necessary pager variables.
     $total_entries = $before_entries + $page_entries + $after_entries;
     $pager_total_items[0] = $total_entries;
     $pager_page_array[0] = $page;
     $pager_total[0] = ceil($total_entries / $page_increment);
     // If this form was already submitted once, it's probably hit a validation
     // error. Ensure the form is rebuilt in the same order as the user
     // submitted.
     if (!empty($form_state['input'])) {
         // Get the POST order.
         $order = array_flip(array_keys($form_state['input']['terms']));
         // Update our form with the new order.
         $current_page = array_merge($order, $current_page);
         foreach ($current_page as $key => $term) {
             // Verify this is a term for the current page and set at the current
             // depth.
             if (is_array($form_state['input']['terms'][$key]) && is_numeric($form_state['input']['terms'][$key]['term']['tid'])) {
                 $current_page[$key]->depth = $form_state['input']['terms'][$key]['term']['depth'];
             } else {
                 unset($current_page[$key]);
             }
         }
     }
     $errors = form_get_errors($form_state);
     $destination = drupal_get_destination();
     $row_position = 0;
     // Build the actual form.
     $form['terms'] = array('#type' => 'table', '#header' => array($this->t('Name'), $this->t('Weight'), $this->t('Operations')), '#empty' => $this->t('No terms available. <a href="@link">Add term</a>.', array('@link' => url('admin/structure/taxonomy/manage/' . $taxonomy_vocabulary->id() . '/add'))), '#attributes' => array('id' => 'taxonomy'));
     foreach ($current_page as $key => $term) {
         /** @var $term \Drupal\Core\Entity\EntityInterface */
         $form['terms'][$key]['#term'] = $term;
         $indentation = array();
         if (isset($term->depth) && $term->depth > 0) {
             $indentation = array('#theme' => 'indentation', '#size' => $term->depth);
         }
         $form['terms'][$key]['term'] = array('#prefix' => !empty($indentation) ? drupal_render($indentation) : '', '#type' => 'link', '#title' => $term->getName()) + $term->urlInfo()->toRenderArray();
         if ($taxonomy_vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
             $parent_fields = TRUE;
             $form['terms'][$key]['term']['tid'] = array('#type' => 'hidden', '#value' => $term->id(), '#attributes' => array('class' => array('term-id')));
             $form['terms'][$key]['term']['parent'] = array('#type' => 'hidden', '#default_value' => $term->parents[0], '#attributes' => array('class' => array('term-parent')));
             $form['terms'][$key]['term']['depth'] = array('#type' => 'hidden', '#default_value' => $term->depth, '#attributes' => array('class' => array('term-depth')));
         }
         $form['terms'][$key]['weight'] = array('#type' => 'weight', '#delta' => $delta, '#title' => $this->t('Weight for added term'), '#title_display' => 'invisible', '#default_value' => $term->getWeight(), '#attributes' => array('class' => array('term-weight')));
         $operations = array('edit' => array('title' => $this->t('Edit'), 'query' => $destination) + $term->urlInfo('edit-form')->toArray(), 'delete' => array('title' => $this->t('Delete'), 'query' => $destination) + $term->urlInfo('delete-form')->toArray());
         if ($this->moduleHandler->moduleExists('content_translation') && content_translation_translate_access($term)) {
             $operations['translate'] = array('title' => $this->t('Translate'), 'query' => $destination) + $term->urlInfo('drupal:content-translation-overview')->toArray();
         }
         $form['terms'][$key]['operations'] = array('#type' => 'operations', '#links' => $operations);
         $form['terms'][$key]['#attributes']['class'] = array();
         if ($parent_fields) {
             $form['terms'][$key]['#attributes']['class'][] = 'draggable';
         }
         // Add classes that mark which terms belong to previous and next pages.
         if ($row_position < $back_step || $row_position >= $page_entries - $forward_step) {
             $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-preview';
         }
         if ($row_position !== 0 && $row_position !== count($tree) - 1) {
             if ($row_position == $back_step - 1 || $row_position == $page_entries - $forward_step - 1) {
                 $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-divider-top';
             } elseif ($row_position == $back_step || $row_position == $page_entries - $forward_step) {
                 $form['terms'][$key]['#attributes']['class'][] = 'taxonomy-term-divider-bottom';
             }
         }
         // Add an error class if this row contains a form error.
         foreach ($errors as $error_key => $error) {
             if (strpos($error_key, $key) === 0) {
                 $form['terms'][$key]['#attributes']['class'][] = 'error';
             }
         }
         $row_position++;
     }
     if ($parent_fields) {
         $form['terms']['#tabledrag'][] = array('action' => 'match', 'relationship' => 'parent', 'group' => 'term-parent', 'subgroup' => 'term-parent', 'source' => 'term-id', 'hidden' => FALSE);
         $form['terms']['#tabledrag'][] = array('action' => 'depth', 'relationship' => 'group', 'group' => 'term-depth', 'hidden' => FALSE);
         $form['terms']['#attached']['library'][] = 'taxonomy/drupal.taxonomy';
         $form['terms']['#attached']['js'][] = array('data' => array('taxonomy' => array('backStep' => $back_step, 'forwardStep' => $forward_step)), 'type' => 'setting');
     }
     $form['terms']['#tabledrag'][] = array('action' => 'order', 'relationship' => 'sibling', 'group' => 'term-weight');
     if ($taxonomy_vocabulary->hierarchy != TAXONOMY_HIERARCHY_MULTIPLE && count($tree) > 1) {
         $form['actions'] = array('#type' => 'actions', '#tree' => FALSE);
         $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary');
         $form['actions']['reset_alphabetical'] = array('#type' => 'submit', '#submit' => array(array($this, 'submitReset')), '#value' => $this->t('Reset to alphabetical'));
         $form_state['redirect'] = array(current_path(), $page ? array('query' => array('page' => $page)) : array());
     }
     return $form;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:101,代码来源:OverviewTerms.php


示例17: install_verify_settings

/**
 * Verify existing settings.php
 */
function install_verify_settings()
{
    global $db_prefix, $databases;
    // Verify existing settings (if any).
    if (!empty($databases)) {
        // We need this because we want to run form_get_errors.
        include_once DRUPAL_ROOT . '/includes/form.inc';
        $database = $databases['default']['default'];
        $settings_file = './' . conf_path(FALSE, TRUE) . '/settings.php';
        $form_state = array();
        _install_settings_form_validate($database, $settings_file, $form_state);
        if (!form_get_errors()) {
            return TRUE;
        }
    }
    return FALSE;
}
开发者ID:schuyler1d,项目名称:drupal,代码行数:20,代码来源:install.php


示例18: guifi_device_form_validate

function guifi_device_form_validate($form, &$form_state)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate()', $form_state['values']);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(vlans)', $form_state['values'][vlans]);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(aggregations)', $form_state['values'][aggregations]);
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(ipv4)', $form_state['values'][ipv4]);
    // nick
    if (isset($form['main']['nick'])) {
        guifi_validate_nick($form_state['values']['nick']);
        $query = db_query("\n      SELECT nick\n      FROM {guifi_devices}\n      WHERE lcase(nick)=lcase('%s')\n       AND id <> %d", strtolower($form_state['values']['nick']), $form_state['values']['id']);
        while (db_fetch_object($query)) {
            form_set_error('nick', t('Nick already in use.'));
        }
    }
    // ssid
    if (empty($form_state['values']['ssid'])) {
        $form_state['values']['ssid'] = $form_state['values']['nick'];
    }
    // Validate ip address(es)
    // Finding duplicates
    $ips = array();
    if (!empty($form_state['values']['ipv4'])) {
        // first checking local IPs
        foreach ($form_state['values']['ipv4'] as $keyS => $valueS) {
            if (empty($valueS[ipv4])) {
                continue;
            }
            // duplicate ip?
            if (in_array($valueS[ipv4], $ips)) {
                form_set_error("ipv4][{$keyS}][ipv4", t('address %addr is duplicated', array('%addr' => $valueS[ipv4])));
            }
            $ips[] = $valueS[ipv4];
            $valueSIPCalc = _ipcalc($valueS[ipv4], $valueS[netmask]);
            // Now looking into remote IPs
            foreach ($valueS[subnet] as $keyI => $valueI) {
                if (empty($valueI[ipv4])) {
                    continue;
                }
                guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate(ipv4s)', $valueS[ipv4] . ' / ' . $valueI[ipv4] . ' ' . $valueI[did]);
                // duplicate ip?
                if (in_array($valueI[ipv4], $ips)) {
                    if ($valueI['new']) {
                        $field = "ipv4][{$keyS}][subnet][{$keyI}][ipv4txt";
                    } else {
                        $field = "ipv4][{$keyS}][subnet][{$keyI}][ipv4";
                    }
                    form_set_error($field, t('address %addr is duplicated', array('%addr' => $valueI[ipv4])));
                }
                $ips[] = $valueI[ipv4];
                // same subnet as related IP?
                $valueIIPCalc = _ipcalc($valueI[ipv4], $valueS[netmask]);
                if ($valueSIPCalc[netid] != $valueIIPCalc[netid] or $valueSIPCalc[maskbits] != $valueIIPCalc[maskbits]) {
                    form_set_error("ipv4][{$keyS}][subnet][{$keyI}][ipv4", t('address %addr1 not at same subnet as %addr2', array('%addr1' => $valueI[ipv4], '%addr2' => $valueS[ipv4])));
                }
                // remote id should be populated
                if (empty($valueI[did])) {
                    form_set_error("ipv4][{$keyS}][subnet][{$keyI}][did", t('Remote device for address %addr1 not specified', array('%addr1' => $valueI[ipv4])));
                }
            }
            // for remote IPs
        }
        // for local IPs
        /*   if (db_affected_rows(db_query("
              SELECT i.id
              FROM {guifi_interfaces} i,{guifi_ipv4} a
              WHERE i.id=a.interface_id AND a.ipv4='%s'
                AND i.device_id != %d",
              $form_state['values']['ipv4'],
              $form_state['values']['id']))) {
              $message = t('IP %ipv4 already taken in the database. Choose another or leave the address blank.',
                array('%ipv4' => $form_state['values']['ipv4']));
              form_set_error('ipv4',$message); 
            } */
    }
    // Validating vlans & aggregations
    foreach (array('vlans', 'aggregations') as $vtype) {
        foreach ($form_state['values'][$vtype] as $kvlan => $vlan) {
            // interface_type (name) should have a value
            if (empty($vlan['interface_type']) and !form_get_errors()) {
                $vlan['interface_type'] = substr($vtype, 0, 4) . $kvlan;
                form_set_value(array('#parents' => array($vtype, $kvlan, 'interface_type')), $vlan['interface_type'], $form_state);
                $form_state['rebuild'] = TRUE;
                drupal_set_message(t('Setting interface name to %name', array('%name' => $vlan['interface_type'])), 'warning');
            }
            // parent should exists
            if (empty($vlan['related_interfaces'])) {
                form_set_error("{$vtype}][{$kvlan}][related_interfaces", t('%name should have related interface(s)', array('%name' => $vlan[interface_type])));
            }
        }
    }
    // foreach vlans, aggregations
    // No duplicate names on interface names
    $ifs = guifi_get_currentInterfaces($form_state['values']);
    $iChecked = array();
    foreach ($ifs as $k => $iname) {
        if (in_array($iname, $iChecked)) {
            guifi_log(GUIFILOG_TRACE, 'function guifi_device_form_validate()', $iname);
            foreach (array('interfaces', 'vlans', 'aggregations', 'tunnels') as $iClass) {
                if (isset($form_state[values][$iClass][$k])) {
//.........这里部分代码省略.........
开发者ID:itorres,项目名称:drupal-guifi,代码行数:101,代码来源:guifi_devices.inc.php


示例19: checkUserNameEmailExists

 /**
  * Check if username and email exists in the drupal db.
  *
  * @param array $params
  *   Array of name and mail values.
  * @param array $errors
  *   Array of errors.
  * @param string $emailName
  *   Field label for the 'email'.
  */
 public static function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email')
 {
     $errors = form_get_errors();
     if ($errors) {
         // unset drupal messages to avoid twice display of errors
         unset($_SESSION['messages']);
     }
     if (!empty($params['name'])) {
         if ($nameError = user_validate_name($params['name'])) {
             $errors['cms_name'] = $nameError;
         } else {
             $uid = db_query("SELECT uid FROM {users} WHERE name = :name", array(':name' => $params['name']))->fetchField();
             if ((bool) $uid) {
                 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', array(1 => $params['name']));
             }
         }
     }
     if (!empty($params['mail'])) {
         if (!valid_email_address($params['mail'])) {
             $errors[$emailName] = ts('The e-mail address %1 is not valid.', array('%1' => $params['mail']));
         } else {
             $uid = db_query("SELECT uid FROM {users} WHERE mail = :mail", array(':mail' => $params['mail']))->fetchField();
             if ((bool) $uid) {
                 $resetUrl = url('user/password');
                 $errors[$emailName] = ts('The email address %1 already has an account associated with it. <a href="%2">Have you forgotten your password?</a>', array(1 => $params['mail'], 2 => $resetUrl));
             }
         }
     }
 }
开发者ID:scardinius,项目名称:civicrm-core,代码行数:39,代码来源:Backdrop.php


示例20: createDrupalUser

 /**
  * Function to create a user in Drupal.
  *  
  * @param array  $params associated array 
  * @param string $mail email id for cms user
  *
  * @return uid if user exists, false otherwise
  * 
  * @access public
  * @static
  */
 static function createDrupalUser(&$params, $mail)
 {
     $values['values'] = array('name' => $params['cms_name'], 'mail' => $params[$mail], 'op' => 'Create new account');
     if (!variable_get('user_email_verification', TRUE)) {
         $values['values']['pass']['pass1'] = $params['cms_pass'];
         $values['values']['pass']['pass2'] = $params['cms_pass'];
     }
     $config =& CRM_Core_Config::singleton();
     // we also need to redirect b
     $config->inCiviCRM = true;
     $res = drupal_execute('user_register', $values);
     $config->inCiviCRM = false;
     if (form_get_errors()) {
         return false;
     }
     // looks like we created a drupal user, lets make another db call to get the user id!
     $db_cms = DB::connect($config->userFrameworkDSN);
     if (DB::isError($db_cms)) {
         die("Cannot connect to UF db via {$dsn}, " . $db_cms->getMessage());
     }
     //Fetch id of newly added user
     $id_sql = "SELECT uid FROM {$config->userFrameworkUsersTableName} where name = '{$params['cms_name']}'";
     $id_query = $db_cms->query($id_sql);
     $id_row = $id_query->fetchRow(DB_FETCHMODE_ASSOC);
     return $id_row['uid'];
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:37,代码来源:CMSUser.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP form_header函数代码示例发布时间:2022-05-15
下一篇:
PHP form_format函数代码示例发布时间: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