0

how to add auto redirect URL after voting ? its possible? here is the code

public function vote(){
    $app = JFactory::getApplication();
    $params = $app->getParams();
    $vote=$params->get('vote');
    $db =JFactory::getDBO();
    $user=JFactory::getUser();
    $user_id=$user->id;
    $vid=JRequest::getVar('vid');
    $Itemid=JRequest::getVar('Itemid');
    $ip=$_SERVER['REMOTE_ADDR']; 
    if($ip):
    $sql="SELECT COUNT(*) FROM #__photo_contest_ip WHERE item_id='$vid' AND ip_address='$ip'";
    $db->setQuery($sql);
    $count=$db->loadResult();
    endif;

    if($user_id):
    $sql="SELECT COUNT(*) FROM #__photo_contest_ip WHERE item_id='$vid' AND user_id='$user->id'";
    $db->setQuery($sql);
    $count1=$db->loadResult();
    endif;
    if($count || $count1):
    $msg = JText::_('COM_PHOTO_CONTEST_ITEM_VOTE_ALREADY');
    else:
        if($vote==2 && empty($count)):
            $query = $db->getQuery(true);
            $query->update('#__photo_contest_photo');
            $query->set('votes=votes+1');
            $query->where('id='.$vid);    
            $db->setQuery($query);
            $db->query();
            $insert= "INSERT INTO #__photo_contest_ip(ip_address,item_id) values ('$ip','$vid')";
            $db->setQuery($insert);
            $db->query();

            if (!$db->query()) {
                        $this->setError($db->getErrorMsg());
                        return false;
             }
             $msg = JText::_('COM_PHOTO_CONTEST_ITEM_VOTE_SUCCESSFULLY');


          elseif($vote==1 && $user_id>0):
            $query = $db->getQuery(true);
            $query->update('#__photo_contest_photo');
            $query->set('votes=votes+1');
            $query->where('id='.$vid);    
            $db->setQuery($query);
            $db->query();
            $insert= "INSERT INTO #__photo_contest_ip(ip_address,item_id,user_id) values ('$ip','$vid','$user_id')";
            $db->setQuery($insert);
            $db->query();

            if (!$db->query()) {
                        $this->setError($db->getErrorMsg());
                        return false;
             }
              $msg = JText::_('COM_PHOTO_CONTEST_ITEM_VOTE_SUCCESSFULLY');
          else:
              $msg = JText::_('COM_PHOTO_CONTEST_ITEM_VOTE_LOGIN');
          endif;


     endif;
     $link=JRoute::_('index.php?option=com_photo_contest&view=photocontest&id='.$vid.'&Itemid='.$Itemid, false);
     $this->setRedirect($link, $msg);


}
0

Use this instead:

$app->enqueueMessage($msg, 'Success');
$app->redirect($link);

That will queue up your system message and then redirect the application to your link.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.