Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By raheelwp on
<?php
/**
* Implements hook_form_alter()
*/
function paypal_signup_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'user_register_form'){
global $user;
if(!in_array('administrator', array_values($user->roles))){
//Submit handler for redirecting user to Paypal.
$form['#submit'][] = '_paypal_signup_redirect_paypal';
} else {
// Remove validation when admin is creating user.
foreach (element_children($form) as $key) {
if (strpos($key, 'field_') !== FALSE) {
$form[$key][LANGUAGE_NONE][0]['#required'] = FALSE;
$form[$key][LANGUAGE_NONE]['#required'] = FALSE;
}
}
dpm($form);
}
}
}
?>
In the dpm it shows that #required = bool(false) also i tried with integer (0). But still i am getting errors of required fields.
It also shows the * sign on all custom fields which by the code it should not. any one please have a look why the validation still exists. If i go to manage fields on user entity and remove the uncheck the requird checkbox the fields set to be non-required. But i want that when admin is creating user the fields should not be required.
Thanks
Comments
Instead of set the required
Instead of set the required field to FALSE check if the field is empty if so just set a default value.
But client don't what this
Plus there are some fields that take only INT some takes Var