Creating a custom confirmation message

From Achievo/ATK Wiki

Jump to: navigation, search

ATK Howto: Creating a custom confirmation message

Complexity: easy
Author: Jorge Garifuna <http://www.GariDigital.com>

List of other Howto's

At times you may want to confirm a specific action before the user continues.

This document will teach you how to do that exactly in ATK.

First you need to place the following code at the location where you want t trigger the confirmation screen. Perfect locations for this could be at the action function (eg: action_view(), action_edit(), etc):

In this example I want to ask the user if he really want to view the record that he clicked on. In real life this example would probably not be that practical, but the intention is to illistrate how you can create your custom confirmations on ATK:

// called on record viewing
function action_view(&$handler)
{
  // user has not called this action before and has not clicked on the cancel button of the record
  if (empty($this->m_postvars['confirm']) && empty($this->m_postvars['cancel']) && 
     empty($this->m_postvars['atkcancel']))
  {
    $page = &$this->getPage();   
 
    // add the confirmation form to the page     
    $page->addContent($this->confirmAction($this->m_postvars['atkselector'], "view", false, TRUE));   
    return;            
  }
  elseif (!empty($this->m_postvars['cancel']))
  {
    // Confirmation page was displayed and 'cancel' was clicked
    $location = $this->feedbackUrl("view", ACTION_CANCELLED);
    $this->redirect($location);    
    return;           
  }
  // move on with performing this action                              
  return $handler->action_view();
}

Now that you have triggered your confirmation, you need to add a function that will have the text the user will see on the confirmation screen.

This function is called automatically as long as it has the form:

function confirmMyActionText($atkselector)

where MyAction is the name of the action you have chosen to confirm.

For our example, since the action that I want to confirm is the "view" action, my function looks as follows:

function confirmViewText($atkselector)
{
  return "Are you sure you want to do this?";
}// end function

Well, that's it!

If you have any questions about this, feel free to bring it up at the ATK forum located at:

http://www.achievo.org/forum

Personal tools
Navigation