Forums

Sending a form via email after user clicks confirmation link

Robster79 06 Mar, 2010
Hi folks,

I have to build an order form that submits the placed order via email. A registration of the user should be avoided to keep things simple for the user (no forgotten passwords, no problem with people who don't want to register, etc.). As the orders are paid on delivery and shipping is free, there is no need for any payment system. The only thing that has to be done is the verification of the users email via a confirmation mail. Until here, everything is quite clear for me, but this one leaves me with a question: The email with the order should only be sent to the shopowner if the user clicks the link in the double-opt-in confirmation mail.

In another post I read the following:
"The plugin allows you to send an email to the user containing a verification link. When they click the link a database table is checked and updated to confirm their e-mail address is valid."
and
"* On the Extra Code tab you can enter code to be run before the email is sent, or after the verification link is clicked. The code can include HTML which will be displayed and PHP inside tags."

What does that mean? Will the email with the order be sent to the shopowner only after the user clicked the confirmed link or is just the database table updated?
Is the code that is run after the verification link is clicked just for something like a "thanks for your confirmation" page or do I have to use this to trigger the sending of the form to the shopowner? Is it even possible, to achive what I want with ChronoForms and the Email Verification plugin "out of the box"?

Greetings from Germany,
Robin
gemlog 11 Mar, 2010
No sense making a new thread when this one is nearly exactly what I need to do :-)

I've duplicated some functionality already present in chronoengine before out of ignorance, so I want to ask before I do it again...

I see the after/before confirmation tabs. I don't have any product or money involved, but I need to send email(s) after confirmation. The info comes from the same record they confirm. Storage and confirmation are already working fine.

Is there a way to tie into the regular email tabs of chrono (this is where I'd be wasting existing functionality) or do I need to write that in the after confirmation code along with the thank you page? If the latter how do I reference the current record to get the data or is it already in an array in the after code environment? Then, is there a func() I can call in chrono with receiver, subject, mailbody or do I use the php one or sendmail?

Whoa. Too many questions. I'll stop now!
GreyHead 11 Mar, 2010
Hi gemlog,

I've been trying to get my head around this. I'm not certain but I think that what I'd probably do is to build a custom verification link that comes back to the submit part of a different ChronoForm (i.e. it has task=send in the URL). You'd need to add the code to handle the confirmation - presumably to update the database record - but then you can use all the ChronoForms functionality to send emails, etc.

Bob
gemlog 11 Mar, 2010
Thanks Bob. Sounds like it may be simpler to just assemble the mail from the db record myself then. Thanks for your quick reply! (as always)
gemlog 13 Mar, 2010
I opted to just use Jfactor::getMailer() This works fine and it sends out the mail after verification. Now I just need to discover what vars I have available to fill in the email properly and I'm pretty much done this little project, except for some odds and ends

All I got it to email me using get_defined_vars() etc. was 'Array1', so far. Somehow, I need at least the uid for the record. Any ideas?
GreyHead 13 Mar, 2010
Hi gemlog,

The code that Max used in the ChronoForms mailer is
$email_sent = JUtility::sendMail($from, $fromname, $recipients, $subject, $email_body, $mode, $ccemails, $bccemails, $this_attachments, $replyto_email, $replyto_name );

Bob
gemlog 13 Mar, 2010
Thanks Bob, I'll try that. Tomorrow zzzz...
gemlog 13 Mar, 2010
Daytime now, actually read your post.

No, no. My code is triggered and does send an email. No problem there. I need to access the data in the record that just got verified, so I can place it into the email. That's the bit I don't know how to access. I don't know what var is holding the uid for example, so that I could read it. I thought there would be an array holding the whole record, but I don't know what it is.
GreyHead 13 Mar, 2010
Hi gemlog,

This is after the verification link has been clicked? I don't think that there are any results saved in an array. That happens after a normal DB Connection save.

Bob
gemlog 14 Mar, 2010
Yes, it's after they click the verification in the email which hits this link (e.g.)
...chronoformname=pcode_32&task=beforeshow...
And the database gets updated to a 1 (verified). At this point I need to read the record the record that just got verified and updated and create a mail to go out. I have the mail I made going out ok after verify, but not the real data in it, because I don't know what to put in my code to grab the right vars.

I have this in "OnSubmit After Verification - Success:" in the plugin:
$mailer =& JFactory::getMailer();
$config =& JFactory::getConfig();
$sender = array( 
    $config->getValue( 'config.mailfrom' ),
    $config->getValue( 'config.fromname' ) );
$mailer->setSender($sender);
etc. etc.


I need to read from the current record, so I can set these properly
$mailer->addRecipient($[read from current record]);
$mailer->setSubject($[read from current record]);
$mailer->setBody($[read from current record]);


That all works fine and sends a mail, just not the one I want it to send :-)
Sorry I was unclear before.
GreyHead 14 Mar, 2010
Hi gemlog,

Then I think you have to get the 'unique code' from the verification link and use that to look up the corresponding user id/ record id in the table. Once you've got that you can get access to all the data with a second DB query.

Bob
gemlog 14 Mar, 2010
An idea I had when I was out to supper was to mess with the regular mail. It does send one out on verification and prolly has the current record in its env. I will try that out on Monday. Plus I can use the On Submit code - after sending email and before to tidy up and nuke part of the record and subscribe them to acajoom (if they opted in). I'd just have to add some more extra code to the original form to assemble the mail in advance of the verification and store it in the record. Dunno why I was thinking of doing it post verify at all.

Thanks Bob, that sounds like it will work no? Sometimes it's just good to be able to talk to someone to sort out how to do something.

I know you are 8-9 hours ahead of me, but don't you sleep?? :-)
Thanks again. You guys are awesome. Best. Joomla. Component. Support. Ever!
gemlog 21 Mar, 2010
Yep. That works. Bah, my upside-down thinking sometimes. Sorry to cause you the bother bob.

Was going to start a new post, but I should prolly extend this one.

So, the user clicks on the confirmation url, good db stuff happens (it gets updated to 1), then the normal email stuff execs, AND the vars in it work, BUT the redirect URl doesn't. Have I messed something up? The redirect URL is ignored and they get taken to a blank form. N.B. this is the normal Redirect NOT the plugin Redirect.
GreyHead 21 Mar, 2010
Hi gemlog,

Looking at the plugin code it *ought* to redirect if the verification succeeds . . . so not sure what is happening. I'll dig a bit deeper later.

Bob
This topic is locked and no more replies can be posted.