I'm in the process of making a Phonegap application to create nodes of a certain content type. The site I'm writing data to/getting data from utilises Field Collection module, and I've looked at the database structure. It creates additional tables for the contained fields and cross-references them. I was wondering if anyone has come across this situation and how did you manage to solve it.


I'm using Drupal Services for endpoint, and my request needs to send all those fields in my fiddle altogether (more than one row).

As for what the fiddle does, I'm creating a table then add more rows to the table.

  • 1
    You're going to have to clarify your problem. Your fiddle doesn't have any AJAX calls. What's your request need to send? What is the endpoint doing? What are you using for your AJAX endpoint?
    – Shawn Conn
    Aug 19 '15 at 17:06
  • 1
    I don't know if this would help but using the module field collections, the field collection items are saved in the table field_collection_items and all the fields inside the field collection are stored in their own table (normal drupal way). Then inside the fields there is a column called bundle which holds the value of the field_name from the field collection item, creating a 1:m relationship. You can insert into the field_collection_item table then loop through the field values and insert them one by one adding the relationship through the bundle col
    – DMAC
    Aug 19 '15 at 23:06
  • 1
    Why is the question being voted as closed? Isn't it a legit one?
    – Kartagis
    Aug 21 '15 at 7:36
  • 2
    To answer the comment about "why voted as closed": there are currently 2 votes (not from me) that indicated this: "unclear what you're asking. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.". So I think it's in "your" hands to (soon) enhance your question, eg to answer to Shawn's comment also. If we don't understand the question, we cannot answer it, you must understand that, no? Just trying to help, ok? Aug 21 '15 at 19:49
  • 1
    @Pierre.Vriens please see my edit in the question (sorry that it overrode yours)
    – Kartagis
    Aug 21 '15 at 20:00

make sure a field collection exists if you want to go through the Field collection module. Then write the custom php code make sure to use the field collection api. here is an example. another example.

You will have to use AJAX from your phone gap app and send the data you are collecting to your server then use the drupal code to process and insert. AJAX from phonegap to PHP

Let me know if you need any more help, i'm just really busy as of late or I would provide a more detailed answer. It's difficult not having the code in front of me.

  • I have a bunch of other fields than field collection. Do I need to process all of them by making an ajax call to a PHP file, or is it okay if I do the field_collection only by PHP, and the rest as usual?
    – Kartagis
    Sep 14 '15 at 13:17
  • If you are using a javascript front end then yeah, Best practice is to validate the values on the front end, then if passed validation AJAX the data to the server on submit, then re-check the values on the server side, then insert into drupal, then send the response variable back to the AJAX call on the frontend and set the appropriate event action/messages. Drupal has an API already so you can utilize that in your PHP code.
    – DMAC
    Sep 14 '15 at 15:20

You can send JSONP Cross-domain Requests using ajax call in your PHONEGAP application. Cross Domain Request

    url: "http://remote.domain.com/data/?allback=jsonpcallback&id=123",
    jsonp: "jsonpcallback",
    dataType: "jsonp",
    data: {
    id: "123"
  success: function(data) {

 function jsonpcallback(data) {
  //do stuff with JSON

Then you can get all post data and save to particular content type using drupal bootstrap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.