Jump to content

Creating a custom confirmation message: Difference between revisions

From NusaATK
m How to create your own cofirmation message moved to Creating a custom confirmation message
No edit summary
 
Line 1: Line 1:
{{howto|easy|Jorge Garifuna <http://www.GariDigital.com>}}
At times you may want to confirm a specific action before the user continues.
At times you may want to confirm a specific action before the user continues.


Line 7: Line 9:
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:
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
<syntaxhighlight lang="php">
          function action_view(&$handler){
// called on record viewing
              // user has not called this action before and has not clicked on the cancel button of the record
function action_view(&$handler)
              if (empty($this->m_postvars['confirm']) && empty($this->m_postvars['cancel']) && empty($this->m_postvars['atkcancel'])){
{
                  $page = &$this->getPage();   
  // user has not called this action before and has not clicked on the cancel button of the record
                  // add the confirmation form to the page     
  if (empty($this->m_postvars['confirm']) && empty($this->m_postvars['cancel']) &&  
                  $page->addContent($this->confirmAction($this->m_postvars['atkselector'], "view", false, TRUE));   
    empty($this->m_postvars['atkcancel']))
                  return;             
  {
              }elseif (!empty($this->m_postvars['cancel'])){
    $page = &$this->getPage();   
                  // Confirmation page was displayed and 'cancel' was clicked
 
                  $location = $this->feedbackUrl("view", ACTION_CANCELLED);
    // add the confirmation form to the page     
                  $this->redirect($location);     
    $page->addContent($this->confirmAction($this->m_postvars['atkselector'], "view", false, TRUE));   
                  return;           
    return;             
              }
  }
              // move on with performing this action                               
  elseif (!empty($this->m_postvars['cancel']))
              return $handler->action_view();
  {
          }
    // 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();
}
</syntaxhighlight>
            
            
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.
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.
Line 29: Line 39:
This function is called automatically as long as it has the form:
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.
<syntaxhighlight lang="php">function confirmMyActionText($atkselector)</syntaxhighlight>
 
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:
For our example, since the action that I want to confirm is the "view" action, my function looks as follows:


    function confirmViewText($atkselector){
<syntaxhighlight lang="php">
          return "Are you sure you want to do this?";
function confirmViewText($atkselector)
    }// end function
{
  return "Are you sure you want to do this?";
}// end function
</syntaxhighlight>


Well, that's it!
Well, that's it!
Line 42: Line 57:


http://www.achievo.org/forum
http://www.achievo.org/forum
Until next time,
----
Jorge Garifuna<br>
Professional Web Developer<br>
Garinet Global Inc.<br>
http://www.GariDigital.com

Latest revision as of 07:59, 13 February 2007

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