Manipulace s údaji v Contact Form 7 před a po odeslání

WordPress Contact Form 7 Hook Unofficial Developer Documentation and Examples »

Changing Form Data Before it is Saved »

Contact Form 7 - form submit change field value »

How to create a mail counter for Contact Form 7 »

Extending the Contact Form 7 Plugin »

[private]

### příklad použitý na http://u904.cz/mimoradna-nabidka-lifebook-a512/
### pocitadlo objednavek odeslanych z CF7

// Define the key to store in the database
define('CF7_COUNTER', 'cf7-counter');
define('CF7_LASTORD', 'cf7-lastord');
define('POCNAB', '200'); // startovni pocet kusu

### Create the shortcode which will read the value from db option
function cf7db_reader(){
        $val = get_option(CF7_COUNTER, POCNAB);  // kdyz neexistuje option v db, vrati startovni pocet
        return $val;
}
add_shortcode('CF7_show', 'cf7db_reader');


### Action performed BEFORE the mail is sent by CF7
function wpcf7_change_mail($form) {
        $formid = $form->id; // gets current form id
        if ($formid == '384') {
          $wpcf7 = WPCF7_ContactForm::get_current(); // get current FORM instance
                $wpcf7data = WPCF7_Submission::get_instance(); // // get current SUBMISSION instance
                if ($wpcf7data) {
                        $formData = $wpcf7data->get_posted_data();
                }
                // Reading a posted value in the form with PHP
                $poc = $formData['pocet']; // nacte hodnotu z prave odeslaneho formulare
                $val = get_option(CF7_COUNTER, POCNAB); // nacte aktualni hodnotu skladu, kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem objednavku.

                // nahrada dat v mailu
                $mail = $wpcf7->prop('mail');

                if($poc > $val): // objednano vic kusu, nez je na sklade, nahradim REPLACER textem
                        $mail['pocet'] = $val; // snizim objednany pocet
                        // doplnim upozorneni do mailu
                        // Find/replace the "special" tag as defined in your CF7 email body
        $mail['body'] = str_replace('REPLACER', "Jelikož jste objednali větší počet (".$poc." ks), než bylo aktuálně k dispozici skladem (".$val." ks), bude objednaný počet snížen na dostupné množství.\n", $mail['body']);
                else: // odstrani REPLACER string
                        $mail['body'] = str_replace('REPLACER', "", $mail['body']);
                endif;

    // Save the email body
    $wpcf7->set_properties(array("mail" => $mail));

                // return current cf7 instance
    return $wpcf7;
        }
}
add_action('wpcf7_before_send_mail', 'wpcf7_change_mail');


### Action performed WHEN the mail is sent by CF7
function cf7_decrement_order_counter($form){
        $formid = $form->id; // gets current form id
        if ($formid == '384') {
          // $wpcf7 = WPCF7_ContactForm::get_current(); // get current FORM instance
                $wpcf7data = WPCF7_Submission::get_instance(); // // get current SUBMISSION instance
                if ($wpcf7data) {
                        $formData = $wpcf7data->get_posted_data();
                }
    $poc = $formData['pocet']; // nacte hodnotu z prave odeslaneho formulare
    $val = get_option(CF7_COUNTER, POCNAB) - $poc; // kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem snizenym o odeslanou objednavku.
                update_option(CF7_COUNTER, $val); // Update the settings with the new count
                update_option(CF7_LASTORD, $poc); // Update the settings with the new count
        }
}
add_action('wpcf7_mail_sent', 'cf7_decrement_order_counter');


### zmena poctu objednanych kusu v databazi odeslanych formularu (Contact Form DB)
function change_cfdb_value($formData){
        $formName = 'A514';
        if ($formData && $formName == $formData->title) {
                $poc = $formData->posted_data['pocet'];
                $val = get_option(CF7_COUNTER, POCNAB);
                if($poc > $val): // objednano vic kusu, nez je na sklade
                        $formData->posted_data['dodavka'] = $val;
                else:
                        $formData->posted_data['dodavka'] = $poc;
                endif;
  }
  return $formData;
}
add_filter('cfdb_form_data', 'change_cfdb_value');


