简体   繁体   English

如何在表单提交之前确保用户插入说明或文件?

[英]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.

相关问题 我如何确保中间件在另一个之前运行 - How can i make sure middleware is run before another 当多个apache线程尝试访问数据库时,如何确保仅插入一条记录? - how can i make sure only a single record is inserted when multiple apache threads are trying to access the database? 在提交到数据库之前,如何将PHP表单分为两部分? - How can I split a PHP form into two sections, before submission to a database? 如何计算和限制表单提交? - How can I count and limit form submission? 在解析之前,如何确保CSV文件包含数据? - How do I make sure a CSV file contains data before parsing it? 如何确保在页面加载之前显示背景图像? - How can I make sure a background image displays before the page loads? 对于没有加载页面的表单,我如何检测表单提交何时完成,而是提供文件? - How can I detect when form submission is complete, for a form that does not load a page, but rather, serves up a file? 登录前确保Facebook用户“注册” - Make sure Facebook user “register” before login 我如何在用户输入后更新表单,然后再发布 - how can I update the form upon user entry before post 如何确保用户无法使用PHP中的同一帐户登录两次? - How can I make sure that a user cannot login twice with the same account in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM