Pulling it all together One tiny cforms II hack required

You'll recall that we set up our registration link to pass the name of the event in the URL via a GET call, sometimes called a variable string, to the Registration form.

Right now, there is no way that the cforms administration panel will pick up that variable, but there's a quick, and fairly commonly used "hack" for cforms to make sure you can pass your own custom variables to the form.

cforms II creates little-bracket-enclosed template names for the variables it can pick up, like adding the variable template: {Title} will display post or page title that the form is on. We want to pass it a post title from another page (rather than having to manually add this form to every Event post), so we'll add our own variable template to the cformsII plugin.

Customizing a plugin? Keep copious notes!

WordPress and jQuery developers usually keep updating and refining their plugins. Your best bet is to try to find a solution that doesn't require you to edit the actual plugin source files. However, as in this case, if you find you do edit a plugins source file, add your own customization-readMe.txt file to the directory and keep detailed notes of what you amended or edited in the plugin. When the developer releases and upgrades their plugin, especially WordPress plugins that sometimes need updating to keep up with the current WordPress core version, you'll lose your amendments and hacks when you update the plugin. Your notes will make it easy to reintegrate them.

In the cforms II plugin directory, locate the lib_aux.php file. Around line 421, just after code that looks like ...$m = str_replace( '{blogname}',... add this line of code:

$m = str_replace( '{Event}', esc_attr($_GET['evnt']), $m );

Then, in the cforms administration panel for my Registration form, we can now add the {Event} variable to the Event field that I added to the lib_aux.php page in the plugin. Let's also make sure the field is set to "read only".

Just for clarity, I'd like the event name to show up in the header of the form as well. The header is not part of cforms, but part of the page template. In my theme directory, I'll open up registration-page . php and next to the header's the_title () template tag on line 41, I'll add the following code:

<h2><?php the_title(); ?> for: <?php $evnt = esc_attr($_GET['evnt']); echo $evnt;?></h2>

When the form launches, you'll now see the name of the event in the header and in the Event field, which is set to read only and not editable by the user. Now when the form is submitted and e-mailed to the administrator, it's clear what event the registration is for.

Register for: Find Out More About Us rPlease fill out the following. * = Required-

The Event : I Find Out More About Us

Your Name* (required)

Emoi]* I_I (vaiid email required)

We now have an Event page that shows the user's upcoming events and lets them seamlessly register for those in a form that loads in a modal window as planned. Great job! Let's see about making this experience even better.

Blogging For Business

Blogging For Business

Download this Guide And Discover How Start And Run Your Very Own Successful Business Blog. Always Wanted To Start Your Own Blog?

Get My Free Ebook


Post a comment