2

Currently I have a function called redeem_coupon() in one of my modules in a EE2 project. I also have the button in a <form> element to link the function to. I know I have to add the function to the database table called exp_actions. I have the following code for the button:

<form action="./" name="redeemcouponform">
  <table>
    <tr>
      <td><input type="text" name="couponcode" maxlength="12"/></td>
      <td><input type="submit" name="submit" value="APPLY" class="button tiny success" /></td> </tr>
  </table>
  <input name="ACT" value="{AID:Lb_cart:redeem_coupon}" type="hidden">
</form>

Is there any specific way I need to connect the button to the ACT so it can fire the function when the button is clicked?

2

I assume this is a form on the front end, is that correct?

Assuming it is, and assuming clicking the button submits the form in the usual way, you just need to set the action attribute on your opening form tag to be a URL that includes the appropriate Action ID (the one tied to the redeem_coupon() method in your module).

The front end Action URL should look something like http://example.com/index.php?ACT=123 where the "123" is your Action ID. You'll want to set that ID dynamically and it looks like you already have a method for doing that (guessing by the {AID:Lb_cart:redeem_coupon} tag in your example).

For a good primer see A Brief Introduction to ExpressionEngine ACTions

If this form is in the control panel then the idea is similar, but the approach is a little different. Let me know if this form is in the Control Panel not the front end and I will update my answer.

5
  • PS I see from your other question that you might be trying to integrate your coupon function with Expresso Store. If that's the case you may want to consider creating an extension tied to one of Store's Extension Hooks to call your method. – Alex Kendrick Jun 19 '14 at 15:18
  • Hello, yes this is a form in the front-end and I am using store yes. So I can't use a normal form for this with store in the checkout stages, but rather create an extension? – heinkasner Jun 20 '14 at 10:13
  • You can. This separate-form approach should work in any of your templates. But creating a Store extension that runs when one of Store's forms is submitted might be a little easier and streamlined. – Alex Kendrick Jun 20 '14 at 14:59
  • @AlexKendrick Sorry to bring up an old thread, but can you tell me how to do an ACT in the control panel? – Don Rhummy Nov 18 '15 at 5:59
  • Hi Don. Please post a new question with more detail about what you are trying to accomplish. Too tricky to handle via comments. – Alex Kendrick Nov 18 '15 at 14:12

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.