/** * Write the values into the database. * Return 0 if there was an error, else 1. */ function updateDatabase($form, $myvalues) { //Try to create the record now $nSiteID = $this->m_oContext->getSiteID(); $nIEN = $myvalues['tid']; $nUID = $this->m_oContext->getUID(); $sCWFS = $this->m_oTT->getTicketWorkflowState($nSiteID . '-' . $nIEN); $updated_dt = date("Y-m-d H:i:s", time()); if ($myvalues['reason'] == 'Other' && (!isset($myvalues['suspend_notes_tx']) || trim($myvalues['suspend_notes_tx']) == '')) { form_set_error('suspend_notes_tx', 'Cannot suspend a ticket without an explanation when reason is "Other".'); return 0; } //Create the raptor_ticket_suspend_notes record now try { $oInsert = db_insert('raptor_ticket_suspend_notes')->fields(array('siteid' => $nSiteID, 'IEN' => $nIEN, 'notes_tx' => 'REASON:' . $myvalues['reason'] . '<br>NOTES:' . $myvalues['suspend_notes_tx'], 'author_uid' => $nUID, 'created_dt' => $updated_dt))->execute(); } catch (\Exception $e) { error_log('Failed to create raptor_ticket_suspend_notes: ' . $e . "\nDetails..." . print_r($oInsert, true)); form_set_error('suspend_notes_tx', 'Failed to save notes for this ticket!'); return 0; } $sNewWFS = 'IA'; $this->m_oTT->setTicketWorkflowState($nSiteID . '-' . $nIEN, $nUID, $sNewWFS, $sCWFS, $updated_dt); //Write success message drupal_set_message('Suspended ' . $myvalues['tid'] . ' (' . $myvalues['procName'] . ')'); return 1; }
/** * CALLBACK_commerce_extra_configure_validate() */ function CALLBACK_commerce_extra_configure_validate(&$form, &$form_state) { // Example from commerce_extra_quantity feature if (!is_numeric($form_state['values']['commerce_extra_quantity_cardinality'])) { form_set_error('commerce_extra_quantity_cardinality', t('Field @field_name must be numeric value.', array('@field_name' => t('Quantity cardinality')))); } }
public function validate($node) { // As of PHP 5.1.0, strtotime returns FALSE instead of -1 upon failure. if (!empty($node->datestr) && strtotime($node->datestr) < 0) { form_set_error('datestr', t('Please specify a valid date.')); } }
/** * Validation for the administrative settings form. * * @param object $form * An associative array containing the structure of the form. * @param object $form_state * A keyed array containing the current state of the form. */ public static function hookAdminSettingsValidate($form, &$form_state) { if ($form_state['values']['node_expire_date_entry_elements'] == 1 && $form_state['values']['node_expire_handle_content_expiry'] != 0 && !module_exists('date_popup')) { form_set_error('date_entry_elements', t('To use "Date popups" option Date module should be installed with Date Popup enabled.') . ' ' . t('This option is not available in legacy mode.')); } // End of node_expire_admin_settings_validate(). }
function deleteUserPage_validate($form, $form_state) { if ($form_state['values']['acknowledgement'] == 0) { // ensuring that the user has checked the checkbox form_set_error('checkbox', 'You must acknowledge that you are intentionally deleting your account'); } }
/** * {@inheritdoc} */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { parent::validateConfigurationForm($form, $form_state); if (empty($form_state['values']['width']) && empty($form_state['values']['height'])) { form_set_error('data', $form_state, $this->t('Width and height can not both be blank.')); } }
/** * The user has just finished editing the comment and is trying to * preview or submit it. This hook can be used to check or * even modify the node. Errors should be set with form_set_error(). * * @param $form_values * Passes in an array of form values submitted by the user. * @return * Nothing. */ function hook_comment_validate(&$form_values) { // if the subject is the same as the comment. if ($form_values['subject'] == $form_values['comment']) { form_set_error('comment', t('you should write more text than in the subject')); } }
/** * Implements WidgetInterface::validatePreviewForm(). * * Right now no validation is necessary. */ public function validatePreviewForm($form, &$form_state) { $date = self::getTimeStamp($form_state); if (!$date) { form_set_error('preview_date_wrapper', t('Invalid Date/Time given.')); } }
/** * Form element validation handler for 'name' in form_test_validate_form(). */ public function validateName(&$element, FormStateInterface $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); } }
public function validate($form, &$form_state) { $remote = Remote::load($form_state['values']['remote']); if (!$remote) { form_set_error('remote', 'The specified remote is invalid. Please choose another.'); } }
function simplemap_exclusions_form_validate($form, &$form_state) { $input = $form_state['input']; if (!is_numeric($input['nid'])) { form_set_error('nid', t('The NID must be a number')); } }
/** * Validate handler where we actually save the files... */ function flux_theme_settings_validate($form, &$form_state) { // Handle file uploads. $validators = array('file_validate_is_image' => array()); // Check for a new uploaded logo. $file = file_save_upload('cover_photo_upload', $validators); if (isset($file)) { // File upload was attempted. if ($file) { // Put the temporary file in form_values so we can save it on submit. $form_state['values']['cover_photo_upload'] = $file; } else { // File upload failed. form_set_error('cover_photo_upload', t('The image could not be uploaded.')); } } $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg')); // If the user provided a path for a logo or favicon file, make sure a file // exists at that path. if ($form_state['values']['cover_photo_path']) { $path = flux_system_theme_settings_validate_path($form_state['values']['cover_photo_path']); if (!$path) { form_set_error('cover_photo_path', t('The custom path is invalid.')); } } }
/** * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { parent::validateForm($form, $form_state); if (!intval($form_state['values']['request_token_lifetime'], 10)) { form_set_error('oauth_request_token_lifetime', t('The request token lifetime must be a non-zero integer value.')); } }
/** * Some checks to validate the data before we try to save it. */ function looksValid($form, $myvalues) { $is_good = TRUE; //Array ( [table_container] => Array ( [orders] => Array ( [449] => 449 [601] => 601 $orders = $myvalues['table_container']['orders']; if (!is_array($orders)) { form_set_error('table_container', 'Did not find any orders!'); $is_good = FALSE; } else { $foundone = FALSE; foreach ($orders as $key => $value) { if ($key == $value) { $foundone = TRUE; break; } } if (!$foundone) { form_set_error('table_container', 'Did not find any selected orders'); $is_good = FALSE; } } if (!isset($myvalues['cancelreason']) || !is_numeric($myvalues['cancelreason'])) { form_set_error('cancelreason', 'Did not find any a valid cancel reason'); $is_good = FALSE; } return $is_good; }
/** * Write the values into the database. * Return 1 if all okay, else return 0. */ function updateDatabase($myvalues) { if (!isset($myvalues['raw_list_rows'])) { die("Cannot update user record because missing raw_list_rows in array!\n" . var_dump($myvalues)); } $tablename = $this->m_sTablename; $aFieldNames = $this->m_aFieldNames; $aOrderBy = $this->m_aOrderBy; $aRequiredCols = $this->m_aRequiredCols; $aMaxLenCols = $this->m_aMaxLenCols; $aDataTypeCols = $this->m_aDataTypeCols; $aRawRows = $this->m_oPageHelper->parseRawText($myvalues['raw_list_rows']); $result = $this->m_oPageHelper->parseRows($aRawRows, $aRequiredCols, $aMaxLenCols, $aDataTypeCols); $errors = $result['errors']; if (count($errors) > 0) { if (count($errors) > 1) { form_set_error("raw_list_rows", '<ol><li>' . implode('<li>', $errors) . '</ol>'); } else { form_set_error("raw_list_rows", $errors[0]); } /* foreach($errors as $error) { form_set_error("raw_list_rows",$error); } * */ return 0; } else { $nRows = $this->m_oPageHelper->writeValues($tablename, $aFieldNames, $result['parsedrows']); return 1; } }
/** * 'upload_zip' upload field must refer to a zip file containing * all files for the pubnode (may be at top-level or inside a subdirectory) */ public function import(&$form_state, $docid = NULL) { $validators = array('file_validate_extensions' => array('zip'), 'file_validate_size' => array(100000000, 0)); if ($file = file_save_upload($this->fieldname, $validators, file_directory_temp(), FILE_EXISTS_REPLACE)) { $zip = new ZipArchive(); if ($zip->open($file->filepath) !== TRUE) { form_set_error(t("Cannot open !file", array("!file" => $file->filename)), 'error'); return FALSE; } // else if (empty($docid)) { $docid = $this->hashFile($file->filepath); } $pubpath = $this->constructPubPath($docid); //drupal_set_message("PUBPATH: " . $pubpath); file_check_directory($pubpath, FILE_CREATE_DIRECTORY); $zip->extractTo($pubpath); drupal_set_message(t("Extracted !num files to directory !dir", array('!num' => $zip->numFiles, '!dir' => $pubpath))); $zip->close(); $this->pubpath = $pubpath; return TRUE; } // else validations failed and error message will be set by upload function return FALSE; }
/** * Some checks to validate the data before we try to save it. * @param type $form * @param type $myvalues * @return TRUE or FALSE */ function looksValid($form, $myvalues) { $bGood = TRUE; if (!isset($myvalues['reason']) || !is_numeric($myvalues['reason'])) { form_set_error('reason', 'Did not find any a valid cancel reason'); $is_good = FALSE; } return $bGood; }
public function validate($form, &$form_state) { // Validate the MLID selection. $mlid_values = explode(':', $form_state['values']['mlid']); if (count($mlid_values) != 2 || menu_link_load($mlid_values[1]) === false) { form_set_error('mlid', t('The menu link provided is invalid.')); return; } }
public function validate($form, &$form_state) { // Make sure the URL is valid. $url = $form_state['values']['url']; if ($url && !valid_url($url, true)) { form_set_error('url', t('That URL is invalid. You must enter an absolute URL.')); // TODO: Add logic to test the connection to the server and throw validation errors if it fails. } }
/** * {@inheritdoc} */ public function validate(array $form, FormStateInterface $form_state) { $entity = $this->buildEntity($form, $form_state); $validator = \Drupal::service('domain.validator'); $errors = $validator->validate($entity); if (!empty($errors)) { form_set_error('hostname', $errors); } }
function os_poker_admin_form_validate($from, &$form_state) { $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; if ($op != t('Reset to defaults')) { if (!valid_email_address($form_state['values']['os_poker_abuse_mail_to'])) { form_set_error('os_poker_abuse_mail_to', t('The e-mail address you specified is not valid.')); } } }
/** * Process the errors occured during the "validateInput" action * * @return void */ protected function postprocessErrorActionValidateInput() { if (\XLite\Module\CDev\DrupalConnector\Handler::getInstance()->checkCurrentCMS()) { // Highligth the "Email" field using Drupal function form_set_error('mail', t($this->getErrorActionValidateInputMessage($this->getRequestData('login')))); } else { parent::postprocessErrorActionValidateInput(); } }
/** * Submit callback to save the css. */ function os2web_mobile_theme_css_save(&$form, &$form_state) { // Save the contents of the textarea. if (file_put_contents($form_state['values']['theme_path_css'], $form_state['values']['mobile_css'])) { drupal_set_message(t('mobile.css saved')); } else { form_set_error('mobile_css', t('Could not save mobile.css, check file permissions')); } }
/** * Settings form validator. */ public function settingsFormValidate(&$form, &$form_state, $job = NULL) { $elements =& $form['settings'][$this->type][$this->name]; $values =& $form_state['values']['settings'][$this->type][$this->name]; if (!$job) { if (intval($values['max_threads']) <= 0) { form_set_error("settings[{$this->type}][{$this->name}", t('%title must be greater than 0', array('%title' => $elements['launcher']['max_threads']['#title']))); } } }
/** * Overrides CommerceLicenseBase::formValidate(). */ public function formValidate($form, &$form_state) { parent::formValidate($form, $form_state); $parents_path = implode('][', $form['#parents']); $form_values = drupal_array_get_nested_value($form_state['values'], $form['#parents']); // Validate the cle_name field value. if ($form_values['cle_name'][LANGUAGE_NONE][0]['value'] == 'John Smith') { form_set_error($parents_path . '][cle_name][und][0][value', t('John Smith is not allowed to have licenses.')); } }
/** * Some checks to validate the data before we try to save it. * @param type $form * @param type $myvalues * @return TRUE or FALSE */ function looksValid($form, $myvalues) { $bGood = TRUE; if (!isset($myvalues['selected_vid']) || $myvalues['selected_vid'] == '') { //drupal_set_message('>>>>myvalues>>>>'.print_r($myvalues,TRUE)); //die('failed>>>>myvalues>>>>'.print_r($myvalues,TRUE)); $bGood = FALSE; form_set_error('available_visits_table', 'No visit has been selected'); } return $bGood; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $result = $this->zoho_generate_authtoken($form_state->getValue('zoho_username_email'), $form_state->getValue('zoho_password')); if (isset($result['authtoken'])) { drupal_set_message(t('Successfully generated a new Authtoken : :token', array(':token' => $result['authtoken']))); $form_state->setValue('zoho_api_authtoken', $result['authtoken']); } else { form_set_error(t('There was an error: :error.<br/>Please resolve the error and try again.', array(':error' => $result['error'])), 'error'); } }
/** * Submit form validation callback: validates data entered via our custom * submit form elements. Failed validation requires a FALSE return value. * Otherwise nothing needs to be returned. */ public function submit_form_validate($pane_form, $pane_values, $form_parents = array(), $order = NULL) { // Throw an error if a long enough name was not provided. if (strlen($pane_values['name']) < 2) { form_set_error(implode('][', array_merge($form_parents, array('name'))), t('You must enter a name two or more characters long.')); // Even though the form error is enough to stop the submission of the form, // it's not enough to stop it from a Commerce standpoint because of the // combined validation / submission going on per-pane in the checkout form. return FALSE; } }
function gd_performance_admin_settings_validate ( $form, &$form_state ) { $batchSize = StringHelper::trim($form_state['values']['file_upload_batch_size']); if (isset($batchSize)) { try { IntegerDataTypeHandler::checkPositiveInteger($batchSize); } catch (Exception $e) { form_set_error('file_upload_batch_size', $e->getMessage()); } } }
/** * Custom Validation Hook */ function locke_theme_settings_validate($form, &$form_state) { // Handle file uploads. $validators = array('file_validate_is_image' => array()); // Check for a new uploaded logo. $file = file_save_upload('seal_upload', $validators); if (isset($file)) { // File upload was attempted. if ($file) { // Put the temporary file in form_values so we can save it on submit. $form_state['values']['seal_upload'] = $file; } else { // File upload failed. form_set_error('seal_upload', t('The seal could not be uploaded.')); } } // If the user provided a path for a seal file, make sure a file // exists at that path. if ($form_state['values']['seal_path']) { $path = _system_theme_settings_validate_path($form_state['values']['seal_path']); if (!$path) { form_set_error('seal_path', t('The custom seal path is invalid.')); } } }