請你修改這段代碼。如果未填寫完畢提示“请填写完整表单信息!”如果填寫ok提交彈出對話框提交成功@app.route('/submit', methods=['POST']) def submit(): # 获取表单数据 line = request.form['line'] date = request.form['date'] model = request.form['model'] lists = request.form['lists'] number = request.form['number'] prod_date = request.form['prod_date'] shift = request.form['shift'] prod_line = request.form['prod_line'] responsible = request.form['responsible'] # 表单验证:检查是否所有表单字段都已填写 if not all([line, date, model, lists, number, prod_date, shift, prod_line, responsible]): return "<script>alert('请填写完整表单信息!');history.back();</script>"
时间: 2024-01-30 12:03:15 浏览: 110
好的,根据你的要求,我修改了代码,添加了弹出对话框和表单验证的逻辑。以下是修改后的代码:
```python
@app.route('/submit', methods=['POST'])
def submit():
# 获取表单数据
line = request.form['line']
date = request.form['date']
model = request.form['model']
lists = request.form['lists']
number = request.form['number']
prod_date = request.form['prod_date']
shift = request.form['shift']
prod_line = request.form['prod_line']
responsible = request.form['responsible']
# 表单验证:检查是否所有表单字段都已填写
if not all([line, date, model, lists, number, prod_date, shift, prod_line, responsible]):
return "<script>alert('请填写完整表单信息!');history.back();</script>"
else:
# 在这里添加提交表单信息的代码
return "<script>alert('提交成功!');window.location.href='/';</script>"
```
这段代码中,我们先获取表单数据,然后使用 `all` 函数来检查是否所有表单字段都已填写。如果有字段为空,则弹出提示框,并使用 `history.back()` 来返回上一页。如果所有字段都已填写,则我们可以在这里添加提交表单信息的代码,并弹出提交成功的对话框,使用 `window.location.href` 来跳转到首页。
希望这个代码片段能够满足你的需求!
阅读全文