Page 1 of 1
insert html elements before a field
Posted: 2020-06-06 20:02
by fgazza
Hello everyone!
I would like to insert a custom text before a field. The text should be formatted in html and precede the field label.
I think the solution is to use $html in the hook file's tablename_dv () function but I have no idea how to use it. For example, I would like to display the image mysite / image.jpg before the field label and a paragraph below the image.
Could anyone please tell me how to use the $html parameter?
THANKS!
Fabiano
Re: insert html elements before a field
Posted: 2020-06-08 11:52
by D Oliveira
fgazza wrote: ↑2020-06-06 20:02
Hello everyone!
I would like to insert a custom text before a field. The text should be formatted in html and precede the field label.
I think the solution is to use $html in the hook file's tablename_dv () function but I have no idea how to use it. For example, I would like to display the image mysite / image.jpg before the field label and a paragraph below the image.
Could anyone please tell me how to use the $html parameter?
THANKS!
Fabiano
I might be wrong because I never used html in that function but your can try echo '<p> html code</p>'; or close and re-open the php syntax like this:
hope it helps, cheers!
Re: insert html elements before a field
Posted: 2020-06-08 12:45
by jsetzer
Hi,
appending custom html to the bottom of DV or prepending html to the top is not hard by just modifying the given $html variable. But here, the challenge is to place the custom html
above the field.
If this is a normal field (and not a lazy loaded lookup) you can do it this way:
file: hooks/TABLENAME.php
Code: Select all
function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args)
{
$fieldname = "resource_type"; // TODO: change $fieldname
$html .= '<p id="my_custom_paragraph" class="well">my <i>custom paragraph</i> with <b>bold</b> text</p>';
$html .= '<script>$j("#my_custom_paragraph").prependTo($j("#' . $fieldname . '").closest(".form-group"))</script>';
// ...
}
Result

- chrome_AUXQ38io6K.png (4.76 KiB) Viewed 3357 times
Inserted above field named "resource_type".
Regards,
Jan
Re: insert html elements before a field
Posted: 2020-06-12 13:44
by fgazza
Many thanks!
with your suggestion I prepared the form correctly (i set my code into div tag and not into p tag because i have several paagraph and an image) but unfortunately if I view the form itself with the "print" option (print view), my custom html code is displayed below the form fields.
I would be grateful for your help.
Re: insert html elements before a field
Posted: 2020-06-12 14:04
by D Oliveira
fgazza wrote: ↑2020-06-12 13:44
Many thanks!
with your suggestion I prepared the form correctly (i set my code into div tag and not into p tag because i have several paagraph and an image) but unfortunately if I view the form itself with the "print" option (print view), my custom html code is displayed below the form fields.
I would be grateful for your help.
could try modifying the tablename_DV.html template in templates folder and see how it goes
Re: insert html elements before a field
Posted: 2020-06-12 14:40
by fgazza
Thank you but as I renew many times my app generating new files by appgini tool i prefer a solution that affect only the hook file.