1

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.

Note:

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.

11
  • 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, 2015 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, 2015 at 23:06
  • 1
    Why is the question being voted as closed? Isn't it a legit one?
    – Kartagis
    Aug 21, 2015 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, 2015 at 19:49
  • 1
    @Pierre.Vriens please see my edit in the question (sorry that it overrode yours)
    – Kartagis
    Aug 21, 2015 at 20:00

2 Answers 2

1
+100

Make sure a field collection exists if you want to go through the Field collection module. When writing code make sure to use the field collection API. See the examples on Programmatically Adding a Field Collection Item to a Node in Drupal or Example: Programmatically adding field collection entries to a node .

You will have to use AJAX from your PhoneGap app, send the data you are collecting to your server, and use code to process and insert, as shown on Can I use PhoneGap jQuery to make AJAX calls?

2
  • 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, 2015 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, 2015 at 15:20
0

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

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

 function jsonpcallback(data) {
  //do stuff with JSON
    console.log(data);
 }   

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.