Restrict form actions based on conditions

In a previous topic you have blocked the add, edit and delete actions according to some conditions (user level, the article assigned user ID etc.). This hides the buttons from the list, but if the form page is accessed directly and the URL is altered, the actions will still execute. To prevent this you will have to add some conditions to each possible operation.

Allow insert only for authors

The NeXTensio form allows executing three different operations on the same page - insert, update and delete. Also, the condition to be met for each operation is different, so you cannot block the entire page from loading just to prevent a single operation. To block a specific operation from the form, you can use a Throw Error trigger. A trigger is an action that gets executed before or after the main operation. The Throw Error trigger executes before the operation and can stop it if set so.

To prevent unauthorized users from adding new articles follow the next steps:

  1. Open the admin/form page in Dreamweaver.

  2. Go to the Server Behaviors tab > Plus (+) > MX Kollection > Forms and select the Throw Error entry.

  3. On the first tab of the user interface that loads - Basic - define what error message to display:


                     

  4. Next click the Advanced tab to decide to what action the check will be applied, and to set the condition:


                    

  5. Click OK to close the user interface and apply the changes.

Save the page. If you login with an editor account and enter the form URL in the browser's address bar to add a new article, the error message defined earlier will be displayed. The form still appears, but the insert will not work:

 

Note: The error message displayed differs when in Development or Production mode. For more information about the error reporting modes, see this page.

Allow delete only for the webmaster

Next you have to block the delete operation for all users except for the webmaster. To do so you will use the same approach as above, with some differences:

  1. Open the admin/form page.
  2. Go to the Server Behaviors tab > Plus (+) > MX Kollection > Forms and select the Throw Error entry.
  3. In the Basic tab, in the Error message textarea enter: You are not authorized to delete articles!
  4. In the Advanced tab, in the Transactions list leave only the del_article_art transaction and remove the others:


                  
  5. Click OK when you are done configuring the user interface.
Save the page. If you try to remove an article and you are not logged in with the webmaster account, the error message will be displayed.

Allow update only for assigned articles

Editing an article is allowed in two situations, as explained in a previous topic, which can be reduced to one condition: the user ID set in the assigned_to_art column must match the currently logged in user ID. The update operation on the form must be allowed only if the two match. To create this condition you must first create a filtered recordset that retrieves the ID of the user, and then apply a Throw Error server behavior configured on the correct condition.

To stop unauthorized users from editing articles follow the next steps:

  1. Open the admin/form page in Dreamweaver.

  2. Go to the Bindings tab > Plus (+) > Recordset (Query).

  3. Configure the Recordset interface as shown below:


                       

  4. Go to the Server Behaviors tab > Plus (+) > MX Kollection > Forms and select the Throw Error entry.

  5. In the first tab of the user interface that loads - Basic - define what error message to display.

  6. In the Advanced tab, from the Transaction list remove all entries except for the upd_article_art transaction. In the Priority text field enter 1.

  7. Click OK twice to apply the server behavior.

Now the restrictions are completely created, and only the correct users can add, edit or delete articles.

 

Where to go from here

This concludes the Content Management System (CMS) tutorial that uses MX Kollection 3 and KTML 4 to allow your users create their own rich content. You can further improve this application by:

If you want to find out more things you can do with MX Kollection 3, check out the online tutorials here.

For help on editing content with KTML 4, read this tutorial.