I'm working with Symfony2 and have a form which has two submit actions:
- on a submit within the form
- a javascript submit()
In the first option the HTML5 form validation runs smoothly, but not in the second option, and the aplication send the parameters without show the tooltips. What is the reason for this?
Controller:
public function showCombosAction(Request $request){
$user = $this->getUser();
$form = $this->createForm(new InfoFormType(), NULL, array('foo' => $user->getRoles()[0]));
$form->handleRequest($request);
if ($form->isValid()) {
$params = $form->getData();
if (!isset($params['tienda1'])) $params['tienda1'] = $user->getStore()->getId();
$db = $this->get("db_connection_service");
$store = array();
if (isset($params['tienda2'])) {
//Comparamos tienda con tienda
$params['tienda2'] = $params['tienda2']->getId();
$store = $db->findDataStoreVsStore($params['tienda1'], $params['tienda2'], 4);
}else{
echo $params['tienda1'];
switch ($params['comparativa']){
case 'anterior':
break;
case 'totnacional':
$store = $db->findDataStoreVsNacional($params['tienda1'], 4);
break;
case 'totregion':
$store = $db->findDataStoreVsRegion($params['tienda1'], 4, $user->getStore()->getRegion());
break;
default:
break;
}
}
$this->showInfoTwoStoresAction($params['tipo'], $store[0], $store[1]);
}
return $this->render('AppBundle:Admin:showcombos.html.twig', array(
'form' => $form->createView()
));
}
View:
{% extends "AppBundle::layout.html.twig" %}
{% block fos_user_content %}
<form action="{{ path('frontend_show_combos') }}" method="POST" class="form- horizontal" name="combos">
{{ form_widget(form) }}
<div id="combos_tienda2"></div>
<input type="submit">
{{ form_end(form) }}
<script>
$(document).ready(function(){
var $comparativa = $('#combos_comparativa');
$comparativa.change(function() {
var $form = $(this).closest('form');
var data = {};
data[$comparativa.attr('name')] = $comparativa.val();
if ($comparativa.val() == "otra"){
$.ajax({
url : $form.attr('action'),
type: $form.attr('method'),
data : data,
success: function(html) {
$('#combos_tienda2').replaceWith(
$(html).find('#combos_tienda2')
)
$('#combos_tienda2').change(function(){
$form.submit();
}
);
}
});
}else{
document.combos.submit();
}
});
});
</script>
{% endblock fos_user_content%}
Thank You in advance.