Forums

Dynamic To & Email fields

ljk 04 Apr, 2011
Hello,

I have a Contact Form in V3 that will change the Dynamic Subject and the Dynamic To fields depending on what the user enters. I am trying to get the same functionality in V4.

Here is what I have done. In the email under On Submit I have set the following:
Under Static tab:
bcc: [email]test@domain.com[/email]
Under the Dynamic tab:
Dynamic To: toemail
Dynamic Subject: subject2
Dynamic From name: first_name
Dynamic From email: email

first_name and email are fields in the contact form. toemail and subject2 are just placeholders for replacing the field info.

I have added a Custom Code block which comes after the Captcha Check and before the Email block (described above). The mode is set to Controller. In the Custom Code block I have the following code:

<?php
// Change the Subjects to have the site name in them
  $name = JRequest::getString('first_name', '', 'post') . ' ' . JRequest::getString('last_name', '', 'post');
  $subject = "Inquiry on UBC Department of Radiology from $name";
  JRequest::setVar('subject2', $subject);

// Check for an doamin2 email address
  $email = JRequest::getString('email', '', 'post');
  if (strpos($email, '@domain2.com') === false) {
    /**************************************************************************/
    // This uses the Global Configuration EMAIL ADDRESS
    /**************************************************************************/
    $app = JFactory::getApplication();   
    JRequest::setVar('toemail', $app->getCfg( 'mailfrom' ));
    JRequest::setVar('bccemail', 'bcc@domain.com');
  } else {
    // Found a domain2 email address, so change the To email address
    JRequest::setVar('toemail', $email);
    JRequest::setVar('bccemail', '');
  }
?>

Note in the above code I have changed to using domain.com and domain2.com from the real domains.
In the original V3 version bccemail was in the Dynamic bcc field, but V4 doesn't seem to have this.

The errors I get when I try to submit the form are:
Notice: Undefined index: subject2 in /home/xxx/public_html/administrator/components/com_chronoforms/form_actions/email/email.php on line 68

Notice: Undefined index: toemail in /home/xxx/public_html/administrator/components/com_chronoforms/form_actions/email/email.php on line 77

It looks like you can't access the dynamic email fields the same way in V4 as you could in V3. So, how do you change these fields now?

How do you redirect to a speific URL in V4 right now I can only see where you can put in a message on success in the "Show Thanks Message" block. I don't see a Redirect Block.

If it would help to have login access, please let me know and I can give that to you.

Thank you for your help on this.
GreyHead 04 Apr, 2011
Hi ljk,

The PHP notices are just notices - they are inconvenient but shouldn't stop the execution.

I don't know why Max has left out the Dynamic CC & BCC addresses, I'm sure that they could be added.

From a quick scan the code you have posted looks OK to me; if you add a Debugger action what results are shown there.

Later: Take that back. I think the values need to be added to $form->data now like this
$form->data['toemail']  = $app->getCfg( 'mailfrom' ));
$form->data['bccemail'] = 'bcc@domain.com');


There are no ReDirect actions in the current release. I wrote a couple (one simple and one more complex) that Max is debugging for the next release.

Bob

PS I strongly recommend that you do *not* use the Dynamic From Email element in your Email Setups. Using this often results in your emails being marked as spam and dropped into a spam filter. Instead use the static From Email with an address that matches the site domain name and use Dynamic ReplyTo Email for the user email. The result is the same but with a much better chance of good delivery.
ljk 04 Apr, 2011
Hello,

Thank you very much for that quick response and help.

