Jump to content

Creating a custom confirmation message: Difference between revisions

From NusaATK
Create a custom confirmation message in ATK.
 
No edit summary
Line 47: Line 47:
----
----


Jorge Garifuna
Jorge Garifuna<br>
Professional Web Developer
Professional Web Developer<br>
Garinet Global Inc.
Garinet Global Inc.<br>
http://www.GariDigital.com
http://www.GariDigital.com

Revision as of 03:39, 13 February 2007

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:

- 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

Until next time,


Jorge Garifuna
Professional Web Developer
Garinet Global Inc.
http://www.GariDigital.com