2017-11-07 2 views
0

양식을 제출하고 데이터베이스에 데이터를 저장하려고하는데 데이터를받을 수 없습니다. 컨트롤러Express - POST 양식에서 데이터를 가져 오는 방법

routes.post('/new-inventory/:dbname', inventory.store); 

내 기능입니다 :

내 경로는 점이다 난 그냥 데이터를 수신 있는지 확인하기 위해 콘솔 로그를 않습니다. 첫 번째 console.log를 보여주기 때문에이 함수로 간다. req.body{}입니다. 내 노드에서

div(class="popup-content") 
    form(action="/new-inventory/#{dbname}" method="post") 
    div(class="popup-title") 
     span Novo inventário 
    div(class="popup-data") 
     div(class="form-group") 
     label(for="inventory-description") Descrição 
     input(type="text" id="inventory-description" value="#{description}" class="form-control" disabled) 
     div(class="form-group") 
     label Armazém 
     select(class="form-control" id="wharehouse-select") 
      each whare, i in wharehouse 
      option(value="#{whare.szzstamp}" data-option="#{whare.armazem}") #{whare.armazem} - #{whare.zona} 
     div(class="form-group") 
     label(for="inventory-date") Data 
     input(type="text" id="inventory-date" class="form-control") 

    div(class="popup-button") 
     div(class="btn-submit") 

     button(type="submit") Criar 
     div(class="close-btn") 
      span Cancelar 

내가 body-parser을 시작으로 게재 :

app.use(bodyParser.json()); // support json encoded bodies 
app.use(bodyParser.urlencoded({ extended: true })); // get information from html forms 

나는이 어떻게 할 수있는

store: (req, res) => { 
    console.log('Storing new inventory...'); 
    console.log(req.body) 
    }, 

HTML (옥) 나의 양식은 무엇입니까? 내가 뭘 잘못하고있어?

+1

당신이 그것을 작동 입력 – Tien

+1

를 사용하여 이름 ATTR에 대한'name' 속성을 추가하지만 이름을 추가하면하지 않았다고 생각 비활성화 된 첫 번째 입력을 제외하고 그 해결책은 무엇입니까? @Tlen – agit

답변

2

그냥 각 입력 태그에 name 속성을 추가 감사

+0

각 입력 필드 – user3242861

+0

@ user3242861 고맙습니다. 첫 번째 입력이 비활성화 된 경우 이해할 수 있는지 확실하지 않습니다. '이름'을 제거하거나 본문 요청에서 해당 데이터를 제거 할 수 있습니다. – Tien