Creating a Send me a copy scenario

RSForm!Pro offers tremendous flexibility through its PHP scripting areas, allowing you to perform, virtually, any kind of operations with the submitted and form-related information.


A commonly requested scenario is to only send the User Email if the submitter selects an option in a checkbox group. We'll explain the implementation in detail below.



Adding the checkbox


To keep things short, we will be working directly on the default RSForm!Pro example form that gets installed along with the component. Head to Components >> RSForm!Pro >> Manage Forms >> edit the RSForm! Pro example form >> Components tab.


To the left, you will see a listing of all available field types that can be added to the form's layout. Click on Checkbox Group. A tab will be opened, containing the field's configuration options. We've called the field sendmail, but you can name it in any way you see fit, as long as you replace the name in the code (provided below) as well. Add Yes|Send me a copy in the Items area. This will be the only selectable item in the checkbox group.


The code


There's no default feature that would allow you to implement the scenario that got you into reading this article. However, as we have said earlier, RSForm!Pro is extremely flexible due to its PHP scripting areas. In our case, we will make use of the PHP Email Scripts tab's Script called before the User email is sent area. To access it, follow this path:


Components >> RSForm!Pro >> Manage Forms >> edit the RSForm!Pro example form >> Properties >> PHP Email Scripts >> Script called before the User Email is sent.


Copy and paste the following code in Script called before the User email is sent:

if ($_POST['form']['sendmail'][0]=='Yes')
{
  $userEmail['to']=$_POST['form']['Email'];
}

Setting up the User Email


This is the final step of our custom set-up. RSForm!Pro emails will only get sent if their From, From Name, Subject and Message fields are correctly filled. This is perfect for our scenario, as we need to, by default, not have the User Email sent.


To do so, head to Components >> RSForm!Pro >> Manage Forms >> edit the RSForm!Pro example form >> Properties >> User Email and make sure to clear the To: field. The code provided above will add, in the User Email's To: field, the submitter's email address (collected by the Email field) if the box is checked, otherwise leaving it blank.


15 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

How to create a multi-page form HOT

Dynamic Drop-down change form example HOT

Create Tabbed Forms HOT

How to override front.css file in RSForm!Pro HOT