I have a channel section by the name of order. What I need is that every time a user clicks a button on the front end the data of the form is sent to my plugin which then uses the data to create a new entry of type order and saved in the back end. The data in the form only represents the content of the entry and the only other information we have is that the entry is of type channel and that it belongs to the order channel. What would be the best way to create the entry with the publishing date, title, id, etc all set appropriately? Can I use saveEntry of the entries service in some way?
1 Answer
You can use the FrontEnd Entry Form for this. If you want to allow guests (non-registered users) to submit the form, you need to use the Guest Entries plugin.
Both methods will set "publishing date, id, etc" automatically, you just need to specify the title in the form.
If you want to hard-code some field values and prevent the user from changing it, you'd need to create a plugin which checks for entries.onBeforeSaveEntry
or guestEntries.beforeSave
(if you use Guest Entries plugin).
Edit:
The Entry Form is just an example. You can just as well use an ajax-request to send your data. Just make sure the POST values are set correctly.
If you want to save an entry from within your plugin, use the EntriesService API
-
Hey sorry I noticed a mistake in my question. The reason I cant use the entry form is because I am using another plugin the creates a shopping cart for the user and then sends that data to another site on checkout. The plugin is simplecart js and it requires that my fields be entered in divs instead of a form input. So in the end I do have the data but I have it in a php array inside my own plugin. Is there a way to create a new entry and save it using data from this array? Jul 15, 2014 at 2:48
-