Skip to content

Commit

Permalink
Contact page modified to use JSON request
Browse files Browse the repository at this point in the history
  • Loading branch information
hackazon committed Nov 17, 2014
1 parent 1790016 commit e66dedb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion assets/views/pages/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@
form.hzBootstrapValidator().on('success.form.bv', function(e) {
var l = Ladda.create(document.querySelector( '#form-submit' ));
l.start();
var data = {};
$("#contactForm").serializeArray().map(function(x){data[x.name] = x.value;});
$.ajax({
url: '/contact',
type: "POST",
dataType: "json",
data: $("#contactForm").serialize(),
data: "data=" + JSON.stringify(data),
success: function(data) {
$(".alert").empty().append('Thank you for your question. We will contact you as soon.').show();
form.hide();
Expand Down
8 changes: 5 additions & 3 deletions classes/App/Controller/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ public function action_index() {
$this->view->pageTitle = "Contact us";
if ($this->request->method == 'POST') {
$this->checkCsrfToken('contact');
$post = $this->request->post();
$post = json_decode($this->request->post()['data']);
$this->pixie->orm->get('ContactMessages')->create($post);
if ($this->request->is_ajax())
if ($this->request->is_ajax())
$this->execute = false;
}
$this->view->subview = 'pages/contact';
}
}

}

8 changes: 4 additions & 4 deletions classes/App/Model/ContactMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class ContactMessages extends \PHPixie\ORM\Model {

public function create($post)
{
$this->name = $post['contact_name'];
$this->email = $post['contact_email'];
$this->phone = $post['contact_phone'];
$this->message = $post['contact_message'];
$this->name = $post->contact_name;
$this->email = $post->contact_email;
$this->phone = $post->contact_phone;
$this->message = $post->contact_message;
if (!is_null($this->pixie->auth->user())) {
$this->customer_id = $this->pixie->auth->user()->id;
}
Expand Down

0 comments on commit e66dedb

Please sign in to comment.