Buy Now
Sign in

How to set different actions based on dropdown choice

giulia72 , November 23 2016
g
giulia72

Hi
I have created a form that will send a file to the user who fills it.
I have received a request:
based on the country choice (dropdown field) , we want to set different action:

send a file who belongs to specific countries or send an email who belongs to other countries.
Is it possible?

GreyHead

Hi Giulia72,

Please see this FAQ. That shows you now to change the To Email address dynamically. You can use a similar method to change the email template contents if you need to.

If you need something more complicated then you can use an Event Switcher action with one event for each different email.

Or, you can do the whole thing with a Custom Code action if you need even more flexibility.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

g
giulia72

Hi Bob
thank you for your answer.
Indeed I need something more complicated:
Based on Select Box selection (Country) I would to send the email to different email address but I want also sent different kind of emails (different content and for one of them a file is sent to the user).
Actually theform is configured to send an email with a file to the user who fills the form.

Now I would to send different emails to different recipients based on country choice.

For ex :
if [Country]= France or USA --> send email with file to user + to [sales representative]
if [Country] = Dubai ot other send email to user +to [sales representative]

Is it possible ?
I'm not an expert if we need a customization we can pay for it

Let me know

Giulia

GreyHead

Hi Giulia,

Roughly how many different customisations do you think you need? If its say 5-10 I'd probably use an Event Switcher, if it's more that then I'd probably go for the Custom Code route.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

g
giulia72

ok let me gather more details. I will send you soon the details

Thanks again

Giulia

g
giulia72

Hi Bob
Let me explain better what we want to do, I hope you can help me as usual.

We have a module form to request a demo version of our sw.
Depending on the country (and in case of France on the district area too), the user will receive an email with download information (usually it is a pdf file with download link + password) or a simple email that explain he will be contacted from a sales representative.
In both cases the email will be also sent in copy to other two contacts (usually the sales manager and the secretary).

All the requests will be stored in the database to be exported in a csv file.


So far I have configured the form that send an unique email without considering the country and it is stored in a db table (also I can export data trhankk to your help).

I guess it is possible to create a form with these kinds of actions, but I don’t know how to configure it especially with several email addresses and countries selection.
I’m waiting for the list of countries + associated email addresses + action for download (yes or not)

In the meanwhile could you help me to configure this form?

Please note if it will take a deep customization we can evaluate to pay for it.
I can also provide you the access to our website.

Let me know if it is clear

Thank you in advance
Giulia

GreyHead

Hi Giulia,

If you need different emails and addresses for a hundred or more different combinations then I would probably create a database table to save that information. (You can create a new form to add this plus an admin-only CC listing to manage it.)

Let's assume that the table has some columns like this: cf_id, country, district, attachment, email_to, email_body, file_url, . . .

In your form you can get the country+district. Then, when the form submits use that information to look up the record from this table - let's say that you use a model id for that of send_info

Then you can use send_info.email_to in the Dynamic Email . . . and so on.

The email template is a little trickier. You can include input names in the saved templates as e.g. {name} - I don't think it will work though if you put {send_info.email_body} in the Email template. You will need a little custom code to set the template before the Email action runs. Similarly you will need to add any attachment file names to the $form->files array to have those attach (it might be a bit simpler just to add links to the email body though).

To make links accessible you could save a record in another table with a random key and the file name. In the email add a link with the random key to another form. This one checks if the key is valid and, if it is shows the download link.

That's probably enough to get you started.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

g
giulia72

Hi Bob
thank you for your answer but I'm still a little bit confused, sorry I'm not an expert of ChronoForm and custom code.

