1

When a profile is submitted without a valid cookie, the submission is lost (no data saved in the database) and the site redirects to the front page of the website. This occurs on Joomla when:

  • An HTML snippet is used (I'm working around this by embedding an iframe loading a standalone profile page, with CSS display:none to hide it)
  • You load a profile, then delete the cookies for the site
  • You load a profile, then wait a few hours before submitting it

We just had the 3rd condition trip up someone trying to fill out a form on our website. She loaded the page, let it sit overnight, and tried to submit the form 8 hours later. I don't know how to prevent this besides adding a note by the Save button to the effect of "If it has been more than an hour since you loaded this page, please reload it before saving the form". This seems really clunky, and will potentially lose the long answers users have entered into the form, if their browsers don't handle the reload well.

Is there a way to remove the dependence of the form submission on a cookie?

If not, is there a way to control what I assume is a cookie timeout, to reduce the incidence of the 3rd condition?

If not, is there a way to redirect the failed profile submission to an error page instructing the user to go back and try again? As it is, with no error given and the site redirecting to the front page of the website, the user has no idea anything went wrong and that their submission has been totally lost. This seems like a serious problem.

  • Bumping this... I think we're losing a significant number of membership applications, that vanish into nowhere with neither the end user nor us knowing anything went wrong. This is a serious problem. Please help! – Norris Sep 12 '15 at 7:43
1

I think I've tracked down the problem on my site to the uk.co.vedaconsulting Mailchimp plugin. Removing that seems to fix my issue on my test server, making my hack of embedding an iframe unnecessary (described at Why won't data entered into CiviCRM profile html snippet save? ). Hopefully it also fixes my timeout problem described here...testing that now.

EDIT Sept 22 2015:

Nope, i was wrong...misled by confusions in reloading pages and accidentally making it work with the background-loaded embedded form hack. Disabling Mailchimp or other plugins does not in fact change anything.

The approach I'm now using, successfully so far, is to load the embedded iframe hack at the time of form submission, rather than when the page is first loaded. So there's no danger of the page sitting too long , having the magic cookie (or whatever it is) time out.

1) user loads profile or page with HTML snippet

2) user eventually clicks "submit"

3) iframe hidden with CSS loads a small profile to set the magic cookie

4) when iframe finishes loading, it uses javascript to submit the original form

To accomplish this, I:

1) Embed javascript function in the head of each page with a profile:

<script type="text/javascript">
function loadHack() {
  var ifrm = document.createElement('iframe');
  ifrm.setAttribute('id', 'embeddedhack'); // assign an id
  document.body.appendChild(ifrm); // to place at end of document
  ifrm.setAttribute('src', '/en/?option=com_civicrm&task=civicrm/profile/create&gid=21&reset=1'); // assign url
}
</script>

2) use the alterContent hook (and manually edit HTML snippets) to make the submit button call the function above instead of submitting:

if($tplName == "CRM/Profile/Form/Edit.tpl") 
  $content = str_replace('id="_qf_Edit_next"', 'id="_qf_Edit_next" onClick="loadHack(); return false;"', $content);

3) use the alterContent hook to add a callback to the embedded hack profile, to submit the original form once it's finished loading the iframe:

if ($object->getVar('_gid') == 21) //hack form
        $content .= "<script type=\"text/javascript\">window.onload = function() {\n    parent.document.getElementById('Edit').submit();\n}\n</script>";

This is all ugly, but seems to work. I think this really needs to be addressed in core code, though.

  • See edit to my answer.... – Norris Sep 22 '15 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.