I’m trying to insert custom html directly into a form, in order to create a question for users to answer.
Specifically, I have a function that looks up the current timezone options (they change occasionally), and then generates an HTML element with tidy value labels that can be written into the database (such that users can later be shown things appropriate to their timezone). So if someone chooses “(UTC -08:00) America/Anchorage” it would store “America/Anchorage” as the value to write to the db, which is a meaningful timezone name.
I’ve tried outputting that function as dynamic data into a Bricks selector element, but it puts all of the options as one VERY long string option. Also it uses the random Bricks value key which isn’t a meaningful timezone string.
I’ve wasted a whole day trying to find ways to bodge this. I’ve tried
writing filters that read the_content and dynamically insert my code to get rid of a placeholder. That doesn’t work on a single page because there is no loop, and it got complicated when I tried to force the single page into a loop.
setting a ‘wp_insert_post_data’ hook to edit the html of the post when it gets saved or updated. That doesn’t seem to apply to the Bricks version of a post, only the WP version.
This is driving me nuts.
How do I tell Bricks to insert my custom HTML into the middle of a form? It doesn’t seem like it should be hard!
What form? HTML, or a plugin?
If you have a code snippet to fetch the options, I would:
Create a form with select drop-down. INSPECT to double-check html of field.
Extend your snippet to loop through the array and turn it into an HTML list, then append that to the form field with JS.
Thanks for the suggestion. I’m pretty worthless with javascript so that would be a stiff order, but I found this helpful page that shows you the code to create a form with HTML and insert it as a short code, so I took this and customized the form contents:
Really though Bricks needs an element, like Gutenberg’s, that lets you insert your own HTML directly.
I would create a template, insert just a code block, paste the HTML in, save it… and then insert that template wherever you want the form (you can save blocks as templates to use anywhere you want). If it needs PHP, you can use that in a code block too.
you can do that? Whenever I experiment with the Bricks code blocks, it doesn’t execute the code, it just displays the code itself on the front page. If I put my HTML for a form into one, readers wouldn’t see radio buttons (or whatever) they would get a mess of HTML tags, all in their angle brackets, and they would see “if( $foo ) {”, etc.
Is there a way to get the code to execute instead of being displayed?