不要发布隐藏的表单输入字段?

时间:2014-09-26 09:51:43

标签: forms http-post form-fields

我创建了一个表单,根据选择显示/隐藏输入字段,我只想发布可见的输入字段。目前,隐藏输入字段的值也已提交

我检查了$ _POST,我看到了

[chairs] => Array
    (
        [0] => chair-b-white
        [1] => chair-c-black
    )

    [num_of_chair-a-black] => 
    [num_of_chair-a-white] => 
    [num_of_chair-a-gray] => 
    [num_of_chair-b-black] => 
    [num_of_chair-b-white] => 2
    [num_of_chair-b-gray] => 
    [num_of_chair-c-black] => 5
    [num_of_chair-c-white] => 
    [num_of_chair-c-gray] => 

有没有办法跳过发布空白的输入字段?

1 个答案:

答案 0 :(得分:2)

我假设您使用javascript切换字段的可见性。隐藏它们时,您也可以将它们设置为disabled。禁用的表单字段不会提交给服务器。