Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've fairly used CF7 but I haven't found a work-around or a module to be able to dinamically build a form and then use the CF7 plugin to validate and send it.

In my case, I am using custom fields to build a form in a template. How can I send that template as if it were a CF7 form?

EDIT: I am adding a bounty, requirement for correct answer is how to use CF7's validation, ajax send and locale (with WPML) functions in a partly or completely PHP-generated form. The form I want to send is here.

            $products = get_field('products'); 
            foreach($products as $product):
                $id = $product['id'];
                    <td class="name"><?=$product['name'];?></td>
                    <td class="description"><?=$product['description'];?></td>
                    <td class="quantity">
                        <input type="text" size="4" name="quantity-<?=$id;?>" id="quantity-<?=$id;?>" />
            <label for="your-name"><?=__('Your Name');?></label>
            <input name="your-name" type="text" />
            <label for="your-email"><?=__('Your Email');?></label>
            <input name="your-email" type="text" />
            <input type="submit" value="<?=__('Send');?>" />
share|improve this question
post your code. –  Bainternet Dec 9 '11 at 21:00
added code, and the link to the page is at the end of the description. need to link this generated form to CF7's validate and ajax send. –  Naoise Golden Dec 9 '11 at 21:21
not sure why you need this as a separate form. CF7 can read passed GET and POST. it can also read custom fields from post ... if you prefer not handling code directly, there are also plugins to handle dynamic generation for cf7, a good one can be : sevenspark.com/free-stuff/… . you just need to write a small shortcode function .. –  krembo99 Dec 10 '11 at 6:08
Same here, if the form is generated by your custom function, why would you want to send it by CF7, and since the only validation CF7 has is checking if the required fields are not empty, i really see no reason for that, unless you care to explain? –  Bainternet Dec 10 '11 at 9:51
CF7's validation goes beyond checking if a required field is empty. I just don't want to re-invent the wheel by creating another send function and another validation function if CF7's is good enough. I have already seen this extra plugin, and adding shortcodes in the post doesn't suite, since I am generating the fields in the php template. @krembo99 what do you mean CF7 can read passed GET and POST? Thanks for your comments –  Naoise Golden Dec 10 '11 at 16:46
show 1 more comment

2 Answers 2

up vote 0 down vote accepted

Well I guess what you should to is quite simple include the scripts for cf7 and then make sure the selectors inside the script works for yours aswell. start of with creating a div that wraps ur form give it the class wpcf7, second of all give ur submit button the class wpcf7-submit, and depending on what your validating you give the diffrent inputs diffrent classes and on top of that you have to create some extra divs so it'll be able to show the error messages

<div class="wpcf7-response-output wpcf7-display-none"></div>

for example to validate an email adress u give it the class


When you've done this things and it still doesn't work, it means that some selector failed, and you can easy track which one by opening the javascript console in whatever brower you use and check for the error

share|improve this answer
It seems so obvious I'm ashamed it didn't occur to me. Have you had chance to test if it works? –  Naoise Golden Dec 15 '11 at 11:51
I havent but im sure it will work –  Breezer Dec 15 '11 at 12:00
It worked, there are still some perks to work out but definitely an interesting path to follow. –  Naoise Golden Jan 31 '12 at 11:52
add comment

If I was you I would use the Gravity Forms plugin, it will save you a lot of problems rather than creating a custom form.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.