title: How to send multiple FormData objects to server using AJAX and access those objects on the server
body: <p>I am trying to develop a page where teachers can go and create quizzes for their students. To meet this end, there are two forms on the page. One form is for creating the actual quiz and the other is for creating the questions that go on the quiz. </p>
  
  <p>Everytime the teacher adds a question to the quiz, a JS function is called which saves the question data locally in a FormData object, which is then placed into an array of questions. Keep in mind that one of the inputs on the question form is a file input.</p>
  
  <p>When the teacher finally submits the quiz, I use an AJAX call that sends two items to the server: a FormData object containing the quiz data and an array of FormData objects containing the information about the questions on the quiz.</p>
  
  <p>My question is: how do I access these different objects on the server? I am using CakePHP so my initial thought was <code>$this-&gt;request-&gt;data["quiz"]</code> and <code>$this-&gt;request-&gt;data["questions"]</code>, but I keep getting a "index quiz/question not found" error. Is there a better way for me to be sending this data? Many many thanks to any help you can provide.</p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>var questions = [];
  var currentQuizQuestion = 0;    
  
  function saveNewQuestion()
  {
      var formData = new FormData(document.getElementById("inputQuestionForm"));
      questions[currentQuizQuestion] = formData;
      currentQuizQuestion++;
  }
  
  function saveQuiz()
  {
      var quizData = new FormData(document.getElementById("inputQuizForm"));
      $.ajax({
          type: "POST",
          url: "create",
          data:
          {
              quiz: quizData,
              questions: questions
          },
          processData: false,
          contentType: false
      });
  }
  </code></pre>
  
  <p><strong>CakePHP</strong></p>
  
  <pre><code>public function create()
  {
      if($this-&gt;request-&gt;is("post"))
      {
          $quiz = $this-&gt;request-&gt;data["quiz"];
          $questions = $this-&gt;request-&gt;data["questions"];
          ...
      }
  }
  </code></pre>