If I well understood, the first step is to create a db table with all necessary columns (I have to verify isf file url will be the same for each month).
What do you mean :(You can create a new form to add this plus an admin-only CC listing to manage it?

The second step is to create the form that takes the information from user and check them with the fields in the db table...but I don't know how to do it.


Also it is not clear for me :

To make links accessible you could save a record in another table with a random key and the file name. In the email add a link with the random key to another form. This one checks if the key is valid and, if it is shows the download link.


If I send you my table and form could you help me to check it ?

Thank you

GreyHead

Hi giulia72,

You are creating a mini-application here. The first thing that you need to do is sit down with a pencil and paper (old-fashioned but works OK) and think through the various bits of information you need and how they are stored and used.

You can create a new form to add this plus an admin-only CC listing to manage it?If you have a list of countries+states, emails, etc. then you need to be able to manage that list when it changes. One way to do that is to work directly by editing a table or an included array; another one is to create a ChronoForm to add/edit entries and a CC Listing to let you search sort and link to the edit form.

The second step is to create the form that takes the information from user and check them with the fields in the db tableIt depends on how you want the form to work. One way is to show a drop-down with a list of countries followed by a second dropdown that shows the departements if France is chosen.

To make links accessible you could save a record in another table with a random key and the file name. In the email add a link with the random key to another form. This one checks if the key is valid and, if it is shows the download link.This depends on how you want to make the files available, and how important it is that they are secure. One way to keep downloadable files secure is to save them in a folder above the site root and use a download form to make them accessible. So in your email to the user you would add a link like . . . &chronoform=download&file_id=AHGRT When the form is submitted your download form uses a DB Read to check the table and see if there is a saved file_id AHGRT, if there is is reads the file names and shows download links for them.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

g
giulia72

Hi Bob
ok I have the rules and table fields but how I can create the new form to add this plus an admin-only CC listing to manage it? I didn't find any sample or help

g
giulia72

BTW, does exist any documentation?

It could be useful as it seems to "walk in the darkness"

g
giulia72

I have created the tables with Country,departmen, email1, email2, download-allowed (Yes/No) fields and also the form to fill it.

I have the request download form, the user must fill to receive the dowload instructions.

Now, how can I set up the actions:
1- user allowed to download: an email with a pdf file will be sent to him (cc to 2 email address)
2-user not allowed to download: an email will be sent to him (cc to 2 email address)

the 2 actions are based on a country selection (only for France it will be a double check for department). The values must be compared in my action list table, I have created before.

How can I realize this actions?
I'm not good in php code.

Also I would appreciate to receive a manual as so far I make attempts to reach the goal

GreyHead

Hi giulia72,

There are a lot of FAQs here that cover most of the workings of ChronoForms. The problem that you have is that it is a very flexible framework for creating forms and there are many thousands of ways that you can set it up. No-one so far has offered to pay me for the year or so that it would take to write the manual :-(

To manage alternative actions you can either use an Event Switcher action. This is great for a shortish list of alternative actions - or you can use Custom Code actions and hand-code what you want to happen. Or you can combine both of these.

If you just have yes/no for Download allowed/Not allowed then an Event switcher will do the job. You would set it up with two Events and add Email actions to each of them.

To trigger the Event Switcher you will need to check the selected Country/Country+Department against your action list table. I would use a hand-coded MySQL query to do that. Then you can select the appropriate event. For example

				<?php
$db =& JFactory::getDBO();
$query = "
SELECT `allowed`
FROM `#__some_table`
WHERE `country` = '{$form->data['country']}' ;
";
$db->setQuery($query);
$allowed = $db->loadResult();
if ( $allowed == 'yes' ) {
return 'allowed';
} else {
return 'not_allowed';
}
?>
Here the Event Switcher events are named 'allowed' and 'not_allowed'.

				ok I have the rules and table fields but how I can create the new form to add this plus an admin-only CC listing to manage it?
				

Please see this FAQ and this FAQ
Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

g
giulia72

Hi Bob
Thank you for you reply I will give a look after my vacation in January.
I would to find the simplest way to manage it as I'm not a code expert

Happy New Year!



p.s. I'm sorry there isn't any manual as I see the component is very flexible and powerful

g
giulia72

Hi Bob
After Christmas holiday I 'm returning to my form
I have seen your suggestion but for me is too generic to understand how to apply it to my form:
1.where do I have to insert the code you suggested?
2. In which position of Setup Form do I have to insert Event Switcher action? and How I have to configure it?

If I provide you the name of my db table and fields, could you indicate me how I have to use them in the code?

db_table name (it contains the list of countries/email address/ download y/n)= jrbeg_cf_download_request_actions
list of fields of jrbeg_cf_download_request_actions = country,department, download, email1, email2


The actions shold be:

1- download = 1: an email with a pdf file will be sent to user and email1 + email2

2- download = 0: an email (without any file) will be sent to user and email1 + email2

the 2 actions are based on a country selection (only for France it will be a double check for department).

Is it enough for you to adapt your code to my fields?

g
giulia72

Hi Bob
I can also give you access to my admin panel and I let you set up it
I can also evaluate to pay for this service if it is not so expensive
Let me know

For me it is very urgent to setup this action ASAP as without them we cannot pubblish the website

Please help

Thank you