Quantcast
Channel: WordPress.org Forums » [Contact Form 7] Support
Viewing all articles
Browse latest Browse all 49500

Corrado Prever on "[Plugin: Contact Form 7] validation issue in custom field and custom shortcode"

$
0
0

I noted an error and make a correction but still does not work ....

Here my cf7 custom module

<?php

/* parte per trovare i mesi in italiano in php */

 function mesi_anno2() {
 $mese = array ("Gennaio-", "Febbraio-", "Marzo-", "Aprile-", "Maggio-", "Giugno-", "Luglio-", "Agosto-", "Settembre-", "Ottobre-", "Novembre-", "Dicembre-");
 $str="";
        for($i = 0; $i < 24; $i++) {
        $time = mktime(0, 0, 0, date('n') - $i);
        $str .="<option value=".$mese[(date("n", $time)-1)].date("Y", $time).">".$mese[(date("n", $time)-1)].date("Y", $time)."</option>";
    }
  return $str;
   } 

/* parte per inserire lo shortcode */

wpcf7_add_shortcode('custom_date',  'wpcf7_custom_date_shortcode_handler', true);
wpcf7_add_shortcode('custom_date*', 'wpcf7_custom_date_shortcode_handler', true);

function wpcf7_custom_date_shortcode_handler($tag) {

    if (!is_array($tag)) return '';

    $name = $tag['name'];
    if (empty($name)) return '';

	$validation_error = wpcf7_get_validation_error( $tag->name );

	$class = wpcf7_form_controls_class( $tag->type );

	if ( $validation_error )
		$class .= ' wpcf7-not-valid';

      $html = '
	  <select name="'.$name.'">
 	  <option value="">---</option>
 	  '.mesi_anno2().'
 	  </select>';

return $html;
}

add_filter('wpcf7_custom_date',  'custom_date_filter', 10, 2);
add_filter('wpcf7_custom_date*', 'custom_date_filter', 10, 2);  

 function wpcf7_custom_date_filter( $result, $tag )

{ 

	$tag = new WPCF7_Shortcode( $tag );
 	$name = $tag->name;
 	$value = isset( $_POST[$name] );

	if ( 'custom_date*' == $tag->type ) {
		if ( '' == $value ) {
			$result['valid'] = false;
			$result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
		}
	}

	return $result;
}

?>

Viewing all articles
Browse latest Browse all 49500

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>