### Change content of Ordering Page
function formRemover($content) {
                if(!is_feed() && !is_admin() && is_page(381)) {
        $val = get_option(CF7_COUNTER);
        if($val == 0):
                                $content = str_replace('<h3>Tak neváhejte!</h3>', '<h3>Prodej byl ukončen.</h3>', $content);
        else:
                                $content = str_replace('</ul>', '</ul><h3>Objednávkový formulář</h3><h3></h3>[contact-form-7 404 "Not Found"]', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'formRemover');


### Change content of Thank You Page
function orderAlert($content) {
                if(!is_feed() && !is_admin() && is_page(385)) {
        $val = get_option(CF7_COUNTER, POCNAB);
        $poc = get_option(CF7_LASTORD, 0);
        $roz = $poc-$val;
        if($val <= 0):
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Jelikož jste objednali <b>větší počet</b> kusů, než bylo aktuálně k dispozici skladem, byl Vámi objednaný počet <b>snížen</b>.</p><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                                update_option(CF7_COUNTER, 0); // vynulovani pocitadla
                                update_option(CF7_LASTORD, 0); // vynulovani pocitadla
        else:
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'orderAlert');


### pridani odkazu na blog page k excerptum
function excerpt_read_more_link($output) {
global $post;
return $output . '<a href="'. get_permalink($post->ID) . '"> Více »</a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');


#############################
#### ve starších verzích CF7
#############################

// Define the key to store in the database
define('CF7_COUNTER', 'cf7-counter');
define('CF7_LASTORD', 'cf7-lastord');
define('POCNAB', '260'); // startovni pocet kusu

### Create the shortcode which will read the value from db option
function cf7db_reader(){
        $val = get_option(CF7_COUNTER, POCNAB);  // kdyz neexistuje option v db, vrati startovni pocet
        return $val;
}
add_shortcode('CF7_show', 'cf7db_reader');


### Action performed BEFORE the mail is sent by CF7
function wpcf7_change_mail($formData) {
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
                // Reading a posted value in the form with PHP
                $poc = $formData->posted_data['pocet']; // nacte hodnotu z prave odeslaneho formulare
                $val = get_option(CF7_COUNTER, POCNAB); // nacte aktualni hodnotu skladu, kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem objednavku.
                $bod = $formData->mail['body'];

                if($poc > $val): // objednano vic kusu, nez je na sklade, nahradim REPLACER textem
                        $formData->posted_data['pocet'] = $val; // snizim objednany pocet
                        // doplnim upozorneni do mailu
                        $bod = str_replace('REPLACER', "Jelikož jste objednali větší počet (".$poc." ks), než bylo aktuálně k dispozici skladem (".$val." ks), byl objednaný počet snížen na dostupné množství.\n", $bod);
                        $formData->mail['body'] = $bod;
                else: // odstrani REPLACER string
                        $bod = str_replace('REPLACER', '', $bod);
                        $formData->mail['body'] = $bod;
                endif;
        }
}
add_action('wpcf7_before_send_mail', 'wpcf7_change_mail');


### Action performed WHEN the mail is sent by CF7
function cf7_decrement_order_counter($formData){
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
    $poc = $formData->posted_data['pocet']; // nacte hodnotu z prave odeslaneho formulare
    $val = get_option(CF7_COUNTER, POCNAB) - $poc; // kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem snizenym o odeslanou objednavku.
                update_option(CF7_COUNTER, $val); // Update the settings with the new count
                update_option(CF7_LASTORD, $poc); // Update the settings with the new count
        }
}
add_action('wpcf7_mail_sent', 'cf7_decrement_order_counter');


### zmena poctu objednanych kusu v databazi odeslanych formularu (Contact Form DB)
function change_cfdb_value($formData){
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
                $poc = $formData->posted_data['pocet'];
                $val = get_option(CF7_COUNTER, POCNAB);
                if($poc > $val): // objednano vic kusu, nez je na sklade
                        $formData->posted_data['dodavka'] =     $val;
                else:
                        $formData->posted_data['dodavka'] =     $poc;
                endif;
  }
  return $formData;
}
add_filter('cfdb_form_data', 'change_cfdb_value');


