0

I have an array

$result=array(
    ['firstname'] => 'xyz' ,
    ['lastname'] => 'abc');

this array value echoed in value attribute of input fields of html form

<form name="myForm"  action = "<?php echo base_url('welcome/submission');?>" method="POST">
    <input type="text" class="form-control" ng-model="firstname" name="firstname" value="<?php echo $result['firstname']; ?>" required ng-pattern="/^[a-zA-Z0-9]*$/">
    <span ng-show="myForm.firstname.$dirty && myForm.firstname.$error.required" style="color:red;">Your name is required.</span>
     <span ng-show="myForm.firstname.$dirty && myForm.firstname.$error.pattern" style="color:red;">invalid Entry.</span>
    <input type="text" class="form-control" name="lastname" ng-model="lastname" value="<?php echo $result['lastname']; ?>" required>
    <span ng-show="myForm.lastname.$dirty && myForm.lastname.$error.required" style="color:red;" >Last Name is required</span>
    <span ng-show="myForm.lastname.$dirty && myForm.lastname.$error.pattern" style="color:red;">invalid Entry.</span>
</form>

This is angular js code

<script>
 var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
     $scope.submitForm = function() {
     alert("123");
    //$scope.submitted = true;
    if (myForm.$valid) {
        alert('Form submitted - fields passed validation');
    }

  }; 
}); 
</script>

I need Values should be placed properly in the value attribute of input field but it does not happen. All i can see blank input fields if i inspect element value attribute is filled with proper data but not seen in the window. img 1 img 2

1
  • what is the output of <?php echo $result['lastname']; ?>, Have you checked your CSS if that is hiding your ECHO? use firebug or chrome console Commented Jun 20, 2018 at 6:53

1 Answer 1

3

For this to work, you have to pass the php variable to the first name model in your angular controller.

That’s where angular is reading the value from

$scope.firstname = "<?php echo $result['firstname']; ?>";
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it worked after seeing your answer i realized that angular js works on two way binding.

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.