douzha8489 2012-05-07 09:20
浏览 42
已采纳

仅在表单提交后打开Fancybox如果LiveValidation成功

I use LiveValidation on a submission form that involves 1-4 upload fields for images. What the clients are impatient about is that once they click on submit, the form starts to upload the images, and it takes time according to the size of those images.

What I was trying to achieve is that once the user submits the form, and the LiveValidation passes, a Fancybox popup appears which has a loading image and some text. I do not want the loading progress bar as the client's hosting does not have the PECL upload progress extension or APC, and I don't want to use AJAX for compatibility reasons.

I just want a loading image to be rotating on the screen so the user knows that they have to wait.

I tried to create a function for it and set it to be executed on the events of "onSubmit" and "onClick", but in either case, the pop up appears even though there are errors in the form that are being pointed out by LiveValidation.

Also, i am assuming that once the images get uploaded and the form gets submitted the page will automatically redirect to the confirmation.

I am not good with javascript, and hence was unable to manipulate the scripts to achieve the desired results.

Any help on this will be greatly appreciated. Also if anyone has a better solution, that too will be great!

Thank you :)


for live validation, I'm using the script directly from the website: http://livevalidation.com/

Here is the livevalidation and fancybox initiation:

    <script type="text/javascript">
    $(document).ready(function () { 
        $(".form-validate-label").validate();
        $(".form-validate-p").validate({errorElement: "p"});
        $(".popup").fancybox();
    });

    </script>

The form itself is pretty big, but here is the fields area:

    <form name="frmsubmission" id="frmsubmission" method="post" class="form-validate-p" enctype="multipart/form-data" action="">
    ...
    ...
    <div class="regrow1">
            <div>
                <label class="label-large"><span class="required">*</span>Headshot Image File:</label>
                <input class="required"  name="head_shot" id="head_shot" size="40" type="file" />
            </div>
        </div>
        <div class="regrow2">
            <div>
                <label class="label-large">Attach Resume:</label>
                <input name="txtcv" id="txtcv" size="40" type="file" />
            </div>
        </div>
        <div class="regrow1">
            <div>
                <label class="label-large">Full body shot Image File:</label>
                <input  id="body_shot" name="body_shot" size="40" type="file" />
            </div>
        </div>
        <div class="regrow2">
            <div>
                <label class="label-large">Sanpshot Image File:</label>
                <input id="snap_shot" name="snap_shot" size="40" type="file" />
            </div>
        </div>

        <br /><br />

        <div id="submitrow">
        <button id="submit" name="submit" value="Submit" type="submit">Submit</button>
        </div>
    </form>
  • 写回答

1条回答 默认 最新

  • douqulv6059 2012-05-07 09:45
    关注

    instead of using fancybox and others approach. if you use plupload, i think that it will nice uload interface and upload status feature. below is the link.please see this may help you.

    http://www.plupload.com/example_queuewidget.php

    instead of show fancybox, i added one div with its loadingId. initially it will be hidden when you click, submit button it show the div, inside this div, you rotating image path. here is complete code.

    i am using jquery for hide show. if you do not want to use jquery, you can use javascript also for hide and show.

                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                    <title></title>
    
                    <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
    
                    <script src="Js/LiveValidation.js" type="text/javascript"></script>
    
                    <script type="text/javascript">
                        $(document).ready(function() {
                            $(".form-validate-label").validate();
                            $(".form-validate-p").validate({ errorElement: "p" });
                            $(".popup").fancybox();
                        });
                        function showloading() {
                            $("#loadingId").show();
                        }
                    </script>
    
                </head>
                <body>
                    <form name="frmsubmission" id="frmsubmission" method="post" class="form-validate-p"
                    enctype="multipart/form-data" action="">
                    <div class="regrow1">
                    <div id="loadingId" style="display:none;">Loading....</div>
                        <div>
                            <label class="label-large">
                                <span class="required">*</span>Headshot Image File:</label>
                            <input class="required" name="head_shot" id="head_shot" size="40" type="file" />
                        </div>
                    </div>
                    <div class="regrow2">
                        <div>
                            <label class="label-large">
                                Attach Resume:</label>
                            <input name="txtcv" id="txtcv" size="40" type="file" />
                        </div>
                    </div>
                    <div class="regrow1">
                        <div>
                            <label class="label-large">
                                Full body shot Image File:</label>
                            <input id="body_shot" name="body_shot" size="40" type="file" />
                        </div>
                    </div>
                    <div class="regrow2">
                        <div>
                            <label class="label-large">
                                Sanpshot Image File:</label>
                            <input id="snap_shot" name="snap_shot" size="40" type="file" />
                        </div>
                    </div>
                    <br />
                    <br />
                    <div id="submitrow">
                        <button id="submit" name="submit" value="Submit" type="submit" onclick="showloading();">Submit</button>
                    </div>
                    </form>
                </body>
                </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