Skip to main content
added 39 characters in body
Source Link

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
    // check for desired element   
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){
     $surname= $element['#default_value'];
    $form_state->setValue('SOME_NAME', $surname);    
   }  
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {
    
        $element['#element_validate'][] = array(
            'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
            'validate'
        );      
    } 
}

In the validate function:

public static function validate(array &$element, FormStateInterface $formState, array &$form) {
        ksm($formState->getValue('SOME_NAME'));
        $webformKey = $element['#webform_key'];
        
        $value = $formState->getValue($webformKey);
        $surname= $form_state$formState->getValue('SOME_NAME');
        }

I am not getting any value for surname

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
    // check for desired element   
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){
     $surname= $element['#default_value'];
    $form_state->setValue('SOME_NAME', $surname);    
   }  
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {
    
        $element['#element_validate'][] = array(
            'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
            'validate'
        );      
    } 
}

In the validate function:

public static function validate(array &$element, FormStateInterface $formState, array &$form) {
       
        $webformKey = $element['#webform_key'];
        
        $value = $formState->getValue($webformKey);
        $surname= $form_state->getValue('SOME_NAME');
}

I am not getting any value for surname

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
    // check for desired element   
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){
     $surname= $element['#default_value'];
    $form_state->setValue('SOME_NAME', $surname);    
   }  
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {
    
        $element['#element_validate'][] = array(
            'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
            'validate'
        );      
    } 
}

In the validate function:

public static function validate(array &$element, FormStateInterface $formState, array &$form) {
        ksm($formState->getValue('SOME_NAME'));
        $webformKey = $element['#webform_key'];       
        $value = $formState->getValue($webformKey);
        $surname= $formState->getValue('SOME_NAME');
        }

I am not getting any value for surname

added 17 characters in body
Source Link
user72672
user72672

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { // check for desired element
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){ $surname= $element['#default_value']; $form_state->setValue('SOME_NAME', $surname);
}
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
    // check for desired element   
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){
     $surname= $element['#default_value'];
    $form_state->setValue('SOME_NAME', $surname);    
   }  
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {
    
        $element['#element_validate'][] = array(
            'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
            'validate'
        );      
    } 
}

}

in In the validate function public static function validate(array &$element, FormStateInterface $formState, array &$form) {:

public static function validate(array &$element, FormStateInterface $formState, array &$form) {
       
        $webformKey = $element['#webform_key'];
       
        $value = $formState->getValue($webformKey);
        $surname= $form_state->getValue('SOME_NAME');
}

} i I am not getting any value for surname

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { // check for desired element
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){ $surname= $element['#default_value']; $form_state->setValue('SOME_NAME', $surname);
}
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {

    $element['#element_validate'][] = array(
        'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
        'validate'
    );      
} 

}

in the validate function public static function validate(array &$element, FormStateInterface $formState, array &$form) {

    $webformKey = $element['#webform_key'];
   
    $value = $formState->getValue($webformKey);
    $surname= $form_state->getValue('SOME_NAME');

} i am not getting any value for surname

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) {
    // check for desired element   
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){
     $surname= $element['#default_value'];
    $form_state->setValue('SOME_NAME', $surname);    
   }  
   if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {
    
        $element['#element_validate'][] = array(
            'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
            'validate'
        );      
    } 
}

In the validate function:

public static function validate(array &$element, FormStateInterface $formState, array &$form) {
       
        $webformKey = $element['#webform_key'];
       
        $value = $formState->getValue($webformKey);
        $surname= $form_state->getValue('SOME_NAME');
}

I am not getting any value for surname

added 988 characters in body
Source Link

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { // check for desired element
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){ $surname= $element['#default_value']; $form_state->setValue('SOME_NAME', $surname);
}
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {

    $element['#element_validate'][] = array(
        'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
        'validate'
    );      
} 

}

in the validate function public static function validate(array &$element, FormStateInterface $formState, array &$form) {

    $webformKey = $element['#webform_key'];
   
    $value = $formState->getValue($webformKey);
    $surname= $form_state->getValue('SOME_NAME');

} i am not getting any value for surname

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element

I have a requirement which needs to verify an id entered into a text box, by making a REST API call to another system, the issue is to make that REST API call, I need another text parameter which is also inputed into the webform. I have written a custom handler which makes that rest call, but that custom handler work on webform post save option only, how can I pass more than 2 fields to the validate function mentioned in the example given.

function onboarding_webform_element_alter(array &$element, FormStateInterface $form_state, array $context) { // check for desired element
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--surname'){ $surname= $element['#default_value']; $form_state->setValue('SOME_NAME', $surname);
}
if (isset($element['#webform_id']) && $element['#webform_id'] === 'register_account--proda_id') {

    $element['#element_validate'][] = array(
        'Drupal\dhs_vendor_onboarding\Validate\DhsValidateConstraint',
        'validate'
    );      
} 

}

in the validate function public static function validate(array &$element, FormStateInterface $formState, array &$form) {

    $webformKey = $element['#webform_key'];
   
    $value = $formState->getValue($webformKey);
    $surname= $form_state->getValue('SOME_NAME');

} i am not getting any value for surname

edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Loading
edited tags
Link
user72672
user72672
Loading
deleted 3 characters in body; edited tags; edited title
Source Link
user72672
user72672
Loading
Source Link
Loading