Forum

Thread tagged as: Question

Using Perch within a php form to email

I'm trying to allow editors to customise a php form to email within a page (I know very little php). The email address part works OK. The html page starts like this:

<?php include('perch/runtime.php'); ?>
<?php
$yourEmail = perch_content('destination-email-address', true); 

(in the unmodified form the line reads like this $yourEmail = "your-email@address.com" )

From this Perch picks up the region OK when a new page is created and allows an editor to enter an email address. The address is output to the form, not to the html page, and an email is sent correctly to that address on clicking 'Submit'. Works good. But I have no success for the subject header of the mail. The line in question is like this:

$subject = perch_content('email-subject, true');

and I've also tried

$subject = "perch_content('email-subject, true')";   (in the standard form the subject line is in double quotes)

To begin with I did get a Perch region in the admin but the resulting email had either a blank subject or output the text to the html or output it into the email subject line exactly the same as the perch php code. But I could not achieve that the text entered in admin was output as the email subject line. After deleting regions and/or deleting the page so as to begin afresh, I can't now even get Perch to pick up the region in the admin.

Any suggestions much appreciated.

Peter Hammarling

Peter Hammarling 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

This:

$subject = perch_content('email-subject, true');

should be this:

$subject = perch_content('email-subject', true);

Thanks Drew, and sorry to waste your time - the error was introduced here by me, but not in the page code, it is correct in my page, I've triple checked. But Perch won't pick up the region. If I insert the region outside the php form, it is seen in the usual way by Perch and is editable in Admin. I guess it must be something else in the php of the form that's causing the problem. It's Jem's mail form ( https://jemsmailform.com/ ) but I'm reluctant to post all the form code here as it's a commercial product.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is there a reason not to use the Forms app?

The only reason for trying to retrofit Perch into the existing php form is that the pages and the form existed previously before the Perch installation and I was hoping to save on having to redesign and recode the form.

I've never used the perch forms app. The form I need will have 3 or 4 required fields (name, contact details), and possibly a required drop-down list of choices. It will be on a master page so that editors can create new pages and configure themselves the destination address, the subject line, and the first line of body content.

The existing form offers some basic spam protection, some mis-typing protection, and a 'thank you' message (or redirect to thank you' page) after submit.

Would the forms app do a similar job?

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's what it does. One to remember for future builds.