不能在Bootstrap中提交我的模态表单 [英] Can`t submit my modal form in Bootstrap
问题描述
Django初学者需要帮助!我正在尝试以模态形式上传图片,问题是我无法提交我的模态...当我点击提交按钮时,实际上并没有真正开心......已经挣扎了2天......
我正在使用Bootstrap V 1.0.4
从网上尝试了一些JS代码,但它们都没有为我工作......任何想法我该怎么办?谢谢...
这里是我的模态:
A Django beginner needs help here! I'm trying to upload image in a modal form, the problem is I can't submit my modal...when I click the submit button nothing actually happpen...been struggling this for 2 days... I'm using Bootstrap V 1.0.4 tried some JS codes from the net but none of them worked for me... any idea what should I do? thanks... here`s my modal:
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">آپلود عکس</h4>
</div>
<div class="modal-body">
<p>کاربر گرامی لطفا قبل از آپلود عکس به موارد زیر توجه نمایید:</p>
<ul>
<li>حداکثر حجم قابل قبول برای فایل ارسالی 8 مگابایت می باشد</li>
<li>فرمت های تصویری مجاز: jpg , Gif , PNG</li>
<li>در صورت ارسال عکس های غیراخلاقی عکس و طرح شما به هیچ وجه منتشر نخواهد شد و پس از چاپ از سیستم حذف می گردد</li>
<li>لطفاً در هنگام آپلود عکس صبور باشید :)</li>
</ul>
</div>
<div class="modal-footer">
<form method="post" action="/upload/" id="formfield">
{% csrf_token %}
<div class="form-group">
<label for="upload">آپلود عکس:</label>
<input type="file" class="form-control" id="upload" name="upload"/>
</div>
<div class="form-group">
<label for="sides">چند رو بودن(1-پشت/2-جلو/3-هر دو طرف):</label>
<input type="text" class="form-control" id="sides" name="sides"/>
</div>
<button id="submit" type="submit" class="btn btn-default" data-dismiss="modal">ذخیره</button>
</form>
</div>
</div>
</div>
</div>
抱歉,如果表格是波斯语。
views.py
sorry the if the form is in persian. views.py
def upload(request):
if request.method=='POST':
print "entered upload"
image=request.POST.get('upload', False)
sides=request.POST.get('sides', False)
design=Design.objects.create(image=image, sides=sides)
return HttpResponseRedirect("/home/")
因为我可以 t提交我的模态它没有
甚至输入我的上传
def in views.py。
任何帮助将不胜感激:)
since I cant submit my modal it doesn
t even enter my upload
def in views.py.
any help would be greatly appreciated :)
推荐答案
你有 data-dismiss =提交按钮上的模态
,这是用于关闭模式框的引导处理程序。引导程序正在捕获此事件并阻止默认提交事件,因为其目的是关闭模式。只需从提交按钮中删除 data-dismiss =modal
,就可以了。另请按照 karthikr的提示
You have data-dismiss="modal"
on submit button, which is a bootstrap handler for closing the modal box. The bootstrap is catching this event and preventing default submit event as its purpose is to close the modal. Just remove the data-dismiss="modal"
from submit button and you are good to go. Also follow the tips by karthikr
这篇关于不能在Bootstrap中提交我的模态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!