• Resolved doshareit

    (@doshareit)


    Hello,

    I am facing an issue while I try to store in database the value selected in radio options.

    I’ve implemented a hook in functions.php like this:

    function save_form( $wpcf7 ) {
       global $wpdb;
       $submission = WPCF7_Submission::get_instance();
       $submited['posted_data'] = $submission->get_posted_data();

    I can see all the values in [text] , [textarea], [date] or [select]. However, the [radio] always returns empty:

    Sex:[radio s_sex "Male" "Female"]

    if ($submited['posted_data']['s_sex'] == 'Male')
    		$v_sex = 'M';
    	else
    		$v_sex = 'F';

    do you know what i am doing wrong?

    thx in advance

    https://www.ads-software.com/plugins/contact-form-7-to-database-extension/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Thread Starter doshareit

    (@doshareit)

    Hi Michael,

    Yes, my solution is based on this post. I’ve found a workaround to avoid empty data in radio fields:

    I insert all posted data into an array, and then, serialize/unserialize

    ??

    Hi @doshareit,

    What was your solution?
    I am also trying to find a way to make sure the radio value is not empty, and trying to grab the selected radio value using post_data, but it is not working.

    I am using the code below to send me an email of what the selected radio value is, but it’s giving me nothing. I have tried it with text values, it’s working fine, giving me the text value, but it is not working for the radio button.

    add_action( 'wpcf7_before_send_mail', 'CF7_pre_send' );
    
    function CF7_pre_send($cf7) {
    
    	$submission = WPCF7_Submission::get_instance();
    
      	if ( $submission ) {
    
    	  	if($cf7->title == "Ask a question"){
    	  		$posted_data = $submission->get_posted_data();
    	  	 	$mail = $cf7->prop('mail');
    	  		$radiovalue = $posted_data['card'];
    
    		    $mail['body'] .=  $radiovalue;
    			$cf7->set_properties(array('mail' => $mail));
    		}
      }
    
    }
    Plugin Author Michael Simpson

    (@msimpson)

    @r_imultimedia this is a CF7 question, not a CFDB question. Repost on that forum.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘radio value empty in posted data’ is closed to new replies.