0

I have a form with a value field and i would like to set the value to a markup field as shown below. The problem is that it retuns empty. Is there other alternatives.

 public function buildForm(array $form, FormStateInterface $form_state) { $form['container']['#tree'] = TRUE; $form['container']['#type'] = 'container'; $form['container']['store_value'] = [ '#type' => 'value', '#value' => 'Angeline Mnene' ]; $form['container']['show_value'] = [ '#type' => 'markup', '#markup' => 'The stored value is: ' . $form_state- >getValue(['container','store_value']), ]; return $form; } 

1 Answer 1

0

I finally got an answer and would like to post it here, to help someone who may run into this problem as well.

 public function buildForm(array $form, FormStateInterface $form_state) { //SET THE VALUE HERE $form_state->setValue('store_value', 'The stored value is: Angeline Mnene'); $form['container']['#tree'] = TRUE; $form['container']['#type'] = 'container'; $form['container']['show_value'] = [ '#type' => 'markup', '#markup' => 'The stored value is: ' . $form_state- >getValue('store_value'), ]; return $form; } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.