Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 引导验证程序提交表单_Jquery_Forms_Bootstrapvalidator - Fatal编程技术网

Jquery 引导验证程序提交表单

Jquery 引导验证程序提交表单,jquery,forms,bootstrapvalidator,Jquery,Forms,Bootstrapvalidator,目前我正在使用bootstrapValidator.min.js 0.5.3验证表单: 现在,这对于我绑定发送邮件事件的联系人表单来说很好用 但是现在我想将它用于一个表单,他需要验证表单,发送邮件并提交表单,这样我就可以$\u POST获取字段,将其写入mysql 还请注意,我有一个foreach循环,在添加更多对象时生成更多的表单。(表单用于申请作业,可在后端添加作业。) 代码: 我不会发布表单html和PHP,因为我知道它们可以工作。除非有人问。这是一个很长的表单,我不想用离题代码把它弄乱

目前我正在使用bootstrapValidator.min.js 0.5.3验证表单:

现在,这对于我绑定发送邮件事件的联系人表单来说很好用

但是现在我想将它用于一个表单,他需要验证表单,发送邮件并提交表单,这样我就可以$\u POST获取字段,将其写入mysql

还请注意,我有一个foreach循环,在添加更多对象时生成更多的表单。(表单用于申请作业,可在后端添加作业。)

代码:

我不会发布表单html和PHP,因为我知道它们可以工作。除非有人问。这是一个很长的表单,我不想用离题代码把它弄乱

验证器:

 jQuery('.form-job').each(function (i, obj) {
        jQuery(this).bootstrapValidator({
            fields: {
                firstname: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw naam in.'
                        }
                    }
                },
                lastname: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw achternaam in.'
                        }
                    }
                },
                street: {
                    validators: {
                        stringLength: {
                            min: 5,
                            message: 'Gelieve 5 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw straat in.'
                        }
                    }
                },
                housenumber: {
                    validators: {
                        stringLength: {
                            max: 8,
                            message: 'Vul aub een geldige huisnummer in.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw huisnummer in.'
                        },
                    }
                },
                postal: {
                    validators: {
                        stringLength: {
                            min: 4,
                            max: 8,
                            message: 'Vul aub een geldige postcode in.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw postcode in.'
                        },
                    }
                },
                city: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw stad in.'
                        }
                    }
                },
                country: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw land in.'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: 'Vul aub uw e-mailadres in.'
                        },
                        emailAddress: {
                            message: 'Vul aub een geldig e-mailadres in.'
                        }
                    }
                },
                telephone: {
                    validators: {
                        numeric: {
                            message: 'Gelieve alleen nummers te gebruiken.',
                        },
                        stringLength: {
                            min: 9,
                            message: 'Gelieve 9 of meer cijfers in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub een geldig telefoonnummer in.'
                        }
                    }
                },
                motivation: {
                    validators: {
                        stringLength: {
                            min: 10,
                            max: 550,
                            message: 'Vul aub minstens meer dan 10 letters in en minder dan 550.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw vraag in.'
                        }
                    }
                },
                cvurl: {
                    validators: {
                        file: {
                            extension: 'doc,docx,pdf,txt',
                            type: 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/txt',
                            maxSize: 5 * 1024 * 1024,   // 5 MB
                            message: 'Het geselecteerd bestand is niet geldig. Dit moet een .doc, .docx, .pdf of een .txt zijn en max 5 MB groot.'
                        }
                    }
                }
            }
        })
            .on('success.form.bv', function (e) {
                jQuery("#button").css('color', 'green');
                jQuery("#button").css('border', '2px solid green');
                jQuery(".alert-success").css('display', 'block');
                jQuery("#button").html('Verstuurd');
                jQuery(this).data('bootstrapValidator').resetForm();

                // Prevent form submission
                e.preventDefault();

                // Get the form instance
                var form = jQuery(e.target);

                // Get the BootstrapValidator instance
                var bv = form.data('bootstrapValidator');

                jQuery.post(my_ajax_object.ajax_url, form.serialize());

            });
    });
请不要介意荷兰人。任何荷兰语对问题都不重要,因为显示的只是文本

我也知道上面写着:

                // Prevent form submission
            e.preventDefault();
但当我删除它或注释掉它时,没有任何变化

所以我需要它来验证、发送邮件(有效)并提交。


谢谢

所以我做了这项工作

问题是我试图通过BootstrapValidator通过JS获得ajax发送的邮件

因此,我最终删除了在JS中定义任何内容的部分,剩下的是:

jQuery('.form-job').each(function (i, obj) {
        jQuery(this).bootstrapValidator({
            fields: {
                firstname: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw naam in.'
                        }
                    }
                },
                lastname: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw achternaam in.'
                        }
                    }
                },
                street: {
                    validators: {
                        stringLength: {
                            min: 5,
                            message: 'Gelieve 5 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw straat in.'
                        }
                    }
                },
                housenumber: {
                    validators: {
                        stringLength: {
                            max: 8,
                            message: 'Vul aub een geldige huisnummer in.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw huisnummer in.'
                        },
                    }
                },
                postal: {
                    validators: {
                        stringLength: {
                            min: 4,
                            max: 8,
                            message: 'Vul aub een geldige postcode in.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw postcode in.'
                        },
                    }
                },
                city: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw stad in.'
                        }
                    }
                },
                country: {
                    validators: {
                        stringLength: {
                            min: 2,
                            message: 'Gelieve 2 of meer letters in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw land in.'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: 'Vul aub uw e-mailadres in.'
                        },
                        emailAddress: {
                            message: 'Vul aub een geldig e-mailadres in.'
                        }
                    }
                },
                telephone: {
                    validators: {
                        numeric: {
                            message: 'Gelieve alleen nummers te gebruiken.',
                        },
                        stringLength: {
                            min: 9,
                            message: 'Gelieve 9 of meer cijfers in te vullen.'
                        },
                        notEmpty: {
                            message: 'Vul aub een geldig telefoonnummer in.'
                        }
                    }
                },
                motivation: {
                    validators: {
                        stringLength: {
                            min: 10,
                            max: 550,
                            message: 'Vul aub minstens meer dan 10 letters in en minder dan 550.'
                        },
                        notEmpty: {
                            message: 'Vul aub uw vraag in.'
                        }
                    }
                },
                cvurl: {
                    validators: {
                        file: {
                            extension: 'doc,docx,pdf,txt',
                            type: 'application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/txt',
                            maxSize: 5 * 1024 * 1024,   // 5 MB
                            message: 'Het geselecteerd bestand is niet geldig. Dit moet een .doc, .docx, .pdf of een .txt zijn en max 5 MB groot.'
                        }
                    }
                }
            }
        })
    });
然后我用一个

if (isset($_POST['submit'])
(这是一个示例,永远不要使用提交作为提交按钮的名称)

我调用的函数发送一封邮件,然后对数据库部分使用查询