1

Rookie question.

I am trying to create a contact form with angularjs and python backend on google app engine. The form so far does send the email, however the Subject and Body fields are not captured in the email. Can someone tell what I am doing wrong?

HTML:

<body ng-app="submitExample">
<form ng-submit="submit()" ng-controller="ExampleController">
    <div>
       <p>Name</p>
       <input ng-model="name" name="name" id="name" rows="1" cols="20"/>
    </div>
    <div>
       <p>Email</p>
       <input ng-model="email" name="email" id="email" rows="1" cols="20"/>
    </div>
    <div><p></p><input type="submit" value="Send Email"></div>
</form>
</body>

angularjs:

angular.module('submitExample',[]).controller('ExampleController', function($scope,$http){
        $scope.formData;
        $scope.submit = function() {
            $http({
                method: "post",
                url: "/sign",
                data: {
                    name: $scope.name,
                    email:  $scope.email
                }
            })
        }
});

Python:

class SendEmail(webapp2.RequestHandler):
 def post(self):
    from_address = cgi.escape(self.request.get('email'))
    to_address = "[email protected]"
    subject = cgi.escape(self.request.get('name'))
    body = "xxx"
    mail.send_mail(from_address, to_address, subject, body)

1 Answer 1

2

I found the answer.

Instead of this angularjs code:

angular.module('submitExample',[]).controller('ExampleController', function($scope,$http){
    $scope.formData;
    $scope.submit = function() {
        $http({
            method: "post",
            url: "/sign",
            data: {
                name: $scope.name,
                email:  $scope.email
            }
        })
    }
});

Use this one:

angular.module('submitExample', []).controller('ExampleController', function($scope,$http,$httpParamSerializerJQLike) {
        $scope.formData;
        $scope.submit = function() {
            $http({
                method: "post",
                url: "/sign",
                data: $httpParamSerializerJQLike({
                    name: $scope.name,
                    email:  $scope.email
                }),
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            })
        };
});

Works like a charm.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.