Cel*_*tas 1 html javascript php forms
我正在使用JavaScript练习表单验证,但是当我尝试从页面检索数据时它提交给我无法得到它.
form.html
<body>
Hello.<br />
<form onsubmit="return validate()" action="process.php" method="POST">
Enter name: <input type="text" id="name" /><br />
Enter phone number: <input type="text" id="number" /><br />
Enter password: <input type="password" id="paswd" /><br />
Is there anything else you would like to add: <input type="text" id="anything" /><br />
<input type="submit" value="Check Form" />
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
process.php
<?php
echo 'Here: '.$_POST['number']
?>
Run Code Online (Sandbox Code Playgroud)
无论我使用什么索引,我都会得到"Undefined index:line 2".我究竟做错了什么?
编辑:所以我不能使用id我需要的属性name?无论如何都要防止编码冗余,因为所有names 的值将与相应的值相同id?
您需要name在字段中使用属性
<input type="text" id="number" name="number" />
Run Code Online (Sandbox Code Playgroud)
$_POSTname在字段中查找属性以捕获字段值而不是id