0

i would like to submit my form to a php file

var myApp = angular.module('myApp',[]);
myApp.controller('FormController', function($scope, $http) {
  $scope.task = {
    group: 'fix',
    showme: true,
    select1: 'basique',
    select2: 'micro',
    select3: '1',
    select4: '1',
    select5: 'jour'
  };
  
  var server = 'http://localhost/myserver.php?cd=add';
  var parameters;
  
  $scope.submit = function(form) {
    angular.forEach($scope.task, function(value, key) {
      if(value) {
        if(key === 'date') {
          value = new Date(value).getTime();
        }
        parameters += '&'+key+'='+value;
      }
    });
    console.log(server+parameters);
    //$http.post(server+parameters)
    //.success(function(result) {
    //  console.log("success", result);
    //})
    //.catch(function(error) {
    //  console.log("error", error);
    //})
  }
})

this is the codpen codepen is this valid?

the result at should be http://localhost/myserver.php?cd=add'name='&'describe='

1 Answer 1

1

You are create query string using foreach() and pass with server url but. you are use $http.post(). you have to use $http.get() if you want pass with server url.

Below example with help

$scope.submitForm = function($valid)
{ 
    myobject = {'email' : $scope.user.email, 'pass' : $scope.user.pass};
    Object.toparams = function ObjecttoParams(obj)
    {
        var p =[];
        for (var key in obj)
        {
            p.push(key + '=' + encodeURIComponent(obj[key]));
        }
        return p.join('&');
    };

    $http({
        url: WSURL + '/login',
        method: "POST",
        data: Object.toparams(myobject),
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function (data, status, headers, config) 
    {

    }
    }).error(function (data, status, headers, config) 
    {

    });
}
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.