Forums

Preventing an email from being sent if a value is not found.

davecoventry 07 Feb, 2014
I've been asked to set something up on an existing Joomla installation.

If a user submits information that requires information to be emailed to him, then an email is sent.

If he doesn't then no email is sent.

I can't see how to disable the email.

There's a PHP array called "main_event_actions" which contains the following stdClass objects:

Array (
[0] => stdClass Object (
[id] => 1612
[chronoform_id] => 12
[type] => custom_serverside_validation
[enabled] => 1
[params] =>
[order] => 16
[content1] => {PHP code}
)
[1] => stdClass Object (
[id] => 1617
[chronoform_id] => 12
[type] => auto_serverside_validation
[enabled] => 1
[params] => {PHP Code}
[order] => 2
[content1] =>
)
[2] => stdClass Object (
[id] => 1613
[chronoform_id] => 12
[type] => custom_code
[enabled] => 1
[params] => mode=controller action_label=Classify Breed
[order] => 25
[content1] => {PHP Code} //<---- my custom code to verify the information submitted and to send the email (or not)
)
[3] => stdClass Object (
[id] => 1614
[chronoform_id] => 12
[type] => email
[enabled] => 1
[params] => {subject=Email from_email=noreply@royalcaninbreedersclub.com, etc, etc}
[order] => 20
[content1] => main_event_actions);
)
)

I've tried using this:

if(!$matches){
$breed='generic';
foreach($form->main_event_actions as $action => $actiondata){
if($actiondata->type=='email'){
$actiondata->enabled=0;//<----this doesn't change the entry.
$actiondata->params='';//<----nor does this.
}
}
}

For some reason I cannot change the main_event_action if it's the type 'email'.
However, other main_event_action types can be changed.


if($actiondata->type=='custom_serverside_validation'){//<--- if this isn't the 'email' type
$actiondata->enabled=0;//<----this works
$actiondata->params='';//<----as does this.
}

Can anyone suggest a solution?
GreyHead 08 Feb, 2014
Hi davecoventry,

Please see this FAQ and check my Email [GH] action.

Bob
davecoventry 08 Feb, 2014
Hi Bob,

Thanks for your assistance. I'd done a lot of googling, but hadn't seen that FAQ; thank you!

I'm not sure that the first option would work as the form is validated and the user's data is entered into the database. It's only the sending of the email that I wish to halt if the user has no use for the information. If the user has met certain conditions, then he will require an email to be sent to him. If he doesn't there is no need for the email and I don't wish for it to be sent.

The second and third options use the [GH] version. What is the [GH] nomenclature? I certainly can't find an option on the version that I'm trying to use (Chronoforms 4.0 RC3.4.1) for a conditional drop box.

The forth option is for another component to be added. It's early days with this client and I'm reluctant to ask him to make wholesale changes to his site. So I want to avoid this if I can.

The fact is that he's running Joomla 1.5 and Chronoforms 4.0 RC3.4.1 so both in need of an upgrade and a major overhaul at some stage in the future. Just not yet.

It's the last option on your FAQ list that most interests me, though, and I'm using the Custom Code action to evaluate whether to send the email. The problem is that I see no way of stopping the email being sent.

As I mentioned in the OP, I'm trying to alter the "main_event_actions" array's email type and change the enabled flag, but this doesn't work as it's either immutable or there's something that changes it back after I change it.


foreach($form->main_event_actions as $action => $actiondata){
  if($actiondata->type=='email'){
    $actiondata->enabled=0;//<----this doesn't change the entry.
    $actiondata->params='';//<----nor does this.
  }
}


It does actually work on the other "main_event_actions" array types.
if($actiondata->type=='custom_serverside_validation'){//<--- if this isn't the 'email' type
  $actiondata->enabled=0;//<----this works
  $actiondata->params='';//<----as does this.
}


But this doesn't help me.
GreyHead 08 Feb, 2014
Hi davecoventry,

The [GH] actions are custom actions that I have written, usually they add functionality that is not in Max's standard actions. The [GH] email action has a 'conditional' option that does, I think, exactly what you are looking for.

Bob
davecoventry 08 Feb, 2014
Hi Bob,

It certainly sounds like it!

