提交前删除表单中未使用的字段



我的想法可能错了,但。。。我想,如果我在提交之前从表单中删除了未使用的表单字段的name属性,它会将它们从生成的电子邮件中删除,从而稍微整理一下。我的代码似乎工作不太好,欢迎提供任何帮助。

<script>
  function submitRequestForm(){
   requestForm = $("#formid");
    requestForm.find('input[name], select[name]').each(function(){
    if ($(this).val(){
      $(this).removeAttr('name');
    }
    requestForm.submit();
  }
</script>

不要删除name属性,而是尝试在表单提交期间禁用该字段。

在此之前,您的代码中几乎没有语法错误。

 function submitRequestForm(){
   requestForm = $("#formid");
    requestForm.find(":input").filter(function(){ return !this.value; }).attr("disabled", "disabled");
    requestForm.submit();
   // In case you want to re-enable the fields
   requestForm.find(":input").filter(function(){ return !this.value; }).removeAttr("disabled");
  }

最新更新