Yes, changing to $form->data['toemail'] from JRequest::setVar('toemail' worked. It also got rid of the php Notices.

The Static bcc doesn't seem to be working.

I added a debugger block to the start of the On Submit, but it only showed what it did up to sending the first autoreply email, it didn't show anything after that. I have the autoreply email block after the email that goes to the site owner, but it didn't show in the debug information.

It would be great if the dynamic cc and bcc fields could be added.

Thank you for your help.
GreyHead 04 Apr, 2011
Hi ljk,

Add the debugger as the last entry in the OnSubmit Event (or add more than one and set the earlier ones to clear the debug records shown so far).

If the static CC & BCC aren't working are you using the PHP Mail function as your site mailer? I don't think that supports CC or BCC?

Bob
ljk 05 Apr, 2011
Hi,

Thank you for the debugger tip.

Yes, using PHP Mail Function. Funny, it works with V3 when using PHP Mail Function, so I expected that it would work in V4 too.

Thanks for the help.
GreyHead 05 Apr, 2011
Hi ljk,

Here's an updated email action that includes the dynamic cc & bcc inputs. I've also cleaned up the debugger code a bit so that these addresses are now included if they are set.

Unzip the file and upload the encloses email folder to the administrator/components/com_chronoforms/form_actions folder. I suggest that you save a copy of the current folder first in case you need to go back.

Bob
ljk 05 Apr, 2011
Hello,

Thank you very much. The email fix worked great. I am now getting my bcc emails. But there is a bunch of debug statements that show up even when you don't have the debugger block installed. I had to comment out the lines that start with $mainframe->enqueuemessage to get rid of the debug messages.

On the site I am trying to use V4 on, there are a lot of other modules & the template that are using JQuery. When I install the form which is working on another site without errors, I get the following error:
this.form.getProperty is not a function
Firebug shows: formcheck-yui.js (line 1) as the source, which is the form validation script.

In the source code there is a jQuery.noConflict(); but it isn't helping the issue above.

Any idea how to fix this problem or is there another validation script that could be used that won't conflict with the JQuery scripts?

Thanks again for the quick fix.
GreyHead 05 Apr, 2011
Hi ljk,

Apologies for the extra debug code - my fault for not having removed them. I'll do that now in my copy.

From your post on the JQuery question is sounds as though the MooTools library may not be being loaded.

Please post a link to the form so we can take a quick look.

Bob
GreyHead 06 Apr, 2011
Hi ljk,

Hmmm . . . the validation error has me beat for the moment. I can see the error but the compressed js files make it next to impossible to track it down in detail. I suspect that the NoConflict needs somehow to load before the formcheck-ui.js file :-(

Bob
Max_admin 07 Apr, 2011
Hi,

the validation scripts are loaded through the "Load HTML" action, if you want to load some script before it then please place "Load JS" action before the "show HTML" action, and vice versa.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
ljk 07 Apr, 2011
Hi,

All of the JQuery is being added by other modules and many don't have the option of them not loading JQuery and the JS they need.

But I added a JS Load block before the Show HTML block and put the:
jQuery.noConflict();
in the JS Load block.
When I look at the source code now the there is:

		//<![CDATA[
			jQuery.noConflict();		//]]>

but it is still positioned after the formcheck JS scripts. It didn't actually load the noConflict code before the formcheck code.

In the Auto Server Side Validation block do I need to add the Required fields to the Required field input? I have already marked the fields as required in the html code class.

If I want to change from using the popup black box error messages to just having the errors display below the field in the div, normally I would add:

	showErrors : 1,
	indicateErrors : 2

to the display event when initializing formcheck in the domready event. How do I do this in ChronoForms? What do I need to add in what block?

Thank you for you help on this again.
GreyHead 07 Apr, 2011
Hi ljk,

It's a bit of an awkward one; Joomla! correctly loads the included files before the script snippets. Off the top of my head there are two answers, create a javascript file with the no-conflict line in it and include that in the file loads; or edit the main JQuery file to put noConflict at the beginning.

Bob
ljk 08 Apr, 2011
Hi,

Thank you for the suggestion. After much experimenting I finally was able to get rid of the JS error. Unfortunately, I had to had the JQuery file and add the jQuery.noConflict(); at the end of the file. JQuery needs to be loaded before you can have the jQuery.noConflict(); line and that needs to execute before the formcheck javascript files are loaded.

Now, I need the answer to the question I posted above:
If I want to change from using the popup black box error messages to just having the errors display below the field in the div, normally I would add:


       showErrors : 1,
       indicateErrors : 2


to the display event when initializing formcheck in the domready event. How do I do this in ChronoForms? What do I need to add in what block?

Thank you for you help on this again.
GreyHead 08 Apr, 2011
Hi ljk,

I have a modified Show HTML action that includes an input box for the FormCheck parameters. Otherwise it's mostly a copy of the standard action. Please treat as beta code and let me know about any problems you find.

Download the file from here and upload the show_html_gh folder to the administrator/componenents/com_chronoforms/form_actions folder. This will add a new Show HTML [GH] action that you can use.

Bob
ljk 08 Apr, 2011
Hi,

Thank you for the new files, they allow me to specify where the errors should be displayed, which works great.

But I have found a bug. This doesn't happen with the Show HTML block only the new Show HTML [GH] block. If I enter all of the field but enter an incorrect captcha and click send. When the form reloads, it isn't showing that the captcha field was incorrect, the message at the top of the form saying that an incorrect captcha was entered is not being displayed. You just get a form with the fields filled in except for the captcha field. No indication of what was wrong.

This is how I have the parameters set:
display : {
errorsLocation : 3,
showErrors : 1,
indicateErrors : 2
}

Thanks again.
GreyHead 09 Apr, 2011
Hi ljk,

I found the bug, one update in Max's code that I hadn't spotted :-(

In administrator/components/com_chronoforms/form_actions/cfaction_show_html_gh.php around line 67 replace 'task' with 'event'
 if ( $form->form_params->get('submit_action', 'submit') != 'self' ) {
  $action_url .= '&event='.$form->form_params->get('submit_action', 'submit'); // <-- edit this line
}

That fixes the missing error messages.

Bob

PS I've updated the zip file in my earlier post to include this fix.
ljk 11 Apr, 2011
Hello,

I made the edit to the file as suggested below. Now when you enter an incorrect security image code and click Send you get the following error message:

Fatal error: Call to undefined method CfactionShowHtmlGHHelper::_normalize() in /home/ubcradio/public_html/administrator/components/com_chronoforms/form_actions/show_html_gh/cfaction_show_html_gh.php on line 151

Thank you for your help.
ljk 11 Apr, 2011
Hello,

Update, another problem is that the emails are being sent even if the security code is bad. When I am testing the changed code, I am receiving both the autoreply email and site owner email when I enter a bade security code.
GreyHead 11 Apr, 2011
Hi ljk,

I'm not getting the _normalize error and the function is in my copy of the file. Please will you download the zip from my earlier post and re-upload that file, hopefully that will fix it.

The email error sounds like a sequence problem in the OnSubmit Event. The Check Captcha Event needs to come before the Emails and to have an Event Loop action in the OnFail Event box.

Bob
ljk 11 Apr, 2011
Hi,

I uploaded the new zip contents and now I get the following error:
Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 40961 bytes) in /home/ubcradio/public_html/components/com_chronoforms/libraries/chronoform.php on line 159
The PHP memory_limit for the server is set to 40MB. Shouldn't that be enough memory?

In the On Submit event I have the following:
Auto Server Side Validation
  On Success
  On Fail
Check Captcha
  On Success
  On Fail 
    Event Loop - this had On Load for Target Event have tried On Submit. What should this be set to the Auto Validation > On Fail > Check captcha > On Success or On Fail? Don't understand what these all mean/do.
Custom Code
Show Thanks Message
DB Save
Email Site Owner
Email Autoreply


Thank you.
GreyHead 12 Apr, 2011
Hi ljk,

Sounds as though you have an infinite loop :-(

The OnFail | Event Loop actions should recall the OnLoad event i.e. re-display the form.

Bob
ljk 12 Apr, 2011
Hi,

Not sure why I was getting the memory error yesterday. But today with the On Fail > Event Loop set back to On Load, it has gone away.

One more problem with the new code. I am now getting the message that I entered an incorrect secuirty code and the security code box is highlighted, which is all great. But at the bottom of the form after the submit button the thank you message is showing up. The thank you message that you get on successful completion. I am still also getting the emails being sent on error.

Do I have the thank you block in the wrong place or is this a code error? I didn't get the thank you message on the Show HTML block when I was using it.

Thank you.
GreyHead 13 Apr, 2011
Hi ljk,

The memory error was because when you hit an error you reloaded the OnSubmit event, checked again, failed again, reloaded the OnSubmit event, checked again, . . . until the memory was used up.

Please check that the Event Loop configuration has 'Quit next actions' set to 'Yes'. That is the default setting and should block the later actions.

Bob
ljk 13 Apr, 2011
Hello,

Thank you so much for all your help on this. Finally I have a working contact form just about equivalent to the one I use in V3. The only idfference is that I can't redirect to a thank you page now, but I can live with that for now.

Thanks again.
ljk 13 Apr, 2011
Hi again,

Unfortunately, there is still a problem. When I try to fill the form and don't have a bad security code I am getting a message that the security code is bad. I can't submit the form at all now.

Would it help to get a copy of the form I am using?

Thanks.
GreyHead 13 Apr, 2011
hi ljk,

Sure, please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
Max_admin 15 Apr, 2011
hi ljk,

Did you get this issue solved ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
ljk 15 Apr, 2011
Hi,

No, I PMed the form backup to greyhead but haven't gotten anything back from him on it yet.

Thanks.
Max_admin 17 Apr, 2011
Hi ljk,

Yes, Bob is out of town, could you please show me a screenshot for the "Events" tab in your form wizard ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
GreyHead 18 Apr, 2011
Hi ljk,

I did get your PM just before I went away but there was no attachment.

Bob
ljk 18 Apr, 2011
Hi,

Form events screenshot attached. I have also PMed the form to Greyhead again.

Thank you.
GreyHead 19 Apr, 2011
Hi ljk,

I restored the form into Joomla! 1.5.23 and it appears to behave correctly. I've tested correct, blank and 'wrong' Captcha codes.

There are a couple of minor things I would change in the setup:[list=a]
  • Put the Check Captcha before the Auto Server Side validation so that you kick out the bad captchas without bothering with the validation.

  • Add an Event Loop action into the Auto Server Side Validation OnFail box.
  • [/list:o]
    Bob
    ljk 19 Apr, 2011
    Hi,

    Thank you for your help. Everything seems to be working today with moving the Captcha above the Server validation and adding the Event loop as you suggested when I use the link to the live form from the backend. But when I go to an article and use {chronoforms}ContactForm{/chronoforms} in the article it is not working. I keep getting the looping that the security code is incorrect. So, what I did is go to the contact article with the form and click send without filling any fields. I get the error messages for the required fields and the captcha field. Then fill in all of the fields correctly and submit. It comes back and says the captcha is incorrect. Fill in correct captcha and submit, get back incorrect captcha. I can't get past the captcha check now. Even if you don't do the initial submit without data, that is if you fill the form in correctly the first time, it comes back with invalid captcha message.

    In the Auto Validation on Fail Event loop, do I leave the Target Event as On Load or change to one of the other events? Is there anywhere that it is documented what the various Target events are/do?

    Are you going to upgrade your book to V4?

    Thanks again for all of your help.
    GreyHead 19 Apr, 2011
    Hi ljk,

    Good to hear that it's working.

    The OnLoad event is the correct one to use here. So far I haven't used anything else - the rest of the drop-down lists all the other events currently set up for the form so I guess that you could construct conditional loops for processing with a little planning.

    You should upgrade to the RC1.8 release for the component and the plug-in if you haven't already done so as I think Max fixed some problems with correctly passing the event type in the url. Hopefully that will resolve the submission problems.

    And, yes something will happen to update the book once Joomla! 1.6 and ChronoForms v4 have stabilised. I'm not yet sure if I'll do it with Packt, or rewrite as a series of tutorials (or both).

    Bob
    ljk 19 Apr, 2011
    Hi,

    Well it looks like everything is finally working.

    Thank you very, very much for all of your help on getting all of the issues solved.
    ljk 10 Aug, 2011
    Hi,

    I have upgraded to version 4 RC1.9.

    Just checking out the form again and there is a problem with the validation. If you leave all the required fields blank and just enter the captcha, it goes to the thank you page with an error message: You must provide at least one recipient e-mail address. rather than reloading the form and showing the error messages for the required fields. The name and email fields have the Required field checked.

    This is how I have the events setup:
    [attachment=0]form.JPG[/attachment]

    The On Fail Event Loop has On Load set for both the Captcha and JS Validation.

    Any ideas why the required field validation wouldn't be working?

    Thank you.
    GreyHead 11 Aug, 2011
    Hi ljk,

    Everything there looks OK. It should work on both the client-side and server-side validation.

    Please post a link to the form so I can take a quick look.

    Bob
    GreyHead 12 Aug, 2011
    Hi ljk,

    Your template (or some other component) is loading the jQuery JavaScript library. Out of the box jQuery isn't compatible with the MooTools library used by Joomla! and ChronoForms. You can use jQuery with MooTools in no-conflict mode. There are various ways of doing this. The simplest is to add a line of script in the ChronoForms Form JavaScript box:
    jQuery.noConflict();
    This will free the $ operator which is used by MooTools, so you may need to update your own javascripts to use the longer jQuery operator.

    There is also a neat Joomla! 1.5 system plugin named SC jQuery that allows you to control on which pages jQuery is loaded, and, in theory at least, will always load it in no-conflict mode.

    Bob
    ljk 12 Aug, 2011
    Hi,

    I added the jQuery.noConflict(); to the form, it is showing in the source code. But still the same results, the form validation is not working for the required fields.

    I tried putting the jQuery.noConflict(); in the form as you suggested and also right in the template, but neither fixed the problem.

    Any other ideas?

    Thank ou for your help.
    Max_admin 13 Aug, 2011
    Hi ljk,

    I see that you have a system plugin called "Load JQuery" ? try to either disable it or check its settings for a noConflict mode ? I "guess" that the noConflict line should be before the mootools file load, but I'm not sure really🙂

    Regards,
    Max
    Max
    ChronoForms developer...
    Did you try ChronoMyAdmin for managing your Joomla database tables ?
    GreyHead 13 Aug, 2011
    Hi ljk,

    The noConflict code has to run after the JQuery library is loaded and before any MooTools code is executed (loading the library itself doesn't cause an error).

    Unfortunately Joomla! (unlike WordPress) doesn't provide any good way of managing the load sequence :-(

    On your page The FormCheck library is being loaded and executed after JQuery loads and before the noConflict snippet. You could just copy and paste the snippet into the beginning of the formcheck-yiu.js file as a workaround.

    Bob
    Max_admin 13 Aug, 2011
    Cool, the solution is to inject the "noConflict" snippet into a "Load JS" action and make sure its placed under the "On Load" event BEFORE the "show HTML" action, this will make sure that the noConflict is loaded before the formcheck file code🙂

    Thanks Bob for clarifying this!🙂
    Max
    ChronoForms developer...
    Did you try ChronoMyAdmin for managing your Joomla database tables ?
    ljk 16 Aug, 2011
    Hi,

    Cool, the solution is to inject the "noConflict" snippet into a "Load JS" action and make sure its placed under the "On Load" event BEFORE the "show HTML" action, this will make sure that the noConflict is loaded before the formcheck file code


    This doesn't work, the noConflict still gets put in the wrong place.

    On your page The FormCheck library is being loaded and executed after JQuery loads and before the noConflict snippet. You could just copy and paste the snippet into the beginning of the formcheck-yiu.js file as a workaround.


    I have tried this as well and the validation still isn't working. See:
    http://www.radiology.redesignlab.com/components/com_chronoforms/js/formcheck/formcheck-yui.js
    has the jQuery.noConflict(); at the beginning of the file. I tried it both with the jQuery library plugin having the conflict mode turned on and off (so jQuery.noConflict(); was only added to the file once), but still no difference.

    Any other ideas?
    GreyHead 17 Aug, 2011
    Hi ljk,

    I'm struggling to make sense of this one. I can see the snippet there - and there is still a JavaScript error that looks like one that comes from a JavaScript libraby conflict :-( The error still show up when you view the form without the template JQuery is being loaded here but not much else.

    I'm not sure what else to usefully suggest. I'll download the SC JQuery plug-in and see if I can replicate the problem.

    Bob
    ljk 17 Aug, 2011
    Hi,

    The plugin that we are using isn't the SC Jquery one. We are using Accordion Menu Pro and it has its own library plugin that loads JQuery. That shouldn't make a difference, but just wanted to let you know.

    Thank you again for your help on this.
    Max_admin 22 Aug, 2011
    @ljk,

    When I test your form now I see the
    jQuery.noConflict();
    line in a wrong place, please try my suggestion earlier then let me know to test your form and see where the line of code is loaded exactly.

    Regards,
    Max
    Max
    ChronoForms developer...
    Did you try ChronoMyAdmin for managing your Joomla database tables ?
    ljk 22 Aug, 2011
    Hi Maxx,

    I did try what you suggested, but it didn't work. It put the jQuery.noConflict(); in the wrong place. It put it after the formcheck-yui.js link. If you let Joomla load the JS then it puts the JS after all the linked JS files, which is not what was needed in this case.

    Thanks.
    Max_admin 24 Aug, 2011
    Hi ljk,

    Ok, I see, the custom code snippets are always loaded after the files, regardless of when they have been called, in the new version I'm adding a new dynamic JS file to load snippets option, this comes handy as it loads the code before the other files based on the wizard order.

    Regards,
    Max
    Max
    ChronoForms developer...
    Did you try ChronoMyAdmin for managing your Joomla database tables ?
    ljk 15 Sep, 2011
    Hi,

    It doesn't seem to be the problem. Even if you add the noConflict in the top of the form validation JS file, the form will still not validate. There is something else that is causing a conflict between the Accordion menu and the validation scripts.
    This topic is locked and no more replies can be posted.