暂停使用javascript提交表单

sou*_*w93 8 html javascript php form-submit

我正在尝试用照片做提交表单.在用户加载照片后,他按下提交按钮,我希望表单暂停10秒,为这10秒钟设置进度条动画,然后提交表单,你们可以说我做错了吗,看起来不像10秒后提交表格.这是代码:

HTML:

<form action="uploadpic.php" method="post" id="upload_form">
<input type="text" name="title" id="title">
<p id="title_p">Title</p>

<hr />

<input type="text" name="theme" id="picture_theme" size="40"/>
<p id="theme">Picture Theme<img src="../simages/info.gif" id="info" width="12" height="12" style="margin-left:10px;"></p>
<hr />

<div class="custom-upload">
    <input type="file" name="picture" id="true_pic" />
    <div class="fake-file">
        <input disabled="disabled" >
    </div>
</div>
<p id="upload_pic">Upload picture</p>?

<input type="submit" name="submit" id="submit" value="Upload" />
</form>
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT:

form = document.getElementById("upload_form");
    size=1;
    form.onsubmit = function()
    {
        if (size < 10)
        {
            setTimeout(delayedSubmit,1000); 
        }
        return false;
    }
    function delayedSubmit() {
        size++;
            if (size<5)
            {
                setTimeout(delayedSubmit,1000);
                alert("Counting "+size);    
            }
            else
            {
                alert("Form submitted");
                form.submit();
            }
    }
Run Code Online (Sandbox Code Playgroud)

PHP:

<?php

if ($_POST['submit'])
{
    $title = $_POST['title'];
    $theme = $_POST['picture_theme'];
    echo $title," ",$theme; 
}




 ?>
Run Code Online (Sandbox Code Playgroud)

我可以告诉表单不会提交任何事情,因为php变量不会显示任何内容,然后页面不会加载.

loo*_*per 4

当表单有一个名称和/或 id“提交”的按钮时,它将不再起作用(我的旧帖子是错误的)。

所以你需要做的是更改按钮的名称/id:

<input type="submit" name="submit-button" id="submit-button" value="Upload" />
Run Code Online (Sandbox Code Playgroud)

请记住:您还需要更改 PHP:

if ($_POST['submit'])
{
    $title = $_POST['title'];
    $theme = $_POST['picture_theme'];
    echo $title," ",$theme; 
}
Run Code Online (Sandbox Code Playgroud)

if ($_POST['submit-button'])
{
    $title = $_POST['title'];
    $theme = $_POST['picture_theme'];
    echo $title," ",$theme; 
}
Run Code Online (Sandbox Code Playgroud)

  • @tborychowski这是因为`form.submit`不再指向`form`对象的`submit()`函数,它指向名为“submit”的元素。 (2认同)