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 8210117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:57:48+00:00 2026-06-07T09:57:48+00:00

First of all i am new to php and javascript I have a web

  • 0

First of all i am new to php and javascript

I have a web form where users can add multiple contacts ans send to ther server.

Due to some reasons i cant use the normal html elements to store the values ,so i am using an array to store values.

//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);

I added many contacts to the contacts array and now i need to submit the array to server.

Problem

I am using Codeignitor and Malsup FORM plugin.

as per malsup i can configure the data option like this

var options = { 

dataType:'json', //type of data
data:[contactArray:contacts], //additional parm

    }; 

and on ajaxSubmit option i can give this option as a parm.

when i do this i am getting the following error

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

IT WORKS with $.POST in jQuery.

so i tried the JSON.stingify() to convert the data to string.

but on server i am getting like this

'contactArray' => string '[{"name":"username","sex":"12","sex":"false"}]'

If i used the json_decode then i cant use the form validation.

I want to use the FORM VALIDATION LIBRARY IN CODEIGNITOR.

CI supports validation of array of elements.

so

if i get something like name[],age[],sex[] then i can validate easily.

Please help me to solve the problems or give me suggestions.

Thank you.

  • 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-06-07T09:57:50+00:00Added an answer on June 7, 2026 at 9:57 am

    This code does not create an array:

    tempArray = {
          name:"username",
          age:12,
          sex:false
         };
    

    It creates an object (completely overwriting the blank array you assigned to tempArray earlier).

    if i get something like name[],age[],sex[] then i can validate easily.

    If you want, you can create post data that would look like that, as a prep step prior to sending in your data. It’s fairly easy::

    function prepContacts(contacts) {
        var result = []; // Build up string in array, we'll join at the end
        var nameKey, ageKey, sexKey;
    
        // I've put [] in these because you use PHP
        nameKey = encodeURIComponent("name[]");
        ageKey = encodeURIComponent("age[]");
        sexKey = encodeURIComponent("sex[]");
    
        for (index = 0; index < contacts.length; ++index) {
            contact = contacts[index];
            result.push(nameKey + "=" + encodeURIComponent(contact.name));
            result.push(ageKey + "=" + encodeURIComponent(contact.age));
            result.push(sexKey + "=" + encodeURIComponent(contact.sex));
        }
    
        return result.join("&");
    }
    

    Then post that via $.ajax:

    $.ajax({
        url: "/path/to/resource",
        type: "POST",
        data: prepContacts(contacts),
        success: function(response) {
            // POST worked, but you have to check response for whether
            // it worked at the logic level
        },
        error: function() {
            // POST failed
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to web programming. New to Javascript, PHP, Ajax, etc. I have
I'm new to PHP first of all .. My question is once I got
first of all I'm totally new to FAST but I already have a couple
First of all I have to say I am new to iOS development. My
First of all, forgive me for being a beginner to Javascript and PHP. Second:
So I am still somewhat new to PHP, MySQL, and Javascript but I have
First of all i have the following to convert my Javascript array to a
First of all, I am new to Javascript. I need concrete help not only
I am fairly new to Jquery and javascript and have jumped in head first
First off I am completely new to Javascript but I have some HTML/CSS experience.

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.