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

Contact Form: Dynamic attributes lost when submitting form, when using do_shortcode #3187

Closed
webservices-nm opened this issue Dec 18, 2015 · 5 comments · Fixed by #3188
Closed
Assignees
Labels
[Feature] Contact Form [Type] Bug When a feature is broken and / or not performing as intended

Comments

@webservices-nm
Copy link

I know there have been several other threads discussing this, but I can verify that trying to dynamically change the 'to' address of a Jetpack contact-form shortcode in a do_shortcode situation fails. The dynamic 'to' address isn't recognized. To repeat, try something like the following in your PHP:

echo do_shortcode( "[contact-form to='".$dynamic_user_email_addy."' subject='Custom Subject'][contact-field label='Your Name' type='name' required='1'/][/contact-form]" );

The custom 'to' attribute gets lost in the function process_form_submission. The shortcode is re-created, but the attributes don't come along with it.

I fixed the issue by
a) Saving the attributes via update_post_meta() in the store_shortcode function, like the shortcode content already is.
b) Retrieving those attributes in the process_form_submission function using get_post_meta(), and then re-inserting the attributes into the shortcode just before do_shortcode() is run again.

I've tested my solution repeatedly and can verify it works. However, the whole process seems tortured. The do_shortcode function is being called twice. So while my 10 lines of code definitely fixes the surface problem, there might be a more elegant solution by simplifying the whole process. My fix feels like a band-aid, albeit a pretty good one.

I'm attaching my edited version. I made a pull request months ago, but nothing ever happened with it. However, I can make another pull request if it will help.

grunion-contact-form.php.zip

@kraftbj
Copy link
Contributor

kraftbj commented Dec 18, 2015

@stdangerous -- To help cross-link everything, which pull request did you make months ago that went stale? I couldn't find one after a quick search.

@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Contact Form labels Dec 18, 2015
@jeherve jeherve added this to the 4.0 milestone Dec 18, 2015
@jeherve jeherve changed the title (Re-opened) contact-form shortcode in do_shortcode situation loses attributes Contact Form: Dynamic attributes lost when submitting form, when using do_shortcode Dec 18, 2015
@jeherve jeherve modified the milestones: Community, 4.0 Dec 18, 2015
@webservices-nm
Copy link
Author

HI @kraftbj and @jeherve , I don't make many pull requests, so forgive me if I don't have the nomenclature correct, but my list of pull requests says #1 on Aug 10, 2015. - https://github.com/WebServicesManagement/jetpack/pulls

Looking at it now, maybe that just went to my fork? Apologies for my lack of experience.

screen shot 2015-12-18 at 11 33 13 am

@kraftbj
Copy link
Contributor

kraftbj commented Dec 18, 2015

@stdangerous GitHub's website for making edits and submitting PRs is really confusing. I've done that same thing before too. It did only get submitted to your fork, so we never saw it :-(. Thanks for your patience!

WebServicesManagement#1

@webservices-nm
Copy link
Author

@kraftbj Thanks for all the tireless work you guys put in! Any estimated timeline on 4.0?

@jeherve
Copy link
Member

jeherve commented Dec 18, 2015

I created #3188 so we can test and discuss your changes.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Contact Form [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants