Bram
Bram

Reputation: 1112

Send JSON to PHP as part of form

I have a complicated form with some inputs and textareas that allow the user to create a calendar item. I also have a popup that let's them link activities to the item and another popup that lets them link predefined targets to an activity.

Activities and links between targets and activities should only be saved when the calendar item is saved

I was thinking of handling all the popup stuff by saving the data in a JSON object. That object should then be sent to the PHP file handling the form submit.

I do not want to send the JSON using Ajax, I need it to be part of the form. I was thinking of simply adding a hidden textarea with json data in it and using json_decode() in my page, but I'm wondering if there are better approaches.

Upvotes: 0

Views: 173

Answers (1)

shadyyx
shadyyx

Reputation: 16065

I guess the popups are handled by javascript (jQuery?) so You can fill Your hidden inputs with JSON encoded data from these popups (done by javascript) and then simply post the form when ready.

Then in PHP You just decode the JSON data and manage them.

Upvotes: 1

Related Questions