PreAction & PostAction Examples

PreAction & PostAction are not commands in the traditional sense. They are intercepts that allow you to insert script directly before or after any Miva Merchant action and affect the processing of the action commands using regular Storemorph page templates as a subroutine. You can also construct your own custom action command scripts.

In the examples below we add a custom customer field for called Tax_id. Examine any page template that contains a form and you will find an action command taken from the ACAD Customer Create page.

<input type="hidden" name="Action" value="ICST">

When the form is submitted the ICST action instructs Merchant to insert a new customer record. Merchant will validate the data before saving the record but if an error occurs, the user is returned to the ACAD screen to correct the error. If you add additional fields to the form, Merchant will simply ignore them. By inserting one or both of these new actions you can provide your own validation script for the extra data.

<form method="post" action="&mvt:global:secure_sessionurl;">
<input type="hidden" name="Store_Code" value="&mvte:global:Store_Code;">
<input type="hidden" name="PreAction" value="PREACTION_ACAD">
<input type="hidden" name="Action" value="ICST">
<input type="hidden" name="PostAction" value="POSTACTION_ACAD">

<mvt:if expr="NOT g.Tax_id_Invalid">
  <h5 class="floatleft">Tax Id:</h5>
  <h5 class="invalid floatleft">Tax Id:</h5>
<input type="text" name="Tax_id" size=15 value="&mvte:global:tax:id;">

In this example PREACTION_ACAD is the page code for the custom page template. Validate the Tax_id field data.

<mvt:if expr="(ISNULL g.PreAction) AND ('PREACTION_' IN g.Action NE 1)">
  <mvt:exit />

<mvt:item name="ry_toolbelt" param="assign|g.acaderror|" />
<mvt:item name="ry_toolbelt" param="assign|g.Tax_id|encodeentities(trim(g.Tax_id))" />
<mvt:if expr="ISNULL g.Tax_id">
  <mvt:item name="ry_toolbelt" param="assign|g.Tax_id_Invalid|1" />
  <mvt:item name="ry_toolbelt" param="assign|g.acaderror|1" />

In this example POSTACTION_ACAD is the page code for the custom page template. Redirect the user in case of an error.

<mvt:if expr="(ISNULL g.PostAction) AND ('POSTACTION_' IN g.Action NE 1)">
  <mvt:exit />

<mvt:if expr="g.acaderror">
    A validation error was triggered during PREACTION. Go back to the ACAD screen
  <mvt:item name="ry_toolbelt" param="assign|g.Screen|'ACAD'" />