[SOLVED]Sending conditional emails fileupload

elmarra

Member
Hi everyone.
I'm trying to set up a conditional email send.
I would like the email to be sent if a document has been uploaded in the file upload element in the form.
I currently have a manual checkbox, but I would like the email to be sent only if the file has been uploaded in the file upload element.
Do you have a tip for me?
A thousand thanks.
 
Hi there!

The email plugin for forms has a condition option. You could test there fi the upload field has a meaningful value. However, I'm not sure what happens when the actual upload of the file fails for some reason.

Kindly,
Lorenz
 
Yes I know the plugin and the conditional option.
In fact, I currently use the value of a checkbox as a condition, which I tick manually when loading the file.
I would like to set a condition on the presence or absence of the file. but I did not succeed
 
Well, what was your code in the condition?
In principle, it makes no difference if you check for a ticked checkbox or for a supplied filename.
 
Code:
$origData = $formModel->getOrigData();
$origData[0]->cedolinidipendenti___mailsend;
if ('{cedolinidipendenti___mailsend_raw}' == 1) {

  return true;

}

elseif ('{cedolinidipendenti___mailsend_raw}' == 0)

{

return false;

}

The code in question is this.
When the checkbox has a value of "1" send the email.

Since the filename always has different values, I don't know how to return the condition.
As it does not always have the same value.
 
Hi there!

Here's how I would do it:
First, I don't think you need the $origData part, the placeholders are available right away.
Then something like this:

Code:
if (isset('{cedolinidipendant___filetoupload}') {
  return true;   // send the mail
} elseif {
  return false; // don't send the mail
}

Replace filetoupload with the name of your fileupload element. This simply checks if the fileupload element has any value and the set the condition to true or false accordingly. I would suggest to also validate the element for notempty, to make sure that all users upload a file - if this is what you want.

Kindly,
Lorenz
 
Hi Thanks for your help.
I tested with your code, but it gives me the error:

0 syntax error, unexpected token "{"

Regarding element validation thanks for the advice but I don't need it,
as I only need to notify a user when there is a new document reserved for him in his reserved area.
Thanks again
 
Seems to be a missing bracket. Just addd a second ')' after ...filetoupload ->
if (isset('{cedolinidipendant___filetoupload}')) {
 
Seems to be a missing bracket. Just addd a second ')' after ...filetoupload ->
if (isset('{cedolinidipendant___filetoupload}')) {
HI,
Thank you for your help.
Yes there is a syntax error, I had already tried to add the second).
always returns error:

0 syntax error, unexpected token "{", expecting "("
Call stack


my php version is 8.3.3
 
Sorry, try this
Code:
$filetoupload = '{cedolinidipendant___filetoupload}';
if (isset($filetoupload)) {
 
Did you replace cedolinidipendant___filetoupload with your element name?
0 syntax error, unexpected token "{", expecting "("
Call stack
What is the Call stack?
What is your complete code?
expecting "("
sounds strange.

I can't see why else instead of elseif should return error 500.

Use debug tools like var_dump(...);exit; to see what you get.
 
Basically this should be sufficient as condition in the email plugin:
$filetoupload = '{cedolinidipendant___filetoupload}';
if (!empty($filetoupload)) {
return true;
}
 
Ups, just read the tipp-text of the condition field. So the code should be:
$filetoupload = '{cedolinidipendant___filetoupload}';
if (empty($filetoupload)) {
return false;
}
 
Did you replace cedolinidipendant___filetoupload with your element name?

What is the Call stack?
What is your complete code?

sounds strange.

I can't see why else instead of elseif should return error 500.

Use debug tools like var_dump(...);exit; to see what you get.
I had replaced it with my my element.

The complete code was this:
Code:
if (isset('{cedolinidipendenti___allegato}')) {
  return true;   // send the mail
} elseif {
  return false; // don't send the mail
}
 
Basically this should be sufficient as condition in the email plugin:
$filetoupload = '{cedolinidipendant___filetoupload}';
if (!empty($filetoupload)) {
return true;
}
With this code,
it works, if there is a file attached it sends me the email. otherwise no.
Thank you!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top