[英]How can I make sure a user either inserted a description or file before form submission?
i have a foreach row that displays the "message icon" (i dont think it has anything to do with the form since the form is outside the loop: enter image description here which displays a chat form that you can either type a chat or send an attachment: enter image description here 我有一个显示“消息图标”的foreach行(我不认为它与表单有任何关系,因为表单在循环之外: 在此处输入图像描述,其中显示一个聊天表单,您可以键入聊天或发送附件: 在此处输入图像说明
How can i make one of them required before submission? 如何才能在提交前提出其中一个要求? I tried through multiple JQuery ways but because they are in a for loop and each of them do not have a special id, its not working.
我尝试了多种JQuery方法,但因为它们处于for循环中,并且每个都没有特殊的id,所以它不起作用。 any help please?
有什么帮助吗? I just need it to show an alert
我只是需要它来显示警报
Here is my code for the form: 这是我的表单代码:
<form method="post"action="<?php echo base_url();?>form_support_chat" enctype="multipart/form-data" class="ticket-reply-form">
<div class="row">
<div class="col-xs-12">
<div class="chat-left">
<input type="text" name="message" placeholder="Type Message ..." class="form-control" autocomplete="off">
<input type="hidden" name="cst_id" value="<?php echo $cst_id; ?>">
<input type="hidden" name="arch_ticket" value="<?php echo $arch_ticket; ?>">
<input type="hidden" name="ticket_number" value="<?php echo $ticket_number?>">
</div>
<div class="chat-right">
<label>
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" >
<input type="file" name="file" class="form-control" style="display:none;" id="hidden_upload_file_chatting">
</label>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
<span id="_showName"></span>
</div>
</div>
</div>
</form>
Simply use html5's required value 只需使用html5的必需值即可
<input name="cst_id" value="<?php echo $cst_id; ?>" required>
or 要么
<input name="cst_id" value="<?php echo $cst_id; ?>" required="true">
update 更新
Using jQuery, add id value to each input 使用jQuery,为每个输入添加id值
$(document).ready(function() {
if( $('#input1').valid() || $('#input2').valid(); ):
console.log("Success");
endif;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.