Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted September 1, 20177 yr I have a couple of apps that uses questions/answers. Currently I'm using textarea, which has no issue but a user requested to change it to textarea for formatting purposes. It shows fine in another template: But it shows like that in the form: Is it possible to parse HTML in forms?
September 5, 20177 yr Is that a Radio form field? If so, the template already uses the |raw modifier. <label for='elRadio_{$name}_{$k}_{$htmlId}' id='elField_{$name}_label'>{$v|raw}</label> What are you passing as the 'parse' option to the form helper? Sounds like you need to pass this option set to 'raw' to prevent the values you send in for the options from being escaped.
September 5, 20177 yr Author 24 minutes ago, bfarber said: Is that a Radio form field? If so, the template already uses the |raw modifier. <label for='elRadio_{$name}_{$k}_{$htmlId}' id='elField_{$name}_label'>{$v|raw}</label> What are you passing as the 'parse' option to the form helper? Sounds like you need to pass this option set to 'raw' to prevent the values you send in for the options from being escaped. Like that: $form->add( new \IPS\Helpers\Form\Radio( 'answer_' . $i, isset( $data['answer_' . $i ] ) ? $data['answer_' . $i ] : '', TRUE, array( 'options' => $answers, 'parse' => 'normal' ) ) ); Answers: /* Merge wrong and correct answers together */ $answers = $this->question->getAnswers( $question['question_id'] ); /* Shuffle them up */ shuffle( $answers ); /* Give each answer a "unique" ID */ $temp = array(); foreach( $answers as $answer ) { $temp[ md5( $answer['answer_title'] ) ] = $answer['answer_title']; } $answers = $temp; and it goes to the template: return \IPS\Theme::i()->getTemplate( 'view' )->startForm( $form, $data, $this->question, $question['question_id'] ); And: <div data-role="wizardContent"> {$form|raw} </div>
September 6, 20177 yr case 'normal': foreach ( $this->options['options'] as $k => $v ) { if ( is_array( $v ) ) { foreach ( $v as $x => $y ) { $options[ $k ][ $x ] = htmlspecialchars( $y, \IPS\HTMLENTITIES, 'UTF-8', FALSE ); } } else { $options[ $k ] = htmlspecialchars( $v, \IPS\HTMLENTITIES, 'UTF-8', FALSE ); } } break; You are passing parse as 'normal', which runs the value through htmlspecialchars(). That's why I suggested 'raw' in my last reply.
September 6, 20177 yr Author 20 minutes ago, bfarber said: case 'normal': foreach ( $this->options['options'] as $k => $v ) { if ( is_array( $v ) ) { foreach ( $v as $x => $y ) { $options[ $k ][ $x ] = htmlspecialchars( $y, \IPS\HTMLENTITIES, 'UTF-8', FALSE ); } } else { $options[ $k ] = htmlspecialchars( $v, \IPS\HTMLENTITIES, 'UTF-8', FALSE ); } } break; You are passing parse as 'normal', which runs the value through htmlspecialchars(). That's why I suggested 'raw' in my last reply. Not sure I follow. I'm parsing NORMAL, ok: array( 'options' => $answers, 'parse' => 'normal' ) So I removed it or changed it to 'none' as appears in other places. Same result. In IPS\Helpers\Form\Select there's only NORMAL and LANG for the options. Not sure what I have to do.
September 6, 20177 yr 'parse' => 'lang', // Sets how the values for options should be parsed. Acceptable values are "lang" (language keys), "normal" (htmlentities), "raw" (no parsing) or "image" (image URLs, only for Radio fields). Default is "lang". Without testing further though it's hard to say from here. On the surface, it seems that passing 'raw' as the parse option should accomplish what you are after. If it doesn't, I would start digging to find out why.
September 6, 20177 yr Author Damn, I only read the method itself; didn't see the option at the top: $array = array( 1 => "<span style='font-size:200%;color:blue;'><strong>1111</strong></span>", 2 => 2222, 3 => 3333 ); foreach( $array as $k => $v ) { $options[ $k ] = $v; } $form->add( new \IPS\Helpers\Form\Radio( 'answer', '', TRUE, array( 'options' => $options, 'parse' => 'raw' ) ) ); Quick test: Tks, @bfarber.
Archived
This topic is now archived and is closed to further replies.