I am new to wordpress php and have a question regarding custom contact form 7 validation.
I have the code below and wish to add this to return the error msg if not selected.
function add_shortcode_metalspurityradio() {
wpcf7_add_shortcode( 'goldkarat', 'metalspurityradio_handler', true );
}
add_action( 'wpcf7_init', 'add_shortcode_metalspurityradio' );
function metalspurityradio_handler( $tag ){
$tag = new WPCF7_FormTag( $tag );
$atts = array(
'type' => 'radio',
'name' => $tag->name,
'list' => $tag->name . '-options' );
$input = sprintf(
'<input %s />',
wpcf7_format_atts( $atts ) );
$datalist = '';
$datalist .= '<div class="goldkaratradio d-flex">';
foreach ( $tag->values as $val ) {
list($radiovalue,$imagepath) = explode("!", $val
);
$datalist .= sprintf(
'<div class="quotetabswrap col-md-1 col-xs-2 p-1">
<label class="quotetabslabel p-1 pb-0 mb-1">
<input type="radio" name="%s" value="%s" class="hideradio" />
<div class="quotetabsshape">
<div id="'.$radiovalue.'" class="quotetabstext">%s</div>
</div>
</label>
</div>', $tag->name, $radiovalue, $radiovalue, $radiovalue
);
}
$datalist .= '</div>';
return $datalist;
}
Just want it to be validated if required is selected
ie:
[goldkarat* metals-purity
"1K"
"2K"
"3K"
"4K"
"5K"
"6K"
"7K"
"8K"
"9K"
]
2
Answers
Hello try the below code it should working with you
the answer of Sayed Mohamed was almost good, I corrected it below because I cannot edit it. then mark his answer as good.