close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Can't use a php IF test in UniversalEMail?

Thread began 12/13/2010 4:04 pm by SaladoGuy | Last modified 12/16/2010 6:45 am by Jason Byrnes | 2548 views | 8 replies |

SaladoGuyBeta Tester

Can't use a php IF test in UniversalEMail?

Hello,

For almost a week I've been working on this simple problem and can't figure it out ...

On this website that I'm building (done with eCart and other WA extentions), customers buy classes. It may be a one day class or a multi-day class. In the email confirmation receipt it is important for the customer to see the dates of the class they just bought so they know when to show up :-)

It's easy enough to print both dates:

<?php //echo $eCart1->DisplayInfo("Date"); . " - " . $eCart1->DisplayInfo("Through"); ?>


( FYI $eCart1->DisplayInfo("Through") is a cart attribute that I created and it does work, perfectly, everywhere else on the site )

I can also assign those dates to variables and format them nicely:

$bdate = $eCart1->DisplayInfo("Date");
$edate = $eCart1->DisplayInfo("Through");
print date('l F jS, Y', strtotime($bdate));

And all of that works great both on the site pages and in the confirmation email. The email is a UE4 object, but I believe it was created as part of the eCart checkout wizard.

With these functions I can get a nice looking date such as:

Thursday December 21st, 2023
through —
Fri., Dec. 22nd


The breakdown occurs on one-day classes. I don't want to print 2 dates on the one day classes, it looks bad and confuses the customers.

On the php web pages this is is to do, I simply put the "through -" and the second date inside an if statement and only display them if the start date and end dates don't match:


<?php //echo $eCart1->DisplayInfo("Date"); . " - " . <?php echo $eCart1->DisplayInfo("Through"); ?>
<?php
$bdate = $eCart1->DisplayInfo("Date");
$edate = $eCart1->DisplayInfo("Through");
print date('l F jS, Y', strtotime($bdate));
//echo $eCart1->DisplayInfo("Date");

if ($bdate != $edate) { // Show if date doens't match
print "<br /><em>&nbsp;&nbsp; through &nbsp; &mdash;</em><br />" . date('D., M. jS', strtotime($edate));
//print "&nbsp;-&nbsp;to&nbsp;-&nbsp;" . date('D., M. jS', strtotime($edate));
} // Show if date doens't match
?>

However, not matter what I try, I cannot get an if statement to work correctly in an email.

I've tried all kinds of things, my last try was:



<?php if ($bdate != $edate) { echo "does not match"; }?>
<?php if ($bdate == $edate) { echo "does match"; }?>
<?php if ($bdate != $edate) { print "does not match"; }?>
<?php if ($bdate == $edate) { print "does match"; }?>

<!--Show if date doens't match-->
<?php if ($eCart1->DisplayInfo("Date") != $eCart1->DisplayInfo("Through")) { "<br /><em>&nbsp;&nbsp; through &nbsp; &mdash;</em><br />" . date('D., M. jS', strtotime($edate)); }?>
<?php // alternate print line:// print "&nbsp;-&nbsp;to&nbsp;-&nbsp;" . date('D., M. jS', strtotime($edate)); ?>
<!--Show if date doens't match-->

Does anyone know how to do this in an email?

Thanks

Sign in to reply to this post

SaladoGuyBeta Tester

Here's the relevant files in case it helps (attached) ....

Attached Files
email_if_test.zip
Sign in to reply to this post

SaladoGuyBeta Tester

If anything about that post wasn't clear or I need to explain it better, please let me know.

Sign in to reply to this post

Jason ByrnesWebAssist

look at the lines that do work, they are not using an echo, but instead, they are applying the text to the $MailBody variable:

$MailBody = $MailBody . date('D., M. jS', strtotime($edate));



you need to do the same with your if statement. instead of:
if ($bdate != $edate) { echo "does not match"; }


use:
if ($bdate != $edate) { $MailBody = $MailBody . "does not match"; }

Sign in to reply to this post

SaladoGuyBeta Tester

Originally Said By: Jason Byrnes
  look at the lines that do work, they are not using an echo, but instead, they are applying the text to the $MailBody variable:
use:
if ($bdate != $edate) { $MailBody = $MailBody . "does not match"; }  



Thanks! That was it.

Sign in to reply to this post

CraigRBeta Tester

Hooray!

I'm glad I picked up this thread, I was experiencing a similar problem

showthread.php?t=17722

Can someone at WA confirm, that if you have an 'if' statement in the code, that the 'edit in dreamweaver' option for UE4 doesn't give you the correct result.

Can I also assume that it would be a bad idea to edit the email via the server behavior interface once these changes have been hand coded ?

FYI my issue now appears to be resolved, the only other problem I had was that a value from a recordset want being included in the email, but this was fixed by moving the server behavior code block to below the recordset block.

Sign in to reply to this post

Jason ByrnesWebAssist

it all depends on how you code the if statement.

coding the if statement like this will not work correctly:

php:
<?php
if("this" != "that") {
    echo((isset(
$_POST["textfield"]))?$_POST["textfield"]:"");
} else {
    echo((isset(
$_POST["textfield2"]))?$_POST["textfield2"]:"");
}
?>



however, coding the if statement like this will:

php:
<?php if("this" != "that") { ?>
<?php 
echo((isset($_POST["textfield"]))?$_POST["textfield"]:""); ?>
<?php 
} else { ?>
<?php 
echo((isset($_POST["textfield2"]))?$_POST["textfield2"]:""); ?>
<?php 
?>




the key is that universal email will transalate code in the following form:

php:
<?php echo((isset($_POST["textfield"]))?$_POST["textfield"]:""); ?>



to:

php:
$MailBody = $MailBody . ((isset($_POST["textfield"]))?$_POST["textfield"]:"");



but when it is literally surrounded in the if statement, it does not translate properly.

Sign in to reply to this post

CraigRBeta Tester

thanks Jason.

For now, I edited the waue_confirm_1.php manually to get the desired result

if i revisit this page via the interface and use dreamweaver edit, i assume the template is re-created from the waue_confirm_1.php in the correct format

Sign in to reply to this post

Jason ByrnesWebAssist

it should be, yes.

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...