Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Ajax request - get form data and loop through element_name[]

I am performing an AJAX-Reqest with form data and additional data as array (selected_members)

$.ajax({
    type: "POST",
    url: "inc/insert.inc.php",
    data: { 
        frmData: $("#frmData").serialize(),
        selected_members: selected_members
    },

How can I get these data in insert.inc.php as two arrays (form data and selected_members)? The form contains also elements with name="element_name[]"

    var_dump($_POST);
        array(2) {
  ["frmData"]=>
  string(232) "datDate=2022-02-13&tmBeginn=17%3A00&tmEnde=17%3A00&cmb_Mittel%5B%5D=1&txt_Aufwandmenge%5B%5D=1&txt_mKh%5B%5D=1&cmb_Mittel%5B%5D=2&txt_Aufwandmenge%5B%5D=2&txt_mKh%5B%5D=3&cmbGeraet=1&cmbDuese=1&txtWasser=300&cmbGasse=2&cmbAnwender=1"
  ["selected_members"]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "4"
  }
}

How can I get the form data, and loop through each "row" of the three element_name[] inputs?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As we can see, cmb_item and txt_amount are existing values in $yourarray and they are arrays of items. They do not need to be associative arrays, because they share the same name and differ in value only. In order to refer to them, you can simply do $yourarray['cmb_item'] and $yourarray['txt_amount'], respectively.

EDIT

Example:

<?php

$foo = 'datDate=2022-02-13&tmStart=15%3A00&tmEnd=15%3A00&cmb_item%5B%5D=1&txt_amount%5B%5D=30&cmb_item%5B%5D=2&txt_amount%5B%5D=50&&cmbDevice=1';

parse_str($foo, $bar);

echo var_dump($bar['cmb_item']);

The result is

array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!