english/administrator/components/com_messages/controllers/config.php
/**
	 * Method to save a record.
	 */
Method to save a record.
Method to save a record .
public function save()
	{
		JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
		$app		= JFactory::getApplication();
		$model		= $this->getModel('Config', 'MessagesModel');
		$data		= JRequest::getVar('jform', array(), 'post', 'array');
		$form	= $model->getForm();
		if (!$form) {
			JError::raiseError(500, $model->getError());
			return false;
		}
		$data = $model->validate($form, $data);
		if ($data === false) {
			$errors	= $model->getErrors();
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if (JError::isError($errors[$i])) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}
			$this->setRedirect(JRoute::_('index.php?option=com_messages&view=messages', false));
			return false;
		}
		if (!$model->save($data))
		{
			$this->setMessage(JText::sprintf('JERROR_SAVE_FAILED', $model->getError()), 'warning');
			$this->setRedirect(JRoute::_('index.php?option=com_messages&view=messages', false));
			return false;
		}
		$this->setMessage(JText::_('COM_MESSAGES_CONFIG_SAVED'));
		$this->setRedirect(JRoute::_('index.php?option=com_messages&view=messages', false));
		return true;
	}
public function save ( ) { JRequest :: checkToken ( ) or jexit ( JText :: _ ( 'JINVALID_TOKEN' ) ) ; $ app = JFactory :: getApplication ( ) ; $ model = $ this -> getModel ( 'Config' , 'MessagesModel' ) ; $ data = JRequest :: getVar ( 'jform' , array ( ) , 'post' , 'array' ) ; $ form = $ model -> getForm ( ) ; if ( ! $ form ) { JError :: raiseError ( 500 , $ model -> getError ( ) ) ; return false ; } $ data = $ model -> validate ( $ form , $ data ) ; if ( $ data === false ) { $ errors = $ model -> getErrors ( ) ; for ( $ i = 0 , $ n = count ( $ errors ) ; $ i < $ n && $ i < 3 ; $ i ++ ) { if ( JError :: isError ( $ errors [ $ i ] ) ) { $ app -> enqueueMessage ( $ errors [ $ i ] -> getMessage ( ) , 'warning' ) ; } else { $ app -> enqueueMessage ( $ errors [ $ i ] , 'warning' ) ; } } $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_messages&view=messages' , false ) ) ; return false ; } if ( ! $ model -> save ( $ data ) ) { $ this -> setMessage ( JText :: sprintf ( 'JERROR_SAVE_FAILED' , $ model -> getError ( ) ) , 'warning' ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_messages&view=messages' , false ) ) ; return false ; } $ this -> setMessage ( JText :: _ ( 'COM_MESSAGES_CONFIG_SAVED' ) ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_messages&view=messages' , false ) ) ; return true ; }
Method to save a record.
Method to save a record .
// Check for request forgeries. // Initialise variables. // Validate the posted data. // Check for validation errors. // Get the validation messages. // Push up to three validation messages out to the user. // Redirect back to the main list. // Attempt to save the data. // Redirect back to the main list. // Redirect to the list screen.