Forums

cannot email and submit form

mbohunovsky 24 Mar, 2015
I need to submit my form to an external site that only accepts POST arguments, but I also want to execute a couple email actions before the form gets submitted to that site.

I have Html render added to "on load" and the 2 email actions to "on submit".

If I select POST and enter an action URL in the Html Render setup, the form correctly submits to the external site. However, it completely ignores the 2 email actions.
If I leave the action URL field empty, then the 2 email actions are executed but I cannot get the form to then submit to the external site. I tried to add a redirect action with additional parameters (there is really only one field that I need to pass to the external site, all other fields are only used in the emails), but that does not work because the parameters from the redirect action are submitted as part of the URL (as a GET action)

I think what I am trying to do is very basic. What am I doing wrong?

Thanks,
Markus
GreyHead 24 Mar, 2015
Answer
1 Likes
Hi mbohunovsky,

As you've worked out the POST has to happen after the form submits and the emails are sent. There are a couple of ways to do this:

+ If you just need to send the data and the User stays on your site then the cURL action should do it,

+ If you need to send the User with the data - to confirm a subscription or payment - then you can do it by adding a 'dummy' form in the Thank you page. This form has all the data you need in hidden inputs and has the form action set to the remote URL. Then you can either display the data and add a 'Confirm' button for the user to click and submit to the other site; or you can use JavaScript to auto-submit the form after say 5 or 10 seconds. There's more about this in the FAQs.

Bob
mbohunovsky 24 Mar, 2015
that makes sense, thank you!

If I could pick your brain on one more thing:
Usually I would add a form.submit() to the onload event of the <body> tag of a page to auto-submit the form. However, in Joomla I can't do that (since the <body> tag is in the template. How do I make sure that the page is fully loaded before the submit() gets executed? I believe that simply adding the command at the end of the article would not be enough.

Also: I'm having real trouble adding javascript to Joomla articles. I can add them as long as I toggle my editor (JCE) to code view. They execute correctly. But if i ever forget that a specific article has a script on it and save it from the WYSIWYG view, the script gets completely erased. No settings that I've tried seem to change that and I have not been successful getting any clear answers on this in any general Joomla forum. How can I get Joomla to simply leave my scripts in place even if I'm in WYSIWYG mode of my text editor?

I know these are not ChromoForms questions so I understand if you can't reply but they are related to getting this to work without too many inconveniences.

thanks,
Markus
GreyHead 25 Mar, 2015
1 Likes
Hi Markus,

This JavaScript will automatically Submit a form:
jQuery(document).ready(function(jQ){
  jQ('#submit_btn').delay(500).click();
});

Note that submit_btn is the ID of the submit button in the form so edit to suit. You can also change or leave out the delay.

Add the JavaScript in a Load JavaScript action in your form On Load event.

I wouldn't even try to load a script into article text. It's syntactically poor design and causes more trouble than it is worth. If you need page specific scripts then you can use a ChronoForm with no visible output in a hidden location e.g. the footer module. Or better use something with less overhead - I used to use Jumi a lot - to add a few lines of PHP in an an invisible module that will then load your script as required:The basic PHP is
<?php
$jdoc = JFactory::getDocument();
$script = "
// some JavaScript here (can include PHP)
";
$jdoc->addScriptDeclaration($script);
?>
This will load the script snippet neatly in the template header.

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