dimanche 7 juillet 2019

How to get a nested json output from a html form with multiple add input elements and sections

USE CASE

A parent/guardian form is created and in that form, the parent can add multiple phone numbers, and add multiple parent/guardian section information.

THE PARENT FORM (IMAGE)

https://imgur.com/a/2bCE7Zs

https://imgur.com/a/VUo79bd

Post data

https://imgur.com/a/iU9YGNH

I want to get the data from a form post with multiple add input elements (phone number) and sections to the server in a nested json format, so that i can do a foreach statement in laravel to loop through the info and save it to the database.

https://paste.laravel.io/5a680be7-f787-4a7e-89c8-36c18bbc71e5

 {
  "parents": [
    {
      "enrollment_id" : "15"
      "title": "MR",
      "fname": "udeme",
      "mname": "samuel",
      "relation": "Mother",
      "home": "Block 6789 flat 5766 Feswac etention, oshodi lagos",
      "email": "udemesamuelxyz@gmail.com",
      "num": [
        {
          0: "234788999567",
          1: "2345565656564"
        }
      ],
      "work": "Oshodi lagos Nigeria",
      "office": "Yaba lagos Nigeria",
    },
    {
      "enrollment_id" : "15"
      "title": "Mrs",
      "fname": "bridget",
      "mname": "magret",
      "relation": "Mother",
      "home": "ff Enoma Junction Ago Palace Okota Lagos",
      "email": "bridgetmarret54r@ymail.com",
      "num": [
        {
          0: "23454456767667",
          1: "234568869970000"
        }
      ],
      "work": "Oshodi lagos Nigeria",
      "office": "Yaba lagos Nigeria",
    }
  ]

also explain how i can loop this data in laravel and save it to the data base.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire