add html to parent form, not to an element

Notice: This thread is very old.
mikeb
Member | 31
+
0
-

I'm sure I'm missing something obvious… how can I add a block of html directly to a form. ie not attached to an input element. for instance a heading and paragraph of text between two elements. like $form->addHTML ($el); (not than addHTML works on the form, of course).

thanks for your suggestions

CZechBoY
Member | 3608
+
0
-

Do you mean description?

$form->addText('abc')
	->setOption('description', Html::el('b')->setText('description for abc'));
mikeb
Member | 31
+
0
-

that's it! thankyou

Last edited by mikeb (2016-10-27 09:09)

mikeb
Member | 31
+
0
-

hang-on. No, not that. that adds a text input then adds the html description attached to that element.
I want the html description added without the text input.
any ideas?
thanks

CZechBoY
Member | 3608
+
0
-

Why do you need that? You can try to add description to container.

mikeb
Member | 31
+
0
-

i can't add description to a container using setOption():
Call to undefined method Nette\Forms\Container::setOption()
is there another way to add a description to a container?
I can add description to a group but it doesn't look great so I'd have to restyle it.
???

mikeb
Member | 31
+
0
-

so i made a new class to extend base control:

use Nette\Forms\Form;
use Nette\Utils\Html;
class netteLabel extends Nette\Forms\Controls\BaseControl
{
	var $show_label, $html;//mb
	public function __construct($label = NULL, $html=null)
	{
		parent::__construct();
		$this->show_label = $label;//mb
		$this->html = $html;//mb
	}

	public function getControl()
	{
		return Html::el()
			->addHtml(Html::el($this->html)->setText($this->show_label));

	}

}

and set the element like this:

$html = 'h1';//or whatever
$label = 'grrr';
$form[$el_name] = new \netteLabel($label,$html);

and it gives me html formatted text inline in the form

if there's an easier way please let me know!

Last edited by mikeb (2016-10-27 10:45)