How do I get this added functionality?

~ Dave
GreyHead 08 Feb, 2014
Hi Dave,

There's a link in the FAQ.

Bob
davecoventry 11 Feb, 2014
Hi Bob,

I'm a little bit adrift here.

I presume that the Email[GH] module is an add on to the chronoforms component.

I don't see a download link, though. Do I download something? How do I install it?

~ Dave
davecoventry 12 Feb, 2014
It's ok, I found the download link at the bottom of the page
davecoventry 12 Feb, 2014
Hmmm.

My problem is that the field that I want to test on has 77 different possibilities.

If the field contains text that matches one of those possibilities, then I want an email sent. If it doesn't, then I want the email aborted.
GreyHead 12 Feb, 2014
Hi davecoventry,

And having 77 options is a problem because . . . ?

Bob
davecoventry 12 Feb, 2014
Hi Bob,

The help suggests that you can abort the email on a value and gives the example as {send_email}::Yes.

Are you suggesting that this would work:

{breed}::Akita||Anatolian Shepherd||Bordeaux Mastiff||Irish Wolfhound||Majorca Mastiff...

Dave
GreyHead 12 Feb, 2014
HI Dave,

No, that won't work at all, but if you add a Custom code action before the Email [GH] action and add code like this, then you should be in with a chance:
<?php
$breeds = array(
  Akita||Anatolian Shepherd||Bordeaux Mastiff||Irish Wolfhound||Majorca Mastiff
);
$breeds = array(
  'Akita',
  'Anatolian Shepherd',
  'Bordeaux Mastiff',
  'Irish Wolfhound',
  'Majorca Mastiff',
);
$send_email = 'no';
if ( in_array($form->data['breed'], $breeds) ) {
  $send_email = 'yes';
}
$form->data['send_email'] = $send_email;
?>
and put {send_email}::yes in the Condition box.

Bob

PS If you have the breeds in a database table then you could also load the list from there - or use a MySQL query to check.
davecoventry 12 Feb, 2014
Just to clarify.

I'm not looking for one option out of 77.

The option list contains 700 different entries in the drop-down.

If the option selected from the dropdown box is one of 77 values, then the email is sent.

If it's not, then no email is sent.

For example, "Afgan Hound" has an entry in the 77 defined values, but Beagle does not.

I want to check the value from the {breed} field and if the value matches one of the 77, then the email is sent. If the user selects "Beagle" then no match will be found and the email will not be sent.
davecoventry 12 Feb, 2014
Sorry,

I must've typed my clarification post at the same time as your post.

I obviously would need to define "send_email" as a hidden field.

Can I add this to a custom form type?

Under the preview tab it says

Your form type is "Custom" and so you can NOT add/edit the form fields (code) in the wizard, any fields you add here now will NOT be saved.

davecoventry 12 Feb, 2014
I've gone to 'Edit' for the form and added the line:

<input type=hidden id="send_email" name="send_email" value="yes" />

at the bottom of the code displayed under the 'Code' tab.

However, this doesn't seem to work as I just get a white screen when I submit the form.

The 'Template' code box simply has the following code:

<?php

$form->data['send_email'] = 'yes';
$matches=true;
if(!$matches){
  $form->data['send_email'] = 'no';
}


?>
davecoventry 17 Feb, 2014
Hi Bob,

As far as I can tell I have the email[GH] working.

However, I cannot add the hidden input field {send_email} as the form is of the type "Custom" .

Your form type is "Custom" and so you can NOT add/edit the form fields (code) in the wizard, any fields you add here now will NOT be saved.



I've tried to fool it by adding to the $form->data array by implementing a "Custom Code" core action in the onLoad event:
<?php
$form->data['send_email'] = 1;
?>


However, the form does not send:

Debug Data
Email info
Conditional Email cancelled: send_email was not 1



I've tried building the form from scratch, but this breaks it and I'm consistently getting white screens.

I feel that, if I could successfully add the send_email hidden input field, then I might be some way towards solving this.

~ Dave
GreyHead 19 Feb, 2014
Hi Dave,

I'm sorry, I've lost track of what you are doing here. What do you need a hidden input for? (And if you do need one then you can surely just add it to your Custom Form HTML.)

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