How can I store data from Symfony formbuilder into an Array?
up vote
1
down vote
favorite
I am creating a form with formbuilder:
$formBuilder->add($fieldMapping['fieldName'], TextType::class, array('attr' => array('class' => 'form-control')), 'required' => 'true');
When I am saving the form I am able to store the data from the form into an array:
$('.create-item').on( 'click', function (e) {
forms(e,this);
});
function forms(e,el) {
var id = $(el).attr("data-id");
var target = $(el).attr("data-target");
e.preventDefault();
var $link = $(e.currentTarget);
$.ajax({
method:'POST',
data: {
"id": id,
"target": target
},
url: $link.attr('href')
}).done(function(data){
$('.form-output').html(data.output);
$('#form_save').on( 'click', function (e) {
e.preventDefault();
var form = $(this).closest('form');
var formData = form.serializeArray();
$.ajax({
method:'POST',
url:'{{ path('forms', { 'slug': page.slug }) }}',
data: {
"data": formData
},
success: function(data){
window.location.reload();
}
});
});
});
}
So the output of the variable formData is:
[
{name:"form[id]", value:""},
{name:"form[username]", value:""},
{name:"form[plainPassword]", value:""},
{name:"form[email]", value:""},
{name:"form[isActive]", value:"1"},
{name:"form[_token]", value:"123414234"}]
The information I would also need in this array is if "required = true". Is there a chance to add this to the array?
arrays json symfony formbuilder
add a comment |
up vote
1
down vote
favorite
I am creating a form with formbuilder:
$formBuilder->add($fieldMapping['fieldName'], TextType::class, array('attr' => array('class' => 'form-control')), 'required' => 'true');
When I am saving the form I am able to store the data from the form into an array:
$('.create-item').on( 'click', function (e) {
forms(e,this);
});
function forms(e,el) {
var id = $(el).attr("data-id");
var target = $(el).attr("data-target");
e.preventDefault();
var $link = $(e.currentTarget);
$.ajax({
method:'POST',
data: {
"id": id,
"target": target
},
url: $link.attr('href')
}).done(function(data){
$('.form-output').html(data.output);
$('#form_save').on( 'click', function (e) {
e.preventDefault();
var form = $(this).closest('form');
var formData = form.serializeArray();
$.ajax({
method:'POST',
url:'{{ path('forms', { 'slug': page.slug }) }}',
data: {
"data": formData
},
success: function(data){
window.location.reload();
}
});
});
});
}
So the output of the variable formData is:
[
{name:"form[id]", value:""},
{name:"form[username]", value:""},
{name:"form[plainPassword]", value:""},
{name:"form[email]", value:""},
{name:"form[isActive]", value:"1"},
{name:"form[_token]", value:"123414234"}]
The information I would also need in this array is if "required = true". Is there a chance to add this to the array?
arrays json symfony formbuilder
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am creating a form with formbuilder:
$formBuilder->add($fieldMapping['fieldName'], TextType::class, array('attr' => array('class' => 'form-control')), 'required' => 'true');
When I am saving the form I am able to store the data from the form into an array:
$('.create-item').on( 'click', function (e) {
forms(e,this);
});
function forms(e,el) {
var id = $(el).attr("data-id");
var target = $(el).attr("data-target");
e.preventDefault();
var $link = $(e.currentTarget);
$.ajax({
method:'POST',
data: {
"id": id,
"target": target
},
url: $link.attr('href')
}).done(function(data){
$('.form-output').html(data.output);
$('#form_save').on( 'click', function (e) {
e.preventDefault();
var form = $(this).closest('form');
var formData = form.serializeArray();
$.ajax({
method:'POST',
url:'{{ path('forms', { 'slug': page.slug }) }}',
data: {
"data": formData
},
success: function(data){
window.location.reload();
}
});
});
});
}
So the output of the variable formData is:
[
{name:"form[id]", value:""},
{name:"form[username]", value:""},
{name:"form[plainPassword]", value:""},
{name:"form[email]", value:""},
{name:"form[isActive]", value:"1"},
{name:"form[_token]", value:"123414234"}]
The information I would also need in this array is if "required = true". Is there a chance to add this to the array?
arrays json symfony formbuilder
I am creating a form with formbuilder:
$formBuilder->add($fieldMapping['fieldName'], TextType::class, array('attr' => array('class' => 'form-control')), 'required' => 'true');
When I am saving the form I am able to store the data from the form into an array:
$('.create-item').on( 'click', function (e) {
forms(e,this);
});
function forms(e,el) {
var id = $(el).attr("data-id");
var target = $(el).attr("data-target");
e.preventDefault();
var $link = $(e.currentTarget);
$.ajax({
method:'POST',
data: {
"id": id,
"target": target
},
url: $link.attr('href')
}).done(function(data){
$('.form-output').html(data.output);
$('#form_save').on( 'click', function (e) {
e.preventDefault();
var form = $(this).closest('form');
var formData = form.serializeArray();
$.ajax({
method:'POST',
url:'{{ path('forms', { 'slug': page.slug }) }}',
data: {
"data": formData
},
success: function(data){
window.location.reload();
}
});
});
});
}
So the output of the variable formData is:
[
{name:"form[id]", value:""},
{name:"form[username]", value:""},
{name:"form[plainPassword]", value:""},
{name:"form[email]", value:""},
{name:"form[isActive]", value:"1"},
{name:"form[_token]", value:"123414234"}]
The information I would also need in this array is if "required = true". Is there a chance to add this to the array?
arrays json symfony formbuilder
arrays json symfony formbuilder
asked Nov 21 at 14:17
Jarla
2,13511637
2,13511637
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10
add a comment |
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414058%2fhow-can-i-store-data-from-symfony-formbuilder-into-an-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why you would like to retreive that info in the client side while you have it in the server side ?
– zizoujab
Nov 21 at 16:02
I do not have access to it on the server side
– Jarla
Nov 21 at 16:10