Include_HTML plugin: not-so-neat tricks

A question hoisted from comments:

I really want to use this plugin, seems perfect for me, but it doesnt seem to allow forms to work on the pages that are included. Is this possible? These are forms that would normally post to themselves.

There are options here, none of which is particularly elegant. Include_HTML was written to access content (including content from remote sites), not functionality…

One option is to include an iframe, show the form in that iframe and set the form’s target attribute to that same iframe. So when the form posts, only the iframe is updated. A slight variation of this approach is to write the included page as an AJAX client, so that it posts and updates without refreshing the whole WordPress page. This, by the way, is the approach used by the Contact Form plugin by Takayuki Miyoshi, which you can observe in action on the Contact page of this site.

Another way is to simply POST to the true location of the form and at the end of processing redirect back to the POSTing page (whose URL should be available as $_SERVER['HTTP_REFERER']).

But the most radical solution is simply to rewrite the plugin, requiring it to include() code rather than accessing content via file_get_contents().

This entry was posted in Answers, Technology. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *