0

I'm using Freeform 4 and I have to create a Tell a friend page to send e-mails to multiple friends (maximum of 10). Each friend input will have the friends Name + their e-mail address.

The form is variable (1 friend name / friend email input is shown, with a button to add more)

I already found out that I can use brackets for multiple recipients, e.g. I know have:

<label>Name friend 1</label>
<input type="text" name="friend_name[]">
<label>Emailaddress friend 1</label>
<input type="text" name="recipient_email_user[]">

<label>Name friend 2</label>
<input type="text" name="friend_name[]">
<label>Emailaddress friend 2</label>
<input type="text" name="recipient_email_user[]">

<a href="#">+ Add another friend</a>

My first question

How can I set the friend_name[] and recipient_email_user[] as required? I'm trying to show inline errors at the corresponding fields. Is this doable with Freeform?

My second question

How can I retrieve the friend_name[] in the notification so I can begin every e-mail to friends with Hi {name}?

1 Answer 1

1

First question

I assume friend_name is a custom field, so you would use required="friend_name" as a parameter. If you have recipients="yes" and a recipient form field (i.e. recipient_email or recipient_email_user), Freeform should be able to detect if recipients have been filled out or not.

Second question

Since you have potentially multiple friend_names entered in the form, this data will be newline-delimited in Freeform's database table. You'll need PHP to break those apart (using PHP's explode() function for example), but this would be possible only in the email notification body. First, use an {embed} to a template that has PHP enabled, then break apart the friend_names. This is a very loose example of what I mean by "breaking up" the names.

<?php $names = explode("\n", '{embed:friend_names}');?>
<?php foreach($names as $name) {
    echo $name . ',';
}?>

Unfortunately, there is no way to pick only one name out of your friend_names. Freeform sends the same email notification to all recipients.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.