WordPress.org

Ready to get started?Download WordPress

Forums

Grunion Contact Form
Contact Form has an incompatibility with SFC (2 posts)

  1. Samuel Wood (Otto)
    Tech Ninja
    Posted 3 years ago #

    This code in the plugin prevents it from displaying the contact form when used with some of my SFC plugins:

    if ( $id == $contact_form_last_id )
    		return;
    	else
    		$contact_form_last_id = $id;

    I sorta know why it's doing this, but basically it prevents the form from being generated more than once in a row.

    One of the things SFC does is to get the content of the post (while in the head) using code like this:

    $content = get_the_content();
    $content = apply_filters('the_content',$content);

    The point of doing this is specifically to let shortcodes and other plugins do their processing so that it can get the final post content as plain-old HTML. Then it processes through that content looking for things like images, in order to build proper meta-data to send to Facebook.

    However, because the Grunion Contact Form refuses to produce the form again (thinking that it has already done so), the form doesn't show up later in the page, when the theme is actually displaying the content.

    Commenting out the code from GCF fixes the issue and the form displays just fine, however now there is a problem in that, because the plugin is actually using the shortcode to do something of substance (process the resulting form's $_POST, send an email, etc), now it will do that multiple times per page (three times, in my case).

    There's several possible ways to fix this. One of them is to simply move the problem code down further in the file, to near where it checks the $_POST variable. Thus, the shortcode will always generate the form (as it should), but will only process the resulting POST data once.

    On a higher level, using a shortcode to *do something* is a bad idea in general. Shortcodes should only return the data that's supposed to be changed in the content, not take actual actions. You should move the POST processing bits out into some other function entirely. Probably hooked to the init action. This is a bit more effort, but it will prevent this kind of thing from happening in the future, and you will be able to eliminate that last_id global variable entirely.

    http://wordpress.org/extend/plugins/grunion-contact-form/

  2. Joseph Scott
    Member
    Plugin Author

    Posted 3 years ago #

    I'll make sure that gets looked at, sounds like we could definitely improve from what we have so far.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic