• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Using AND within an if statement for custom email

Using AND within an if statement for custom email 2 years 4 months ago #42415

I have a form with 4 Yes/No questions.

If all 4 questions are answered "Yes", I want to display a specific page, and if any of the 4 questions are "No", then I want to display different message.

My field names are Q1, Q2, Q3, Q4.

I figure there should be a way to do:
If Q1 = Yes AND Q2 = Yes AND Q3 = Yes AND Q4 = Yes ...
then display Message A
else display Message B

But I need some guidance on how actually code that in my thank email template? I'd also like to display the conditional text on the thank you page after form submission.

Can anyone provide a working example?
The administrator has disabled public write access.

Using AND within an if statement for custom email 2 years 4 months ago #42424

  • dragos
  • dragos's Avatar
  • OFFLINE
  • Administrator
  • Posts: 634
  • Thank you received: 117
Hello,

You'll need a custom scripting approach on this scenario. For example:

1. create a hidden field

2. add the following code in the PHP 'Script called on form process' area:
$fields = array(
	'q1',
	'q2',
	'q3',
	'q4'
);
 
$hiddenResult = 'hidden-field-name-here';
 
$answers = array();
foreach ($fields as $fieldName)
{
	if (isset($_POST['form'][$fieldName]))
	{
		$answers[] = $_POST['form'][$fieldName];
	}
}
 
if (in_array('No', $answers))
{
	$_POST['form'][$hiddenResult] = 'No';
}
else
{
	$_POST['form'][$hiddenResult] = 'Yes';
}

3. replace q1, q2, q3, q4 with the actual names of your question fields.

4. In your Thank You Message add the following syntax:
{if {hidden-field-name-here:value} == 'Yes'} display Message A {/if}
{if {hidden-field-name-here:value} == 'No'} display Message B {/if}

5. replace 'hidden-field-name-here' with the name of your Hidden field, in both PHP script and Thank You Message syntax
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!