Angularjs - 简单的形式提交 [英] Angularjs - simple form submit

查看:136
本文介绍了Angularjs - 简单的形式提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过与AngularJs学习曲线,我发现有几乎没有例子服务于现实世界中使用。

I am going through learning curve with AngularJs and I am finding that there are virtually no examples that serve real world use.

我想获得一个清醒的认识如何提交一个表单最标准组件,并把它传递到PHP文件。

I am trying to get a clear understanding of how to submit a form with the most standard components and pass it on to a PHP file..

有没有人对提交简单的,未污染的很好的例子,形式,帮助我,也许许多其他Angularjs初学者..

Does anyone have any good examples on submitting simple, un-polluted, forms that would help me and probably numerous other Angularjs beginners..

当我说一个干净的形式,我指的是这样的事情。

When I say a clean form I am referring to something like this..

<div ng-app="myApp">

    <form name="saveTemplateData" action="#" ng-controller="FormCtrl" ng-submit="submitForm()">

        First name:    <br/><input type="text" ng-model="form.firstname">    <br/><br/>
        Email Address: <br/><input type="text" ng-model="form.emailaddress"> <br/><br/>

        <textarea rows="3" cols="25" ng-model="form.textareacontent"></textarea>

            <br/><br/>

        <input type="radio" ng-model="form.gender" value="female" />Female ...
        <input type="radio" ng-model="form.gender" value="male" />Male <br/>

            <br/><br/>

        <input type="checkbox" ng-model="form.member" value="5"/> Already a member

            <br/><br/>

        <input type="file" ng-model="form.file_profile" id="file_profile"><br/>
        <input type="file" ng-model="form.file_avatar" id="file_avatar">

            <br/><br/>

        <!-- <button ng-click="save()" >Save</button> -->
        <input type="submit" ngClick="Submit" >

    </form>

</div>

我的NG-应用code ...

My ng-app code...

var app = angular.module('myApp', []);
app.controller('FormCtrl', function ($scope, $http) {

     var formData = {
        firstname: "default",
        emailaddress: "default",
        textareacontent: "default",
        gender: "default",
        member: false,
        file_profile: "default",
        file_avatar: "default"
    };

    $scope.save = function() {
        formData = $scope.form;
    };

    $scope.submitForm = function() {
        console.log("posting data....");
        formData = $scope.form;
        console.log(formData);
        //$http.post('form.php', JSON.stringify(data)).success(function(){/*success callback*/});
    };

 });

我想三个问题我从这里开始......是

I guess three questions I have from here on are...


  1. 我的PHP文件应该如何与这个互动(怎么我得到的JSON字符串在PHP文件中的数组)?

  2. 我将如何提交一个复选框的值时,该复选框是真的吗?

  3. 我找了很多资料abotu使用jQuery与角提交图片,,我看到有一个形象的对象在本次提交已经,,我该如何找回这些数据?有什么注意事项处理图像包括哪些内容?

我愿意采取任何简洁明了的信息,并组装一个很好的学习的榜样给大家...

I am willing to take any clear and concise information and assemble a good learning example for everyone...

推荐答案

我已经做了相当多的研究和尝试解决不同的问题,我最终来解决的很大一部分在我的其他张贴在这里

I have been doing quite a bit of research and in attempt to resolve a different issue I ended up coming to a good portion of the solution in my other post here:

Angularjs - ?表单提交数据未发布

该解决方案不包括目前上传图片,但我打算在扩大和创造一个清楚和工作示例。如果更新这些职位可能我要让它永远保持最新一路,直到一个稳定且易于学习的例子进行编译。

The solution does not include uploading images currently but I intend to expand upon and create a clear and well working example. If updating these posts is possible I will keep them up to date all the way until a stable and easy to learn from example is compiled.

这篇关于Angularjs - 简单的形式提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