src/Controller/FeedbackController.php
public function save() {
	    $this->request->allowMethod(['post', 'ajax']);

		$data = $this->request->getData();

		//Is ajax action
		$this->viewBuilder()->setLayout('ajax');

		//Save screenshot:
		$data['screenshot'] = str_replace('data:image/png;base64,', '', $this->request->getData('screenshot'));

		//Add current time to data
		$data['time'] = time();

		//Check name
		if (empty($data['name'])) {
			$data['name'] = __d('feedback', 'Anonymous');
		}

		if (!$this->request->getSession()->started()) {
			$this->request->getSession()->start();
		}
		$data['sid'] = $this->request->getSession()->id();

		//Determine method of saving
		$collection = new StoreCollection();
		$result = $collection->save($data);

		if (empty($result)) {
			throw new NotFoundException('No stores defined.');
		}

		// Only first result is important
		$result = array_shift($result);

		//Prepare result
		if (!$result['result']) {
			$this->response->statusCode(500);

			if (empty($result['msg'])) {
				$result['msg'] = __d('feedback', 'Error saving feedback.');
			}
		} else {
			if (empty($result['msg'])) {
				$result['msg'] = __d('feedback', 'Your feedback was saved successfully.');
			}
		}

		$this->set('msg', $result['msg']);

		//Send a copy to the reciever:
		if (!empty($data['copyme'])) {
			//FIXME: Move to a store class
			$this->Feedbackstore->mail($data, true);
		}
	}
public function save() {
	    $this->request->allowMethod(['post', 'ajax']);

		$data = $this->request->getData();

		//Is ajax action
		$this->viewBuilder()->setLayout('ajax');

		//Save screenshot:
		$data['screenshot'] = str_replace('data:image/png;base64,', '', $this->request->getData('screenshot'));

		//Add current time to data
		$data['time'] = time();

		//Check name
		if (empty($data['name'])) {
			$data['name'] = __d('feedback', 'Anonymous');
		}

		if (!$this->request->getSession()->started()) {
			$this->request->getSession()->start();
		}
		$data['sid'] = $this->request->getSession()->id();

		//Determine method of saving
		$collection = new StoreCollection();
		$result = $collection->save($data);

		if (empty($result)) {
			throw new NotFoundException('No stores defined.');
		}

		// Only first result is important
		$result = array_shift($result);

		//Prepare result
		if (!$result['result']) {
			$this->response->statusCode(500);

			if (empty($result['msg'])) {
				$result['msg'] = __d('feedback', 'Error saving feedback.');
			}
		} else {
			if (empty($result['msg'])) {
				$result['msg'] = __d('feedback', 'Your feedback was saved successfully.');
			}
		}

		$this->set('msg', $result['msg']);

		//Send a copy to the reciever:
		if (!empty($data['copyme'])) {
			//FIXME: Move to a store class
			$this->Feedbackstore->mail($data, true);
		}
	}
public function save ( ) { $ this -> request -> allowMethod ( [ 'post' , 'ajax' ] ) ; $ data = $ this -> request -> getData ( ) ; //Is ajax action $ this -> viewBuilder ( ) -> setLayout ( 'ajax' ) ; //Save screenshot: $ data [ 'screenshot' ] = str_replace ( 'data:image/png;base64,' , '' , $ this -> request -> getData ( 'screenshot' ) ) ; //Add current time to data $ data [ 'time' ] = time ( ) ; //Check name if ( empty ( $ data [ 'name' ] ) ) { $ data [ 'name' ] = __d ( 'feedback' , 'Anonymous' ) ; } if ( ! $ this -> request -> getSession ( ) -> started ( ) ) { $ this -> request -> getSession ( ) -> start ( ) ; } $ data [ 'sid' ] = $ this -> request -> getSession ( ) -> id ( ) ; //Determine method of saving $ collection = new StoreCollection ( ) ; $ result = $ collection -> save ( $ data ) ; if ( empty ( $ result ) ) { throw new NotFoundException ( 'No stores defined.' ) ; } // Only first result is important $ result = array_shift ( $ result ) ; //Prepare result if ( ! $ result [ 'result' ] ) { $ this -> response -> statusCode ( 500 ) ; if ( empty ( $ result [ 'msg' ] ) ) { $ result [ 'msg' ] = __d ( 'feedback' , 'Error saving feedback.' ) ; } } else { if ( empty ( $ result [ 'msg' ] ) ) { $ result [ 'msg' ] = __d ( 'feedback' , 'Your feedback was saved successfully.' ) ; } } $ this -> set ( 'msg' , $ result [ 'msg' ] ) ; //Send a copy to the reciever: if ( ! empty ( $ data [ 'copyme' ] ) ) { //FIXME: Move to a store class $ this -> Feedbackstore -> mail ( $ data , true ) ; } }
Ajax function to save the feedback form.

@return \Cake\Http\Response|null
Ajax function to save the feedback form .