how to get radio button, checkbox value in csv using ajax and php?
<p>I have a form field and a submit link. i'm generating csv through my php code. the code working fine but the main problem is i'm not able to get checked checkbox, radio button in csv. I'm using ajax and php.</p>

<p>Here is my html code </p>

<pre><code>    &lt;div class="form-style" id="contact_form"&gt;
        &lt;div id="contact_results"&gt;&lt;/div&gt;
        &lt;div id="contact_body"&gt;

         &lt;input type="radio" id="male" name="gender" required="true" value="Male"&gt;
         &lt;label for="male"&gt;&lt;span&gt;&lt;/span&gt;M&lt;/label&gt;
         &lt;input type="radio" id="female" name="gender" required="true" value="Female"&gt;
         &lt;label for="female"&gt;&lt;span&gt;&lt;/span&gt;F&lt;/label&gt;
         &lt;input type="radio" id="&lt;18" name="age" required="true" value="&lt;18"&gt;
         &lt;label for="&lt;18"&gt;&lt;span&gt;&lt;/span&gt;&lt;18&lt;/label&gt;
         &lt;input type="radio" id="18-25" name="age" required="true" value="18-25"&gt;
         &lt;label for="18-25"&gt;&lt;span&gt;&lt;/span&gt;18-25&lt;/label&gt;

         &lt;input type="checkbox" id="men_fashion" name="Intrest" required="true" value="Men’s Fashion"/&gt;
         &lt;label for="men_fashion"&gt;&lt;span&gt;&lt;/span&gt;Men’s Fashion&lt;/label&gt;
         &lt;input type="checkbox" id="women_fashion" name="Intrest" required="true" value="Women’s Fashion"/&gt;
        &lt;label for="women_fashion"&gt;&lt;span&gt;&lt;/span&gt;Women’s Fashion&lt;/label&gt;
        &lt;input type="checkbox" id="home_decor" name="Intrest" required="true" value="Home Decor"/&gt;
        &lt;label for="home_decor"&gt;&lt;span&gt;&lt;/span&gt;Home Decor&lt;/label&gt;
        &lt;input type="checkbox" id="gaming" name="Intrest" required="true" value="Gaming"/&gt;
        &lt;label for="gaming"&gt;&lt;span&gt;&lt;/span&gt;Gaming&lt;/label&gt;
        &lt;input type="checkbox" id="toys" name="Intrest" required="true" value="Toys"/&gt;
        &lt;label for="toys"&gt;&lt;span&gt;&lt;/span&gt;Toys&lt;/label&gt;

        &lt;a class="submit"&gt;&lt;i class="fa fa-check-circle"&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;/div&gt;
        &lt;/div&gt;
</code></pre>

<p>Here is jquery Ajax</p>

<pre><code>$(document).ready(function() {
    $(".submit").click(function() {        
        var proceed = true;  
        $("#contact_form input[required=true]").each(function(){
            $(this).css('border-color',''); 
            if(!$.trim($(this).val())){ 
                $(this).css('border-color','red'); 
                proceed = false; 
            }
        });

        if(proceed) //everything looks good! proceed...
        {
            //get input field values data to be sent to server
            post_data = {
                'user_name'     : $('input[name=username]').val(), 
                'Gender'    : $('input[name=gender]').val(), 
                'Age'  : $('input[name=age]').val(), 
                'Intrest'  : $('input[name=Intrest').val(), 
                //'subject'       : $('select[name=subject]').val(), 
                //'msg'           : $('textarea[name=message]').val()
            };

            //Ajax post data to server
            $.post('post.php', post_data, function(response){  

            });
        }
    });

    //reset previously set border colors and hide all message on .keyup()
    $("#contact_form  input[required=true]").keyup(function() { 
        $(this).css('border-color',''); 
        $("#result").slideUp();
    });
});
</code></pre>

<p>Here is my php code </p>

<pre><code>&lt;?php
 $cvsData = "";   //Initialize it as empty
if(isset($_POST['Intrest'])) {
    $name = $_POST['Intrest'];
    foreach ($name as $color){
        $cvsData .= $color. " ". " ";      //Append the new color value
    }
}
$user_name = $_POST['user_name'];
$Gender = $_POST['Gender'];
$Age = $_POST['Age'];


if(empty($fn) || empty($ln) || empty($phone)){
$message = 'Fill in areas in red!';
$aClass = 'errorClass';
}

$cvsData .= ",". $user_name. "," . $Age . "," .$Gender .",".  "\n"; //Append the second line here

//Add header here
$exists = true;
if (!is_readable("form.csv")) {
    $exists = false; 
}

$fp = fopen("form.csv","a");
if($fp){
   if (!$exists) { 
       fwrite("This is my awesome header\n"); 
   }
fwrite($fp,$cvsData); 
fclose($fp);
}
?&gt;
</code></pre>

<p>Please help me out .<br>
Thanks in Advance.</p>