### Change content of Ordering Page
function formRemover($content) {
                if(!is_feed() && !is_admin() && is_page(60)) {
        $val = get_option(CF7_COUNTER);
        if($val == 0):
                                $content = str_replace('<h3>Tak neváhejte!</h3>', '<h3>Prodej byl ukončen.</h3>', $content);
        else:
                                $content = str_replace('</ul>', '</ul><h3>Objednávkový formulář</h3><h3></h3>[contact-form-7 404 "Not Found"]', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'formRemover');


### Change content of Thank You Page
function orderAlert($content) {
                if(!is_feed() && !is_admin() && is_page(72)) {
        $val = get_option(CF7_COUNTER, POCNAB);
        $poc = get_option(CF7_LASTORD, 0);
        $roz = $poc-$val;
        if($val <= 0):
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Jelikož jste objednali <b>větší počet</b> kusů, než bylo aktuálně k dispozici skladem, byl Vámi objednaný počet <b>snížen</b>.</p><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                                update_option(CF7_COUNTER, 0); // vynulovani pocitadla
                                update_option(CF7_LASTORD, 0); // vynulovani pocitadla
        else:
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'orderAlert');

[/private]

Ve verzi CF7 4 a vyšší se způsob přebírání dat z formuláře změnil:

/* WPCF7_ContactForm object no longer has a posted_data property. */
$posted_data = $contact_form->posted_data; // Tohle už nefunguje

/* Use WPCF7_Submission object's get_posted_data() method to get it. */
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {
    $posted_data = $submission->get_posted_data();
}

Jak změřit odeslání kontaktního formuláře CF7 v Google Analytics

V pluginu Contact Form 7 existuje pole Additional Settings, do kterého lze přidat kód pro měření

on_sent_ok:"_gaq.push(['_trackPageview', '/form-odeslan']);"

a v nastavení cíle v GA se pak /form-odeslan vloží do pole pro sledované URL (které ve skutečnosti neexistuje), match type = head match.

Viz též:
Google Analytics Goals with Contact Form 7: The Right Way »
Google Analytics’s tracking function »
Stránka pluginu Contact Form 7 »

Přidávání polí do formuláře pro komentář

There are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains how to add an input field, store the data in the database and how to display the additional data in your blog if your theme uses the comment_form() function provided by WordPress.

Celý článek »

Kontaktní formulář, formulářové pluginy

Contact Form 7
http://wordpress.org/…tact-form-7/
http://contactform7.com/

Contact Form 7 can manage multiple contact forms, plus you can customize the form and the mail contents flexibly with simple markup. The form supports Ajax-powered submitting, CAPTCHA, control question, Akismet spam filtering and so on.
Můžete založit třeba sto různých formulářů se stovkou různých obsahů. Takže například jeden bude obsahovat textová pole a rozjížděcí menu, jiný zase check buttony a potvrzovací tlačítka nebo všechno dohromady. Uděláte si takový formulář, jaký budete chtít. Čeština k dispozici.

Optimize and style Contact Form 7

How To Customize The Style Of Contact Form 7 To Match Your Website »

Stylování Contact Form 7 do podoby ElegantThemes Contact Form »

Přidání funkcí onfocus a onblur

Contact Form 7 to Database Extension
http://wordpress.org/…e-extension/

Changing Form Data Before it is Saved »

Saves form submissions to the database that come from Contact Form 7.

Alternative

Save Contact Form 7
https://wordpress.org/…tact-form-7/

Save Contact Form 7 data. Sort, search & export it in CSV+PDF. Unlike CFDB, the plugin itself is very smart and creates column name from your Contact Form 7 Field names.

Jquery Validation For Contact Form 7
https://wordpress.org/…tact-form-7/

This plugin adds jquery validation to your contact form 7. You will be able to validate extra validation rules like: url, date, credit card, phone number in the contact form 7 fields.

Frontend Registration - Contact Form 7
Frontend Registration – Contact Form 7

By using this plugin you can create front-end registration form by which registered user will be register as a subscriber role in WordPress.

Contact Form 7 MailChimp Extension
https://wordpress.org/…p-extension/
Simple way to integrate MailChimp mailing lists to Contact Form 7. Save your subscribers in a proper mailing list.

Contact Form 7 - Success Page Redirects
https://wordpress.org/…e-redirects/
An add-on for Contact Form 7 that provides a straightforward method to redirect visitors to success pages or thank you pages.

Contact Form 7 Modules
http://wordpress.org/…m-7-modules/
Add useful modules such as hidden fields and "send all fields" to the Contact Form 7 plugin. You can also choose to have the value of the hidden field dynamically populated in your form when you are contacted.

Contact Form 7 Select Box Editor Button
https://wordpress.org/…screenshots/
Add a contact form link into article text. For contact forms where the recipient can be chosen in a select box.

Contact Form 7 Dynamic Text Extension
http://wordpress.org/…t-extension/

CF7 DTX lets you create pre-populated fields based on other values. Some examples might include:

  • Auto-filling a URL
  • Auto-filling a Post ID, title, or slug
  • Pre-populating a Product Number
  • Referencing other content on the site
  • Populating with post info
  • Populating with user info
  • Populating with custom fields
  • Any value you can write a shortcode for

You can also choose to have the value of the hidden field dynamically populated in your form when you are contacted.

Další nastavení (Bcc:, Google Analytics) »

Manipulace s údaji v Contact Form 7 před a po odeslání »

Honeypot Module for Contact Form 7 WordPress Plugin »

Fórum podpory »

Configuring Contact Form 7 to Work Perfectly With a Twentyten Child Theme »

Když máte problém s odesíláním »
Další rady, co dělat při selhání »

FAQ »

Alternativy:

Caldera Forms - Drag and drop responsive WordPress form builder
https://wordpress.org/…ldera-forms/

Caldera Forms' visual editor simplifies form building for WordPress. Set up your form with multiple columns, add additional pages, and funnel user responses with conditional logic to get more robust data and relevant information from your customers and site visitors. Anti-spam, AJAX, notification emails, and database entry tracking are enabled by default.

Visual Form Builder
https://wordpress.org/…orm-builder/

A plugin that allows you to build and manage all kinds of forms for your website in a single place. Drag-and-drop reordering, automatically stores form entries in your WordPress database, manage form entries in the WordPress dashboard, export entries to a CSV file, send form submissions to multiple emails, jQuery Form Validation.

Intouch
http://wordpress.org/…ins/intouch/
http://adahas.com/work/intouch/

This is a plugin for WordPress which allows you to insert a custom build contact form, which on submission will send the information via email.
Features
* Customizable contact form with variable number of fields.
* Ability to specify mandatory fields.
* Can forwarded to any email address.
* Instant insertion using the Quicktag.
* Complete customization from admin panel.
* Instant submission using AJAX (for JavaScript supported browsers), and minimum overhead.
* Fall-back to standard HTML form submission, if JavaScript is not supported.
* Conforms to XHTML 1.0 Strict / XHTML 1.1
* Compatible to be served as application/xhtml+xml

cforms II
http://www.deliciousdays.com/cforms-plugin

cforms is a plugin for WordPress, offering convenient deployment of multiple contact forms throughout your blog or even on the same page. The form submission utilizes AJAX, falls back, however, to a standard method in case AJAX/Javascript is not supported or disabled.

Fast Secure Contact Form
http://wordpress.org/…ontact-form/

This plugin allows a webmaster to easily create and add contact forms to WordPress. The contact form will let the user send emails to a site's admin, and also send a meeting request to talk over phone or video. An administration panel is present, where the webmaster can create and preview unlimited forms.

Features a super easy admin panel, multi-form feature, autoresponder, no templates to mess with, and an option to redirect visitors to any URL after the message is sent. Includes CAPTCHA and Akismet support to block all common spammer tactics. Spam is no longer a problem. You can add extra fields of any type: text, textarea, checkbox, checkbox-multiple, radio, select, select-multiple, attachment, date, time, hidden, password, and fieldset.

Formidable Forms
http://wordpress.org/…/formidable/

Quickly and easily build forms with a simple drag-and-drop interface and in-place editing. There are dozens of form-building plugins out there to create forms, but most are confusing and overly complicated. With Formidable, it is easy to create forms within a simple drag-and-drop interface.

Přehled pluginů pro kontaktní formuláře »

Publikování příspěvků nepřihlášenými návštěvníky

Možnost vkládání příspěvků neregistrovanými (ale i registrovanými) uživateli, bez toho, aby museli vstupovat do administrace WordPressu.

Form to Post
Form to Post

Create a WP Post from a Form Submission. Create a form using Contact Form 7, Fast Secure Contact Form, or just a plain form, be sure to name your fields correctly, then the form submission will be sent to a post.

DJD Site Post
https://wordpress.org/…d-site-post/

Write and edit a post at the front end without leaving your site. Add a (responsive) form to your site to write a post without having to go into the admin section. It allows for 'anonymous' or 'guest' posting (not logged in users). Captcha for guest posts. Now the plugin has a widget to include the form in a sidebar.

Alternativy

TDO Mini Forms
http://wordpress.org/…-mini-forms/
http://thedeadone.net/…ress-plugin/

With TDO Mini Forms you can set up forms for visitors to fill out that are used to create posts.

This plugin allows you to add highly customisable forms that work with your Theme to your website that allows non-registered users and/or subscribers (also configurable) to submit posts. The posts are kept in "draft" until an admin can publish them (also configurable).

It can optionally use Akismet to check if submissions are spam.

TDO Mini Forms can be used to create "outside-the-box" uses for WordPress, from Contact Managers, Ad Managers, Collaborate Image Sites, Submit Links, Forum etc.

Použito pro přidávání příspěvků nepřihlášenými návštěvníky na serveru anagrammer.org.

WP User Frontend
http://wordpress.org/…er-frontend/

Gives ability to the user to create new post, edit post, edit profile from site frontend. So users doesn't need to enter the admin panel. Everything they need to do can be done from the frontend.

Guest Post
http://wordpress.org/…-guest-post/

A simple plugin that allows you to accept, edit, & publish guest posts to your blog without writers having to login to your WordPress Admin area.

One Quick Post
http://wordpress.org/…-quick-post/

One Quick Post is a WordPress/Bud­dyPress plugin that allows you to enable frontend posting on your blog; including for non-registered users. Enables building custom forms. Works with custom post types, custom taxomies, custom fields (meta keys).

Frontend Publishing
https://wordpress.org/…-publishing/ Allow your registered members to submit, edit and delete posts from the frontend.
This lightweight plugin allows you to accept guest posts/articles without giving your members access to the sensitive WordPress control panel. It will automatically filter out all the posts that don't meet the submission guidelines of your website. It can be a huge time saver if you have a very popular blog or article directory.

Really Simple Guest Post Plugin
https://wordpress.org/…-guest-post/

Really Simple Guest Post Plugin will help you to generate a guest posting form in the simple and easiest way. Submitted posts will be included with author name, email address, author url, post title, description, categories and keyword tags.

Frontend Uploader
http://wordpress.org/…nd-uploader/

This plugin is a simple way for users to submit content to your site. The plugin uses a set of shortcodes to let you create highly customizable submission forms to your posts and pages. Once the content is submitted, it is held for moderation until you approve it. It’s that easy!