Support » Plugins and Hacks » [Plugin: Contact Form 7] Set include_blank value diff than —

[Plugin: Contact Form 7] Set include_blank value diff than —

Viewing 5 replies - 1 through 5 (of 5 total)
  • Any solution for this?

    I ran into the same issue…there should really be more options for what you want your blank value to be…but I suppose they are trying to keep this plugin as simple to use as possible.

    Solution: I went into your plugins directory wp-content/plugins/contact-form-7/modules/select.php

    This file I edited at line 65 which reads: array_unshift( $labels, ‘—‘ );
    Change this line to read: array_unshift( $labels, ‘Whatever Label You Want’ );

    BOOM: New include_blank text to whatever you want.

    It is better to change the default --- without hacking the plugin php files.

    Add one of the following solutions to your functions.php:

    Simple solution: Replace all --- in all forms with the same Please select... text:

    function my_wpcf7_form_elements($html) {
    	$text = 'Please select...';
    	$html = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $html);
    	return $html;
    add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');

    Complex solution: Replace --- of known select elements with a different text each, you need the names like menu-569 from [select menu-569 include_blank ...] shortcode for this:

    function my_wpcf7_form_elements($html) {
    	function ov3rfly_replace_include_blank($name, $text, &$html) {
    		$matches = false;
    		preg_match('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $html, $matches);
    		if ($matches) {
    			$select = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $matches[0]);
    			$html = preg_replace('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $select, $html);
    	ov3rfly_replace_include_blank('menu-569', 'Choose language', $html);
    	ov3rfly_replace_include_blank('menu-614', 'Choose country', $html);
    	return $html;
    add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');

    Hey Ov3rfly,
    Thanks for your help.

    Im using your script to change the “—” in my form, but when im trying to put two form in the same page, im getting the message-
    Fatal error: Cannot redeclare ov3rfly_replace_include_blank() (previously declared in /home/orkbu/domains/gil.beastserv.com/public_html/hava/wp-content/themes/theme951/GetresForm.php:115) in /home/orkbu/domains/gil.beastserv.com/public_html/hava/wp-content/themes/theme951/GetresForm.php on line 115

    how can i overcome this issue?

    I managed to fix this by taking the “ov3rfly_replace_include_blank”
    function out of the “my_wpcf7_form_elements” function

    there is no reason to place a function inside function in this case.

    hope that will be helpful for someone one day.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Contact Form 7] Set include_blank value diff than —’ is closed to new replies.