close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Send an email only if a field contains a particular string

Thread began 5/20/2021 9:06 am by MagsW | Last modified 5/21/2021 1:15 pm by Ray Borduin | 42 views | 7 replies |

MagsW

Send an email only if a field contains a particular string

Hi Ray, I have a dynamically populated form which sends an email when submitted. The form has a repeating checkbox field with a list of events, which have three possible categories. I want to send the email to different people depending on which categor(ies) the event comes under. I think the simplest way is to include a particular text string in the checkbox value field which will show depending on which categories the event comes under, then surround the email code with an IF statement. I've got this far but I think my IF statement is wrong:

<?php if(isset($_POST['event']) && preg_match("EventType1", $_POST['event'])) { ?>

(email code in here)

<?php } ?>

The checkbox field looks like this:

<input name="event[]" type="checkbox" value="<?php echo($rsEvents->getColumnVal("Title")); ?>, <?php echo($rsEvents->getColumnVal("Venue")); ?>, <?php echo date("l j F",strtotime($rsEvents->getColumnVal('Date')));?> <?php if ($rsEvents->getColumnVal("EventType1") == 1) { ?>
EventType1<?php } ?> <?php if ($rsEvents->getColumnVal("EventType2") == 1) { ?>
EventType2<?php } ?> <?php if ($rsEvents->getColumnVal("EventType3") == 1) { ?>
EventType1<?php } ?>">

I can see in Chrome Inspector that the checkbox value is displaying correctly, but my email doesn't send.

Sign in to reply to this post

Ray BorduinWebAssist

Try:

php:
<?php if(isset($_POST['event']) && in_array("EventType1",$_POST['event'])) { ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

That gives me the following error message:

Notice: Array to string conversion in /var/www/vhosts/mysite.co.uk/events.php on line 21

I've attached a copy of the actual page if it helps!

Sign in to reply to this post

Ray BorduinWebAssist

Line 21 is:
$WAFV_Errors .= WAValidateRQ(((isset($_POST["event"]))?$_POST["event"]:"") . "",false,5);

You are trying to treat event like a string instead of array on that line. I think you should use:
$WAFV_Errors .= WAValidateRQ(((isset($_POST["event"]))?implode(",",$_POST["event"]):"") . "",false,5);

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

MagsW

That didn't work either - no error message showing but the email doesn't send and no redirect to ?sent=true. I've attached the updated page in case I've missed something!

Sign in to reply to this post

Ray BorduinWebAssist

Your event checkbox value is set to:

php:
value="<?php echo($rsEvents->getColumnVal("Title")); ?><?php echo($rsEvents->getColumnVal("Venue")); ?><?php echo date("l j F",strtotime($rsEvents->getColumnVal('Date')));?> <?php if ($rsEvents->getColumnVal("Mortgages") == 1) { ?>

MortgageEvent<?php ?> <?php if ($rsEvents->getColumnVal("Protect") == 1) { ?>
ProtectionEvent<?php ?> <?php if ($rsEvents->getColumnVal("Compliance") == 1) { ?>
ComplianceEvent<?php ?>"



But your IF statement is checking if the value is "MortgageEvent"

It will never be that value, so that code would never run.

It looks like you have multiple checkboxes in a repeat region. What if more than one checkbox is checked? Would it send more than one email?

I think this code:

php:
<?php if(isset($_POST['event']) && in_array("MortgageEvent",$_POST['event'])) { // send if Mortgage Event ?>

<?php
if (isset($_POST["submit"]) || isset($_POST["submit_x"]))     {  //WA Universal Email
  
$Email = new WA_Email("events_2");
  
$Email->Redirect "?sent=true#success";
  
$Email->From "your from";
  
$Email->addTo("your to");
  
$Email->BodyFile "../webassist/email/event-registration.php";
  if (
function_exists("rel2abs") && $Email->Redirect$Email->Redirect $Email->Redirect?rel2abs($Email->Redirect,dirname(__FILE__)):"";
  for (
$emailGroup=0$emailGroup<sizeof($Email->To); $emailGroup++) {
    
$Email->Subject "Event Registration";
    
$Email->send($emailGroup);
  }
  
$Email->close();
}
?>
<?php 
// send if ?>



Maybe should be:

php:
<?php if(isset($_POST['event'])) { // send if Mortgage Event ?>

<?php 
for ($x=0$x<sizeof($_POST['event']); $x++) { // loop on checked boxes ?>
<?php
if (strpos($_POST['event'][$x],"MortgageEvent") !== false)     {  //WA Universal Email
  
$Email = new WA_Email("events_2");
  
$Email->From "your from";
  
$Email->addTo("your to");
  
$Email->BodyFile "../webassist/email/event-registration.php";
  if (
function_exists("rel2abs") && $Email->Redirect$Email->Redirect $Email->Redirect?rel2abs($Email->Redirect,dirname(__FILE__)):"";
  for (
$emailGroup=0$emailGroup<sizeof($Email->To); $emailGroup++) {
    
$Email->Subject "Event Registration";
    
$Email->send($emailGroup);
  }
  
$Email->close();
}
?>
<?php 
// loop on checked boxes 
header("location: ?sent=true#success");
?>
<?php 
// send if ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

That works! My plan is to put that IF statement around the $Email->addTo line and then do two more so that if the user selects a Protection or Compliance event the email goes to someone different. Would you mind removing the details in the post above though as it contains identifiable info? Thanks again!

Sign in to reply to this post

MagsW

Thanks again Ray, have just sent you a tip! :-)

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