Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据从Angular表单传递到PHP_Javascript_Php_Angularjs - Fatal编程技术网

Javascript 将数据从Angular表单传递到PHP

Javascript 将数据从Angular表单传递到PHP,javascript,php,angularjs,Javascript,Php,Angularjs,我试图通过ajax将表单数据保存在Angular中以存储.php文件。但是,数据似乎不是通过文件正确获取的。有人能指出错误吗 <form id="form1" post="content/store.php"> <div class="form-group"> <label for="examplename">Name</label> <input type="text" class="form-co

我试图通过ajax将表单数据保存在Angular中以存储.php文件。但是,数据似乎不是通过文件正确获取的。有人能指出错误吗

<form id="form1" post="content/store.php">

    <div class="form-group">
        <label for="examplename">Name</label>
        <input type="text" class="form-control" id="examplename" placeholder="Enter your name">
    </div>

    <div class="form-group">
        <label for="exampleemail">Email</label>
        <input type="email" class="form-control" id="exampleemail" placeholder="Enter your email">
    </div>

    <button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>          

</form>
STORE.PHP

<?php
  $postdata = file_get_contents("php://input");
  $request = json_decode($postdata);
  @$email = $request->email;
  @$pass = $request->pass;
  echo $email; 
?>

如果要在控制器中使用

电子邮件:$scope.email

名称:$scope.name

或者密码,您需要在视图中具有ng模型绑定,如下所示:

<form id="form1" post="content/store.php">

    <div class="form-group">
        <label for="examplename">Name</label>
        <input type="text" class="form-control" id="examplename" placeholder="Enter your name" ng-model="name">
    </div>

    <div class="form-group">
        <label for="exampleemail">Email</label>
        <input type="email" class="form-control" id="exampleemail" placeholder="Enter your email" ng-model="email">
    </div>

    <button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>          

</form>

名称
电子邮件
提交

您应该声明您的输入
ng型号

i、 e

<input type="email" ng-model="email" class="form-control" id="examplename" placeholder="Enter your name">
<input type="password" ng-model="pass" class="form-control" id="exampleemail" placeholder="Enter your email">
注意:

如果希望将输入字段作为密码,请更改
type=“password”

如果您希望将输入保持在控制器中,只需更改即可


$scope.email
$scope.name
但最好在
输入中声明这些字段,即
ng model=“email”
ng model=“pass”

尝试$\u POST而不是file\u get\u内容(“php://input");
<input type="email" ng-model="email" class="form-control" id="examplename" placeholder="Enter your name">
<input type="password" ng-model="pass" class="form-control" id="exampleemail" placeholder="Enter your email">
email: $scope.email,
pass: $scope.password