title: javascript array to string JSON
body: <p>First of all i am new to php and javascript</p>
  
  <p>I have a web form where users can add multiple contacts ans send to ther server.</p>
  
  <p>Due to some reasons i cant use the normal html elements to store the values ,so i am using an array to store values.</p>
  
  <pre><code>//init array
  
  var contacts = new Array(); //contact array
  
  var tempArray = new Array(); //temp array to store current contacts
  
  //getting the contact info and setting to a temp array
  
  tempArray = {
        name:"username",
        age:12,
        sex:false
       };
  
  //push the content to the `contacts` array
  
  contacts.push(tempArray);
  </code></pre>
  
  <p>I added many contacts to the <code>contacts</code> array and now i need to submit the array to server.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>I am using Codeignitor and Malsup FORM plugin.</p>
  
  <p>as per malsup i can configure the data option like this</p>
  
  <pre><code>var options = { 
  
  dataType:'json', //type of data
  data:[contactArray:contacts], //additional parm
  
      }; 
  </code></pre>
  
  <p>and on <code>ajaxSubmit</code> option i can give this option as a parm.</p>
  
  <p>when i do this i am getting the following error</p>
  
  <pre><code>uncaught exception: [Exception... "Component returned failure code: 0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA) [nsIDOMFormData.append]"  nsresult: "0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA)"  location: "JS frame :: /js/form.js :: fileUploadXhr :: line 224"  data: no]
  temp/jquery.min.js
  Line 4
  </code></pre>
  
  <p>IT WORKS with <code>$.POST</code> in jQuery.</p>
  
  <p>so i tried the <code>JSON.stingify()</code> to convert the data to string.</p>
  
  <p>but on server i am getting like this</p>
  
  <pre><code>'contactArray' =&gt; string '[{"name":"username","sex":"12","sex":"false"}]'
  </code></pre>
  
  <p>If i used the <code>json_decode</code> then i cant use the form validation.</p>
  
  <p>I want to use the FORM VALIDATION LIBRARY IN CODEIGNITOR.</p>
  
  <p>CI supports validation of array of elements.</p>
  
  <p>so</p>
  
  <p>if i get something like <code>name[],age[],sex[]</code> then i can validate easily.</p>
  
  <p>Please help me to solve the problems or give me suggestions.</p>
  
  <p>Thank you.</p>