从表单中获取javascript函数的返回值


Get the return value of a javascript function from inside a form

我有这个表单

<form action="<?php echo $response ?>?nexturl=<?php echo $nexturl ?>"
 method="post" enctype="multipart/form-data" onsubmit="return saveFile(); ">
 <input id = "file" name="file" type="file" style="border:none;"/>

我想这样做:

return $action = saveFile();

我想存储saveFile()的返回值,这是一个JavaScript代码,返回一个布尔值到一个PHP变量。我该怎么做呢?

保留隐藏输入字段中的值,然后提交表单:这样的:

function saveFile()
{
    var val=true;
    var input=document.createElement("input");
    input.setAttribute("type", "hidden");
    input.setAttribute("name", "booleanValue");
    input.setAttribute("value", val);
    document.getElementById("form").appendChild(input);
}

在php中检索这个值:

$myBoolean=$_REQUEST['booleanValue'];