Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:53:43+00:00 2026-05-27T09:53:43+00:00

How do I submit an array from dojo to php. I’m submitting these values:

  • 0

How do I submit an array from dojo to php.
I’m submitting these values:

["a", "b", "c"]

Here’s what I got so far:

 btn_send.onclick(function(){
            var name_array = name_looper();
            console.log(name_array);
            dojo.xhrPost({

                url: "dojo_phpform.php",
                content: {names: name_array},
                load: function(result) {
                    var x = dojo.byId('results');
                    x.innerHTML = result;
                }
            });
        });

        function name_looper(){
            var names = dojo.query('input[type=text]');
            var name_array = [];
            names.forEach(function(element, index, array){
                name_array[index] = dojo.attr(element, 'value');
            });

            return name_array;
        }

I tried to echo $_POST[‘names’] from the php file(dojo_phpform.php) and it didn’t return any errors. It seems like the array isn’t actually submitted. The only thing that’s returned is the last item in the array. What do I do?Please help, Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:53:44+00:00Added an answer on May 27, 2026 at 9:53 am

    As far as I’ve been able to see, dojo’s xhr functions don’t support it. I’m using a helper function to “flatten” parameters myself.

    _flattenXhrParams: function(params)
    {
        var newParams = {};
        for(var key in params)
        {
            if(dojo.isObject(params[key]))
            {
                for(var innerKey in params[key])
                {
                    newParams[key + "[" + innerKey + "]"] =
                            params[key][innerKey];
                }
            }
            else if(dojo.isArray(params[key]))
            {
                for(var i = 0, l = params[key].length; i < l; i++)
                {
                    newParams[key + "[]"] = params[key][i];
                 }
            }
            else
            {
                newParams[key] = params[key];
            }
        }
        return newParams;
    }
    

    It’s butt ugly, I know, and obviously only works on one dimensional arrays/objects. In your case, you’d do:

    dojo.xhrPost({
        url: "dojo_phpform.php",
        content: _flattenXhrParams({names: name_array}),
        load: function(result) {
            var x = dojo.byId('results');
            x.innerHTML = result;
        }
    });
    

    .. and you’d get POST parameters like names[]=a&names[]=b&names[]=c. For objects, you’d get names[somekey]=a&names[otherKey]=b etc. PHP handles both nicely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP: How to remove specific element from an array? Here in my
$page = $curl->post($baseUrl.'/submit.php', array('url'=>$address,'phase'=>'1','randkey'=>$randKey[0],'id'=>'c_1')); $exp = explode('recaptcha_image',$page); The id recaptcha_image is not found although
I am submitting my array from jQuery Datatables for server side processing, in the
I'm trying to pass an array from a jQuery function to my controller. The
I've got a php array: $toField = explode(,, $ids); //Which looks something like '24,25,26,29'
Currently I'm using file_get_contents() to submit GET data to an array of sites, but
Is it acceptable to submit from an http form through https? It seems like
I want to take input from a textfield and turn it into an array
The submit handler gets the same form values no matter what I put in
I have a simple php file with a GET from a form to throw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.