cakephp 3.0 passing data to the form.php -
i using modelless form send contact email. using example in cookbook.
with change data in objects form arrays unsure form data in being passed contactform.php
i have tried $data['name']
, $data[0]['name']
view input name without data[]
<input type="text" class="form-control" name="name" placeholder="your name" required="" aria-required="true" aria-invalid="false">
pagescontroller.php
public function contact(){ $this->request->allowmethod('ajax'); $contact = new contactform(); if ($this->request->is('post')) { if ($contact->execute($this->request->data)) { $data = array( 'status' => 'successful' ); } else { $data = array( 'status' => 'error' ); } $this->set(compact('data')); // pass $data view $this->set('_serialize', 'data'); } }
contactform.php
protected function _execute(array $data) { // send email. $email = new email('default'); $email->emailformat('html'); $email->template('demotemplate')->viewvars( array('username' => $data[0]['name'], 'usercompany' => '$data', 'useremail' => '$data', 'userphone' => '$data')); $email->from('info@domain.com'); $email->to('$data'); $email->bcc('$data'); $email->subject('contact form submission'); if ($email->send()) { return true; } else { return false; } }
well use first tool advanced-rest-client, , inside code of cakephp can use try , catch, can user debug()
too, example debug($data);
in combination advanced-rest-client can see result.
and if debug dont work serialice data
$this->set('data', $data); $this->set('_serialize', ['data']);
but when serialized data use advanced-rest-client, select post
option , type url of want post
.
so:
public function contact(){ $this->request->allowmethod('ajax'); $contact = new contactform(); if ($this->request->is('post')) { if ($contact->execute($this->request->data)) { debug($this->request->data());//first $datos = $this->request->data();//second $data = [ 'content' => $datos, 'status' => 'successful', ]; } else { $datos = $this->request->data(); $data = [ 'content' => $datos, 'status' => 'error, ]; } $this->set(compact('data')); // pass $data view $this->set('_serialize', 'data'); } }
Comments
Post a Comment