One of my pages in a website is a simple form to redeem a coupon (update the status of the coupon in the database). My update function exists in my own custom extension and I have added the id, class and function to the exp_actions table in the database.

I know I have to use $action_id = ee()->functions->fetch_action_id('Lb_cart_ext', 'redeem_coupon'); to retrieve the action id from the database and {AID:Lb_cart_ext:redeem_coupon} in the front end to use the action id in a link.

Where do I use/call the $action_id = ee()->functions->fetch_action_id('Lb_cart_ext', 'redeem_coupon'); line?

2 Answers 2


If I am understanding this correctly what you need to go is create the form that will be displayed this is where you would pass the action id to the form. YEah this won't work in an extension. please move it to a module

How to do this you say, well let's say in your module you create another function that will generate the form and with all the required data and when you call this function on the front end it will display the entire for with all you fields required etc .

Eg this is in your module

//inside this you will get your action id

$action_id = ee()->functions->fetch_action_id('Lb_cart_ext', 'redeem_coupon');

// you will then pass your action id along with your other form data to a ee form //declaration function. you will first need to build your form data this is done like this

// Build an array with the form data

$hidden_fields = array('ACT'=> action_id,'other_hidden_items'=>$other_Data);

$form_data = array(
    "id" => ee()->TMPL->form_id,
    "class" => ee()->TMPL->form_class,
    "hidden_fields" => $hidden_fields

// Fetch contents of the tag pair, ie, the form contents this gets your inputs you have add //to your form i.e your other inputs

$tagdata = ee()->TMPL->tagdata;

//finally declare the form with all the required form data

$form = ee()->functions->form_declaration($form_data) .$tagdata . "close form tags";

//return the form

return $form


On your template it will then look something like this {exp:module_name:form class="test_form"} //input name="fav_car" //input submit type="submit" {/exp:module_name:form}

Hope this helps



Usually it is used for making form hidden fields in modules. In your case (for simple form) it is possible better to use {AID:class:method} tag in template:

<form method="post">
<input type='hidden' name='ACT' value='{AID:Lb_cart_ext:redeem_coupon}' >
<input type="hidden" name="csrf_token" value="{csrf_token}">
<input type="submit">

But I think it is first time when I see that somebody use it with extension. Don't even know if it will work.

I made couple tests - you can't use actions with extensions.

So you need to create module if you want proceed forms this way (Bevin describe it).

Alternative way is add session_start or session_endt hook and check for specific _POST data to start proceed form by extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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