I have HTML markup which is externally generated but I need to display in a form.
I've got the following code in a form controller:
public function buildForm(array $form, FormStateInterface $form_state){
$form['phone_number'] = [
'#type' => 'tel',
'#title' => 'Example phone',
];
$form['TEST-Cloze'] = [
'#markup' => "<p><select><option value='[Walter]'>[Walter]</option><option value=' Hank'> Hank</option><option value=' Gus'> Gus</option><option value=' Jessie'> Jessie</option><option value=' Mike'> Mike</option></select> was diagnosed with cancer in his 50th year. He began working with <select><option value='Badger'>Badger</option><option value=' Skinny Pete'> Skinny Pete</option><option value=' [Jessie]'> [Jessie]</option><option value=' Tortuga'> Tortuga</option><option value=' Bogdan'> Bogdan</option></select> to produce <select><option value='cocaine'>cocaine</option><option value=' heronie'> heronie</option><option value=' opiods'> opiods</option><option value=' [amphetamines]'> [amphetamines]</option><option valu\nhis death. He eventually became involved with hardened criminal <select><option value='[Tuco]'>[Tuco]</option><option value=' Gomie'> Gomie</option><option value=' Bogdan'> Bogdan\noption><option value=' Todd'> Todd</option><option value=' Gale'> Gale</option></select> to help with the distribution of his illegally manufactured product.</p>"
// '#markup' => $question->processed
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
However, the output is completely stripped of markup and displays as plain text, as shown below:
How can I get the markup printed?
UPDATE:
I am attempting to add my form element markup because of the complexity of having multiple drop-down lists in a single paragraph, such as displayed below:
I struggled to achieve this type form output using other form components which is why I began looking into the #markup component.
<p>
tag? Why don't you swap the single quotes and double quotes? Why don't you simply add a'#type' => 'select'
element and add a'#prefix' => '<p>'
and'#suffix' => '</p>'
? Why do all your options have a space in theirvalue
? Can you please update your question for clarification?