Bypass a db Save action

bypass a database save action when a form field is empty.

Overview

The issue occurs because a database save action runs on every form submission, even when the comment field is left blank.
Use an event switcher action with conditional PHP to check if the comment field has content, and only trigger the database save action when data is present.

Answered
ch chriso0258 31 Jul, 2015
Hello,

On my form I have a textarea box where a user can add comments. In my on Submit event I have a db Save action to save the comments to a table I've set up to store them. The table includes a foreign key to another table as well as the date the form was submitted. A user may not always write a note when completing the form but because of the db Save action, a new record gets created in the comments table when the form is submitted. Is there a way I can bypass the db Save action if the is nothing written in the note box of the form?

Thanks for your insights.
Gr GreyHead 01 Aug, 2015
Answer
Hi chriso0258,

Use an Event switcher action; change the event list to say save_comment, save the action. Add PHP like this
<?php
if ( !empty($form->data['comment']) ) {
  return 'save_comment';
}
?>
Add your second DB Save action to the new save_comment event in the Event Switcher.

Bob
This topic is locked and no more replies can be posted.