Hello, I have the following codes: Routes
Router::connect('/', array('controller' => 'pages', 'action' => 'home', 'home'));
Router::connect('/post', array('controller' => 'Posts', 'action' => 'display', 'Posts/index'));
Router::connect('/admin', array('controller' => 'users', 'action' => 'login', 'admin' => true));
/**
* ...and connect the rest of 'Pages' controller's URLs.
*/
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Js
$(".btnFormNeed").on("click", function () {
if ($.validador()) {
var parametros = {
"NeedClient": $(".txtClient").val(),
"NeedNeed": $(".txtNeed").val(),
"NeedObjective": $(".txtObjective").val()
};
$.ajax({
data: parametros,
url: '/',
type: 'post',
dataType: "json",
success: function (response) {
if(response==="si"){
//logica para avanzar a la siguiente vista de cake, la cual no se como se haced desde Jquery
} else{
//sacar mensaje flash de cake desde jquery lo cual tampoco se.
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("error");
}
});
}
});
I'm supposed to insert the form data, the thing is that I do not know what I should change to get to the url, the view is home, I show them ps routes where the driver's route is of home, and not if there is something that I have to change to insert.
PagesController
public function home() {
if ($this->request->is('post')) {
if (!empty($this->request->data)) {
$this->Flash->error(__("Emty"));
$this->loadModel('Need');
$this->Need->create();
if ($this->Need->save($this->request->data)) {
$this->Need->save(array(
'date' => date("Y/m/d")
));
$this->set('doctor', "si");
}
$this->set('doctor', "no");
} else {
$this->set('doctor', "no");
}
} else {
$this->set('doctor', "no");
}
}
That is the controller, the thing is that you can not read the paramatros that you send by post method, to insert them in the database, in pure php you would read $_POST["NeedClient"]; $_POST["NeedNeed"]; $_POST["NeedObjective"];
but in cake I do not know how to do it.
Home - view
<div id="divNeeds" class="row" hidden="true">
<div class="container">
<div class="row">
<div class="col-5">
<h1 id="h1NeedsTitle" class="lang" key="h1NeedsTitle">Descubrir necesidades</h1>
<h4 class="lang" key="h4FNeedsFirstText">
El comienzo de una estratégia funcional es conoces nuestro <br>
objetivo y que necesidades queremos resolver, de esta forma <br>
nuestro equipo a través de un laboratorio enlaza un vínculo con <br>
la marca y da comienzo al plan estrategico.
</h4>
</div>
<div class="col-1">
</div>
<div class="col-6">
<?php
echo $this->Form->create('Need', array('class' => '', 'id' => 'msform'));
?>
<h1 class="lang" key="h1NeedForm">Aprovechemos el tiempo y comencemos</h1>
<?php
echo $this->Form->input('client', array('label' => array('text' => "¿Para que marca vamos a trabahar?",
'key' => 'lblClient', 'class' => 'lang'), 'placeholder' => 'Dinos el nombre de tu empresa',
'class' => 'validador txtClient lang', 'key' => 'txtClient'));
echo $this->Form->input('need', array('label' => array('text' => "Escríbenos acerca de tu necesidad",
'key' => 'lblNeed', 'class' => 'lang'), 'placeholder' => 'Agradecemos nos detalles muy bien la necesidad, '
. 'es nuestro punto de partida para generar ideas quer fortalezcan la estrategia para resolverla.',
'rows' => '4', 'class' => 'validador txtNeed lang', 'key' => 'txtNeed', 'style' => 'resize: none;'));
echo $this->Form->input('objective', array('label' => array('text' => "¿Cuál es el objetivo?",
'key' => 'lblObjective', 'class' => 'lang'), 'placeholder' => 'Que se quiere alcanzar con la'
. 'solución de la necesidad, ¿Adquirir usuario? ¿Mejorar ventas? ¿Posicionar la marca? ... entre otros.'
. ' Agradecemos nos detalles muy bien el objetivo.', 'rows' => '4',
'class' => 'validador txtObjective lang', 'key' => 'txtObjective', 'style' => 'resize: none;'));
?>
<div class="container">
<div class="row">
<div class="col-6">
<label class="lang" key="lblAddNeed">Tienes otra necesidad </label>
<img src="https://image.flaticon.com/icons/png/512/37/37240.png" class="imgAddNeed"/>
</div>
<div class="col-6">
<?php
$options = array(
'class' => 'lang btnFormNeed',
'label' => 'Enviar y continuar',
'key' => 'btnFormNeed',
'type' => 'button'
);
echo $this->Form->end($options);
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>