Forums

Using a form variable as the SendTo email addess

danieli 15 Apr, 2008
Hello, let me start our by saying that I am new to Joomla (1.5.2), Chronoforms (V2.5 J1.5 RC2.1), and PHP... the triple threat!

We are planning to use Joomla internally as our intranet, and the form I have created is a vacation request form.

Basically I am trying to use the Chronoform feature to send an e-mail to a manager's email address collected on the form as variable ManagerEmail... but the General tab insists on "something" being in the Email Address(es): field on the General tab... and is concatenated with (expected overwritten by) the Email field: on the Special tab... so my e-mail goes to 2 addresses instead of one.

The closest thread I could find to my issue is here, but this was about overriding the ReplyTo.

What do I need to add to my OnSubmit() to override the "SendTo" address? or how to I make the Special Tab field override the General Tab?

My current OnSubmit is:
<?php $_POST['subject'] = "Leave Request Form - ".$_POST['EmployeeName']?>


Thanks in advance!
Daniel
GreyHead 15 Apr, 2008
Hi Daniel,

ChronoForms does some overzealous validation on the General Tab :-(

It's possible to hack the code to fix this but a simpler workaround is probably to put a dummy email address (like [email]user@example.com[/email]) in the General Tab and then put this in the 'OnSubmit before email' box;
<?php
$rows[0]->extraemail = $_POST[$paramsvalues->emailfield];
// $_POST[$paramsvalues->emailfield] = "";
unset($paramsvalues->emailfield);
?>
Basically this overwrites the dummy entry with the one from the form. Note: there's no error checking in this so the email will probably crash with an error message if the form doesn't return a valid email.

Bob

NOTE: This post originally had incorrect code in it (see later in this thread). It has now been updated, the original incorrect code is the commented out line.

PS Not tested so may be buggy!<br><br>Post edited by: GreyHead, at: 2008/04/16 12:40
danieli 15 Apr, 2008
Thank you very much for the reply Bob.

I created a drop-down of valid e-mail addresses for the user to choose from, so if there is an invalid address... it's my fault :whistle:

As long as I did everything right... I updated my On Submit - before email code to...
<?php 
$rows[0]->extraemail = $_POST[$paramsvalues->emailfield];
$_POST[$paramsvalues->emailfield] = "";
$_POST['subject'] = "Leave Request Form - ".$_POST['EmployeeName'];
?>

And when I tried submitting the form, I got an error:
SMTP Error! The following recipients failed:


Did I apply it correctly?<br><br>Post edited by: danieli, at: 2008/04/14 21:08
danieli 15 Apr, 2008
I tried some tests with the code and the issue seems to be the line
$_POST[$paramsvalues->emailfield] = '';

if i remove it, I can submit the form successfully, but the dummy address is used (as expected with 1/2 the fix missing).
GreyHead 15 Apr, 2008
Hi Danieli,

Looks like a problem my end. Please will you take a Form Backup from the Forms Manager and email it to me at the address in my sig below. I'll take look and get the code correct.

Bob
danieli 15 Apr, 2008
I have sent the e-mail with the same subject as this thread.

Many thanks is advance. Incredible support!
GreyHead 15 Apr, 2008
Hi danilei,

You're right about the line. Please replace it with this:
unset($paramsvalues->emailfield);
As long as that remains there even though it is empty, ChronoForms adds an empty email address to the list and that gives you the error message. (The clue is the comma after the address.)

Bob
danieli 15 Apr, 2008
Success! :woohoo:

Fantastic Bob, your help and support is incredible!
nosins 05 May, 2008
Hey there,

I'm trying to use this example as a way by which to set the user_email field in my form (the one into which a user types their email address) as the replyto email address so that when I reply to the email from the website, I can reply to the user who submitted the form. However, after replacing 'emailfield' with the name of my form field, 'user_email', and inserting the above code in the OnSubmit before code box, I get the following error upon submitting the form:

Could not instantiate mail function.

Any ideas?

Thanks for a great component!
This topic is locked and no more replies can be posted.