Hello, i created a block, but i dont know how i can add html elements within.
I need a some help...
Take a look at this section
public function get_content(){
if ($this->content !== null){
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->items[] = html_writer::tag('form','');
$this->content->items[] = html_writer::tag('input', '');
$this->content->items[] = html_writer::tag('button', 'Enviar');
return $this->content;
}
Nothing happens...
I'm trying to use html_writter direct in $this->content->text = html_writter::tag('form','');
But it's won't work for FORM.
Sorry for my bad english.
Have a look at the HTML output by the block in your browser.
I suspect you will find something that looks like this:
<ul>
<li><form></form></li>
<li><input></input></li>
<li><button>Enviar</button></li>
</ul>
That is probably not what you are looking for - if you want to create a form, then you should consider using 'block_base', not 'block_list' and setting $this->content->text, instead of $this->content->items.
block_list is for (bulleted) lists of items
block_base is more sensible for a block that has a chunk of HTML inside it, rather than a list of items.
You should also make sure Debugging is on, as I suspect you might be have some warning messages (but I haven't checked).
I'm was missing to extend block_list...
My solution to this was:
class block_htmlsimples extends block_base{
public function get_content(){
if ($this->content !== null){
return $this->content;
}
$this->content = new stdClass();
$this->content->text = '<form method="post" action="">';
$this->content->text .= "Nome: <input type='text'/>";
$this->content->text .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => 'Enviar'));
$this->content->text .= "</form>";
return $this->content;
}
}
What do you think about this?
Hello, i found a solution...
require_once ('myblock_form.php');
public function get_content(){
$this->get_content->text = $mform->render(); //instead $mform->display();
$this->content = new stdClass();
$mform = new myblock_form('mymoodle.com/myblock/another_view.php');
return $this->content;
}
Thus, you can have two views and two form definitons, one for exhibition within block and another page to receiver parameters: post or get
Thanks!