2015-06-16 49 views
0

我正在使用Drag n拖放FormBuilder來創建表單。如何從Form創建json?

現在我想這樣的創建形式的JSON:

{ 
    "action":"hello.html", 
    "method":"get", 
    "enctype":"multipart/form-data", 
    "html":[ 
     { 
      "type":"p", 
      "html":"You must login" 
     }, 
     { 
      "name":"username", 
      "id":"txt-username", 
      "caption":"Username", 
      "type":"text", 
      "placeholder":"E.g. [email protected]" 
     }, 
     { 
      "name":"password", 
      "caption":"Password", 
      "type":"password" 
     }, 
     { 
     "name":"description", 
     "caption":"Description", 
     "type":"textarea" 
     }, 
     { 
      "name":"file", 
      "caption":"Select File", 
      "type":"file", 
      "multiple":true, 
      "id":"file2" 
     }, 
     { 
     "name":"number", 
     "caption":"Your number", 
     "type":"text" 
     }, 
     { 
     "name":"email", 
     "caption":"Your email", 
     "type":"text" 
     }, 
     { 
     "type":"radiobuttons", 
     "name":"gender", 
     "class":"", 
     "options":{ 
      "male":{ 
       "value":"male", 
       "caption":{ 
        "html":"Male", 
        }, 
      }, 
      "female":{ 
       "value":"female", 
       "caption":{ 
        "html":"Female"} 
      } 
     } 
     }, 
     { 
     "type":"checkboxes", 
     "name":"color[]", 
     "options":{ 
      "blue":{ 
       "value":"blue", 
       "caption":{"html":"Blue"} 
      }, 
      "red":{ 
       "value":"red", 
       "caption":{"html":"Red"} 
      }, 
      "black":{ 
      "value":"black", 
      "caption":{"html":"Black",}, 
      } 
     } 
    }, 

    { 
     "type":"submit", 
     "value":"Login" 
    } 
    ] 
} 

我使用這個表單生成http://getfuelux.com/formbuilder.html建立形式。

現在,當我將任何元素拖到區域時,我想要像上面提到的那個字段的json。如何創建表格的json

回答

0

jQuery serializeArray()做你正在尋找。只需添加額外的細節,如method

var jsonString = $("#myForm").serializeArray(); 
//...add your stuff here like method, etc... 
+0

你可以給我舉例說 – ND17

+0

不給像佔位符,標籤,所有的信息..而不是像我想要什麼我上面提到的 – ND17