esedic
12/16/2015 - 6:04 PM

controller.php

<?php

function save()
{
  $app = JFactory::getApplication();
  $db = JFactory::getDBO();
  $query = $db->getQuery(true);
  
  $app = JFactory::getApplication();
	$menu = $app->getMenu();
	$active = $menu->getActive();
	$itemId = $active->id;
	$message = $active->params->get('message');

	$_data = array();
	$_data = JRequest::getVar('jpainter', array(), 'post', 'array');

  $query->insert('#__jpainter_data')
    ->columns(
      array(
        $db->quoteName('image'),
        $db->quoteName('name_surname'),
        $db->quoteName('age'),
        $db->quoteName('city'),
        $db->quoteName('parent_name_surname'),
        $db->quoteName('address'),
        $db->quoteName('parent_city'),
        $db->quoteName('email')
      )
    )
    ->values("'". $_data['image'] . "','" 
    .  $_data['name_surname'] . "','"
    .  $_data['age'] . "','"
    .  $_data['city'] . "','" 
    .  $_data['parent_name_surname'] . "','" 
    .  $_data['address'] . "','" 
    .  $_data['parent_city'] . "','" 
    .  $_data['email']."'");

    $db->setQuery($query);

    try
    {
      $db->execute();
    }
    catch (RuntimeException $e)
    {
      JError::raiseError(500, $e->getMessage());
    }

  $lastRowId = $db->insertid();
  $this->sendMail($_data, $lastRowId);

  $this->setMessage($message);
  $this->setRedirect(JRoute::_('index.php?option=com_jpainter&view=jpainter&Itemid='.$itemId, false));
}