我的表单代码是
<form name="myForm" ng-controller="Ctrl" action="form.php" method="POST">
Name: <input name="input" ng-model="userName" name="name" required placeholder="Enter Name"><br>
Email: <input name="email" ng-model="userEmail" name="email" required placeholder="Enter Email"><br>
<input type="submit" name="submit"><br>
<tt>userType = {{userName}}</tt><br>
<tt>userEmail = {{userEmail}}</tt><br>
</form>
我的脚本是
<script >
function Ctrl($scope) {
$scope.userName = '';
$scope.userEmail = '';
}
</script>
form.php代码是
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$email = $_POST['email'];
echo $name."<br>";
echo $email."<br>";
}
如何将表单值传递给php,任何想法
答案 0 :(得分:1)
这是一个吸虫:http://plnkr.co/edit/fC1GikCS0v1tDVTG37vZ?p=preview
<强>控制器强>
function Ctrl($scope, $http) {
$scope.user = {
name : '',
email: ''
};
$scope.submit = function(user){
$http.post('/form.php', user);
}
}
<强> HTML 强>
<form name="myForm" ng-controller="Ctrl" ng-submit="submit(user)">
Name: <input type="text" ng-model="user.name"><br>
Email: <input type="email" ng-model="user.email"><br>
<input type="submit" name="submit"><br>
</form>
答案 1 :(得分:0)
在上面的代码中你使用名称标签两次.. 这是在PHP代码中它没有拿起数据。