0

How do I get the option text from the submitted value of the radio field in Drupal 8 webform submission? I have written a rule action condition on webform submission where I am storing data in a middle table.

Based on screen I am looking for Option Text from webform field. Current version: Drupal 8.6.15 & webform 8.x-5.2

enter image description here enter image description here

  • 1
    ... Drupal 7 or 8? – No Sssweat May 8 at 3:20
0

Assuming Drupal 8 (since you didn't give a version), there are two parts to this.

Imagine this element in the form:

$form['some_field'] = [
  '#type' => 'radios',
  '#options' => [
    'option1' => $this->t('Option 1'),
    'option2' => $this->t('Option 2'),
  ],
];

The submitted value can be retrieved from $form_state in your submit handler:

$radio_value = $form_state->getValue('some_field');

You can then use the value to get the text of the radio, from the $form element:

$radio_text = $form['some_field']['#options'][$radio_value];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.