Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to set Form Field from shortcode? #92

Open
malcolmgroves opened this issue Jul 4, 2019 · 3 comments
Open

Possible to set Form Field from shortcode? #92

malcolmgroves opened this issue Jul 4, 2019 · 3 comments
Assignees
Labels

Comments

@malcolmgroves
Copy link

malcolmgroves commented Jul 4, 2019

I currently use the form shortcode to embed forms in WP pages. All good. However, I have a lot of product pages that all need effectively the same form on it, the only thing that varies is the product page it is on.

Ideally what I'd like is to be able to have a hidden field in the form that indicates product name. Then when I embed the form I could set that field in the shortcode. Then in the campaign behind the form I can check that field value and do the product specific different behaviours.

Is this possible? The alternative seems to be having one form per product page, which works but is a lot of duplication for each product.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@shulard shulard self-assigned this Jul 5, 2019
@shulard
Copy link
Collaborator

shulard commented Jul 5, 2019

Hello !

If you are not afraid to write some code it's possible yes :-)

Currently, this plugin is "just" providing some shortcodes and interpret them only in the post content but you can use those shortcodes outside of the post body itself.

You'll need to update your product page PHP template to inject the shortcode in it (and interpret it). Since you'll need to automate script injection, you have 2 choices.

For example a code like this can work anywhere in your PHP code when you have the Mautic plugin activated :

<?= do_shortcode('[mautic type="form" id="1"]'); ?>

Another solution can be to inject the corresponding script tag manually in you theme file. Here is the example from inside the plugin : https://github.com/mautic/mautic-wordpress/blob/master/shortcodes.php#L81

@malcolmgroves
Copy link
Author

Thanks @shulard. I don't mind writing a bit of code if needed, but I think I need a bit more of a hint, sorry.

I can see how the shortcode injects the script tag with the form id, but can't see how to set the value of the field. Are there additional attributes I should pass into it to do that? Any pointers to other places in the code that might make it clearer?

Cheers
Malcolm

@shulard
Copy link
Collaborator

shulard commented Jul 10, 2019

Hum, that's a good question !

From my side I haven't handled that case in any of my project...
I checked the documentation and found that link (https://www.mautic.org/docs/en/forms/manage_forms.html#pre-populate-a-form-field-value) but can't make it works during my tests...

If you find others resources, I'll be glad to help !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants