Jump to content

pass html to $this->valid


Recommended Posts

Hi,

I am coding a custom module, which is just doing some computation from data input by the user in a form (without e-commerce functionality).

I want to give back the answer, which is a numerical value and other values computed from the first, shown in a table.
I got inspired from the ps_emailsubscription module, which uses return $this->valid = 'string' to answer in a green box located below the form. 
I can return a string or a number but I want to display a table, so I tried this in mymodule.php

public function myModule($hookName = null)
  {
	...math computation from values input by user in form...
	$html = '<table><thead><tr><th></th><th>firstCol</th><th>secondCol</th><th>third</th><th>fourth<Col/th></tr></thead>';
  	$html .= '<tr><td></td><td>bla</td><td>bla</td><td>bla</td><td>bla</td></tr>';
  	$html .= '</table>';   
  	return $this->valid = $this->trans('blabla = %firstResult% blabla ', ['%firstResult%' => $firstResult], 'Modules.Mymodule.Mymodule') . $html;
}

The html code is displayed but not interpreted. How can I make it interpreted ? Or display my result table with another manner ?
I tried htmlspecialchars($html), htmlentities($html) but I just get things like "&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&"
html_entity_decode($html) has no effect.

Maybe "this->valid" has a special stuff preventing the html to be interpreted but I have no idea where to find its implementation. 

Thank you

Pierre

Edited by jackflyer (see edit history)
Link to comment
Share on other sites

It's because the html is passed trough a smarty variable {$msg} (see code below)

==> https://stackoverflow.com/questions/16449583/show-a-smarty-variable-with-html-content
 {$msg nofilter} works. Now the html is interpreted. The first text is in the "alert-success" green area but the table does not want to stay in the green area. 
That's because <p> probably does not accept a table. Using a <div> instead of a <p> resolves the problem.

    <div class="col-xs-12">
      {if $msg}
        <p class="alert {if $nw_error}alert-danger{else}alert-success{/if}">
          {$msg nofilter}
        </p>
      {/if}
    </div>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...