close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Universal Email IF statement to compare form input with database value before sending email

Thread began 6/11/2015 5:52 am by Mags | Last modified 7/03/2015 11:03 am by Ray Borduin | 1742 views | 5 replies |

Mags

Universal Email IF statement to compare form input with database value before sending email

I have a few automated emails set up on a record update page. Different emails are sent depending on which checkboxes are ticked. I've wrapped each email code with IF statements so that the emails are only sent under conditions, for example the following email is only sent if the OrderSigned and ContractSigned boxes are checked and AERemoved, FactFind and DataTemplate are all unchecked:

<?php if(isset($_POST['OrderSigned']) && $_POST['OrderSigned'] =="1" && ($_POST['ContractSigned'] != "1") && ($_POST['AERemoved'] != "1") && ($_POST['FactFind'] != "1") && ($_POST['DataTemplate'] != "1")) { ?>
[Email code]
<?php } ?>

The form records the progress of an application so only one box is ticked per update, for example the first update would have OrderSigned ticked, the next update would have ContractSigned ticked and so on. However this means that users must tick the boxes in a specific order, otherwise the wrong emails will be generated - for example, if the user ticked ContractSigned the relevant email would be sent, but if they then ticked OrderSigned, the ContractSigned email would be sent again because the value is already "1".

A better way of doing this would be to compare input values with existing database values, so for example the user ticks ContractSigned and updates the record, the IF statement checks to see if ContractSigned is already "1" in the database and only sends the email if the value is "0". Does that make sense? How would I alter my code to do this?

Sign in to reply to this post

Ray BorduinWebAssist

You could store the value in the database before submission in a hidden form element and compare the values before sending.

<?php if (isset($_POST['OrderSigned']) && $_POST['OrderSigned'] =="1" && $_POST['HiddenOrderSigned'] != "1") { ?>

Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

Hi Ray, many thanks for that - all works perfectly now!

Sign in to reply to this post

Mags

Hi Ray, I now need to do a similar comparison but this time with a date field. I want to compare the submitted date with the existing date in the database and only send an email if the values are different. I tried the following:

<?php if (isset($_POST['StagingDate']) && $_POST['StagingDate'] != $_POST['HiddenStagingDate']) { ?>

[Universal Email behavior in here]

<?php } ?>

However it sends the email regardless of whether the date value is different or not. How do I alter the above code to get it to work?

Sign in to reply to this post

Ray BorduinWebAssist

It probably has different date formats.

Try writing the two values and see what the differences are:

<?php if (isset($_POST['StagingDate']) && $_POST['StagingDate'] != $_POST['HiddenStagingDate']) {
die($_POST['StagingDate'] .":".$_POST['HiddenStagingDate']);
?>

Sign in to reply to this post
Did this help? Tips are appreciated...

Mags

Hi Ray

It was the date format that was the problem - I had forgotten to use strtotime in the hidden date field. Working now!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...