Render template shortcodes in form

Yet another ProForms Feature Request :smiley:

I’ve managed to figure this one out (more on that below) but it might be a neat lil feature, unless it’s just me that needs it of course.

I’d like to be able to render template shortcodes inside a form. My current use case is this:

I have a form to book a trip in which you can select Hotels n stuff like that. Now for the hotels, I needed to display them as cards containing the featured image, price, etc. Ultimately just a very styled radio select group.
Initially, I just created those using Bricks and then used JS to populate hidden fields based on the selection.
Later I decided the form was getting a lil long so turning it into a multistepform would be the way to go. Now of course, that doesn’t work with the Hotels rendered outside the actual form and also not for let’s say a spa selection in another step that should also be shown in selectable cards.

This is how I managed to work around it… It’s probably hacky, lacks any kind of properly checking/escaping and also currently just overrides the actual Plugin files (can I override those in my child theme?).

Inside of ProForms.php on line 275 I added:

'shortcode'  => esc_html__('Shortcode', 'bricks'),

to register my field.

Inside of ProForms.php around line 4350 I added:

<?php if ($field['type'] === 'shortcode') { ?>
      <?php echo do_shortcode($init_value); ?>
<?php } ?>

which basically just takes the input of the initial value field and renders the shortcode.

Even if this feature never makes it onto the roadmap, I’d appreciate some pointers from someone who actually knows php, on how to improve this setup a bit :slight_smile:

Also, it would be neat if steps would…

  1. Add a wrapper around the fields contained in a step
  2. Add a class to active steps and / or fields inside an active step (currently solved by adding/removing a class via js, based on the display property set on the step)

EDIT:
managed to refine it a little bit. The field now looks like this:

And inside the template, I basically rebuilt radiobuttons adding all the attributes from the default radio buttons, so that it just works and submits the value without having to pass them into a custom field.
image

image

Lastly, I copied and renamed the whole pro forms file into my childtheme so it won’t get overwritten on the next update. Now I just have to figure out how to properly merge any updates to the forms module.

1 Like

I really like this idea! It will make the form even more flexible. Thanks very much – Propably will add this to my todo even for version 1.0 :wink:

1 Like

Awesome!!! Then I’ll add just one thing that would improve it even more (in my opinion). If we wrap all the fields that are in a step, into a wrapper and give that wrapper a class to show / hide it, instead of setting inline display properties to the fields, we’d be able to add some nice css or js transitions by directly targeting the steps :slight_smile: No idea how involved that is to implement, figured I’d just try my luck in case you have some extra time while working on the forms :wink:

Done. Will be included to the next version :slight_smile:

1 Like

So happy I decided to get Bricksforge :smiley: thanks a lot! :slight_smile:

1 Like