• 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: How to hide unpopulated fields in emails

How to hide unpopulated fields in emails 12 years 2 months ago #21464

  • danpoole
  • danpoole's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 4
  • Thank you received: 1
This solution was supplied by the great support team @ RSJoomla

The Problem
In dropdown select fields I use '== select ==' as the first item then other choices below it, the problem with this is that it is treated as input data when form data is sent via user and admin emails. If this field is not selected by the user that field caption & value are still included in the email. in the form I created there were a lot of these making the email being sent displaying a lot of useless data and the client would have to sift through all of it to find the actual relevant information.

I found the following solution here http://www.rsjoomla.com/forum/37-rsform-pro/18246-hide-unpopulated-fields-in-admin-email.html#20422

This worked for me...
$modUserEmailText = $form->UserEmailText;
if($_POST['form']['my_field_name01'] == '== select ==')
$modUserEmailText = str_replace('{my_field_name01:caption}: {my_field_name01:value}','',$modUserEmailText);
else
$modUserEmailText = str_replace('{my_field_name01:caption}: {my_field_name01:value}','',$modUserEmailText);
$userEmail['text'] = $modUserEmailText;
$userEmail['text'] = str_replace($placeholders, $values, $userEmail['text']);

I don't know why the 'else' is there but without it it didn't work.

This presented a 'I'm too lazy' problem because I didn't want to do the above code another 40 time for e.g.'my_field_name01, my_field_name02' etc.

After contacting RSJoomla Support they supplied me with the following...
$modUserEmailText = $form->UserEmailText;
$fieldNames = array ('my_field_name01','my_field_name02','my_field_name03','my_field_name04');
 
foreach ($fieldNames as $field)
{
if ($_POST['form'][$field][0] == '== select ==')
$modUserEmailText = str_replace('{'.$field.':caption}:{'.$field.':value}','',$modUserEmailText);
}
 
$userEmail['text'] = $modUserEmailText;
$userEmail['text'] = str_replace($placeholders, $values, $userEmail['text']);

This worked perfectly, I also had a lot of text fields displaying the number value '00' so the below code was suggested
$modUserEmailText = $form->UserEmailText;
$fieldNames = array ('my_field_name01','my_field_name02','my_field_name03','my_field_name04');
 
foreach ($fieldNames as $field)
{
if (($_POST['form'][$field][0] == '== select ==') || ($_POST['form'][$field][0] == '00'))
$modUserEmailText = str_replace('{'.$field.':caption}:{'.$field.':value}','',$modUserEmailText);
}
 
$userEmail['text'] = $modUserEmailText;
$userEmail['text'] = str_replace($placeholders, $values, $userEmail['text']);

I hope this helps others, and thank you again RSJoomla Support.
The administrator has disabled public write access.
The following user(s) said Thank You: djaber2000

How to hide unpopulated fields in emails 12 years 2 months ago #21566

  • arpagaus
  • arpagaus's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hello
I have the same problem
I tried this
My form :
https://docs.google.com/file/d/0B636nVAakXU1bENUYnR2NnRjTjA/edit?usp=sharing

the code :

$modUserEmailText = $form->UserEmailText;
$fieldNames = array ('formationmodule1','formationmodule2','formationmodule3','formationmodule4','formationmodule5','formationmodule6','formationmodule7');

foreach ($fieldNames as $field)
{
if ($_POST[$field] == '')
$modUserEmailText = str_replace('{'.$field.':caption}:{'.$field.':value}','',$modUserEmailText);
}

$userEmail = $modUserEmailText;
$userEmail = str_replace($placeholders, $values, $userEmail);

In the email the unpopulated fields appear, in my choise I choose 'formationmodule4':

formationmodule1

formationmodule2

formationmodule3

formationmodule4 Lundi 11 et Mardi 12 Mars 2013

formationmodule5

formationmodule6

formationmodule7

As you can see that don't work. Unpopulated fileds are in the email.
A begining of solution

THIS WORKS FOR ME

$modUserEmailText = $form->UserEmailText;
$fieldNames = array ('formationmodule1','formationmodule2','formationmodule3','formationmodule4','formationmodule5','formationmodule6','formationmodule7');
foreach ($fieldNames as $field)
{
if ($_POST[$field]== '')
$modUserEmailText = str_replace($field,'',$modUserEmailText);
$modUserEmailText = str_replace("{:caption}",'',$modUserEmailText);
$modUserEmailText = str_replace("{:value}",'',$modUserEmailText);
}
$userEmail = $modUserEmailText;
$userEmail = str_replace($placeholders, $values, $userEmail);
The only probleme is
In the email each unpopulated field = one line
to be continued ......
Last Edit: 12 years 2 months ago by arpagaus.
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!