I am working on a registration form in symfony2 with angular js. My doubt is can we do angular js validations in a symfony2 form? because i cannot validate the form and also i dont know how to post form values to symfony controller.. please help.. I am stuck in project..
please check my registration.html.twig code..
<body ng-app="LoginApp">
<div id="register" class="animate form" ng-controller="RegisterController as registerCtrl">
{{ form_start(form, {'attr': {'name':'registerFrm', 'id':'registerFrmId','novalidate': '', 'ng-submit':'registerCtrl.registerFrm()'}}) }}
Your username
{{ form_row(form.username) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[username].$error.required">Username is required!</span>
Your email
{{ form_row(form.email) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[email].$invalid">Invalid email</span>
Your password
{{ form_row(form.plainPassword.first) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[plainPassword][first].$error.required">Password is required!</span>
Please confirm your password
{{ form_row(form.plainPassword.second) }}
<span class="error" ng-show="submitted && registerFrm.adminuser[plainPassword][second].$error.required">Password is required!</span>
<p class="signin button">
<input type="submit" name="signup" ng-model="signup" ng-click="submitted=true" value="Sign up" />
</p>
{{ form_end(form) }}
</div>
<script>
var App = angular.module('LoginApp',[]);
App.controller('RegisterController', ['$scope',function($scope) {
}]);
</script>
</body>
My symfony form builder
$builder
->add('username', TextType::class , array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.username',
'id' => 'usernamesignup',
'placeholder' => 'myusername690',
'required' => false)
))
->add('email', TextType::class , array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.email',
'id' => 'emailsignup',
'placeholder' => '[email protected]',
'ng-pattern' => '/^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/',
'required' => false)
))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array(
'label' => false,
'attr' => array(
'ng-model' => 'formData.password',
'id' => 'passwordsignup',
'placeholder' => 'eg. X8df!90EO',
'required' => false)
),
'second_options' => array('label' => false,
'attr' => array(
'ng-model' => 'formData.confirm_password',
'id' => 'passwordsignup_confirm',
'placeholder' => 'eg. X8df!90EO',
'required' => false)
),
)
);