$ _POST无法从html文件的文本字段中检索数据

时间:2019-04-11 17:58:57

标签: javascript php html

有一个Discovery.html文件,该文件通过html表单中的操作链接到validate_signup.php文件。当我在validate_signup.php中并尝试使用文本字段$ _POST ['XXX']检索格式为regFName,regSName,regEName,regPName的值时,它将返回错误,指出未定义的索引XXX。

文件目录(不确定是否可以发挥作用)

文件夹-HTML,PHP等

HTML-- Discovery.html等 PHP-- validate_signup.php等

我创建另一个工作类似的html和php文件,在本示例中,它可以工作。

HTML发件人:

<form class="modal-content animate"  onsubmit="return validate();" action="../PHP/validate-signup.php" methode="post">
    <div class="containerL">
        <label><b>First name</b></label>
        <input type="text" class="LoginFromPage" id="regFName" placeholder="Enter Frist name" name="regFName" required>

        <label><b>Surname</b></label>
        <input type="text" class="LoginFromPage" id="regSName" placeholder="Enter Surname" name="regSName" required>

        <labelb>Email</b></labelb>
        <input type="text" class="LoginFromPage" id="regEName" placeholder="Enter Email" name="regEName" required>

        <label><b>Password</b></label>
        <input  type="password" id="regPName" placeholder="Enter Password" name="regPName"required>

        <button type="submit">Register</button>
        <button  type="button" onclick="document.getElementById('id02').style.display='none'" id="cancelbtn">Cancel</button>
        <div id="error_para" ></span>
        </div>
</form>

PHP:

$password = $_POST["regPName"];
$email = $_POST["regEName"];
$surname = $_POST["regSName"];
$firstname = $_POST["regFName"];

JS验证数据

var error="";
var name = document.getElementById( "regFName" );

if(valPass() == false)
{
    error = "Password must contain an UpperCase, LowerCase, Number and Symbol character";
    document.getElementById( "error_para" ).innerHTML = error;
    return false;
}

var email = document.getElementById( "regEName" );
if( email.value == "" || email.value.indexOf( "@" ) == -1 )
{
    error = " You Have To Write Valid Email Address. ";
    document.getElementById( "error_para" ).innerHTML = error;
    return false;
}

else
{

return true;
}

1 个答案:

答案 0 :(得分:1)

正确的{0:'myTest'}不是method

methode