WordPress.org

Forums

Contact Form 7
Set include_blank value diff than --- (6 posts)

  1. idovecer
    Member
    Posted 3 years ago #

    Is it possible to set blank value?
    Instead of default "---" to stand something else?

    On one form I do have two different "---" inlcude_blank forms, which each must have different value form example:

    --- > Choose languale
    --- > Choose country

    Thank you?

    http://wordpress.org/extend/plugins/contact-form-7/

  2. kremerdesign
    Member
    Posted 2 years ago #

    Any solution for this?

  3. bmoore2
    Member
    Posted 2 years ago #

    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.

  4. Ov3rfly
    Member
    Posted 2 years ago #

    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');
  5. chryaner
    Member
    Posted 2 years ago #

    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?

  6. chryaner
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic