Answers.Body: <p>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 <a href="https://civicrm.stackexchange.com/questions/2616/why-wont-data-entered-into-civicrm-profile-html-snippet-save/6384#6384">Why won&#39;t data entered into CiviCRM profile html snippet save?</a> ). Hopefully it also fixes my timeout problem described here...testing that now.</p>
  
  <p>EDIT Sept 22 2015: </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>1) user loads profile or page with HTML snippet</p>
  
  <p>2) user eventually clicks "submit"</p>
  
  <p>3) iframe hidden with CSS loads a small profile to set the magic cookie</p>
  
  <p>4) when iframe finishes loading, it uses javascript to submit the original form</p>
  
  <p>To accomplish this, I:</p>
  
  <p>1) Embed javascript function in the head of each page with a profile:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  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&amp;task=civicrm/profile/create&amp;gid=21&amp;reset=1'); // assign url
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>2) use the alterContent hook (and manually edit HTML snippets) to make the submit button call the function above instead of submitting:</p>
  
  <pre><code>if($tplName == "CRM/Profile/Form/Edit.tpl") 
    $content = str_replace('id="_qf_Edit_next"', 'id="_qf_Edit_next" onClick="loadHack(); return false;"', $content);
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>if ($object-&gt;getVar('_gid') == 21) //hack form
          $content .= "&lt;script type=\"text/javascript\"&gt;window.onload = function() {\n    parent.document.getElementById('Edit').submit();\n}\n&lt;/script&gt;";
  </code></pre>
  
  <p>This is all ugly, but seems to work.  I think this really needs to be addressed in core code, though.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-22T21:41:00.483Z
Answers.Text: See edit to my answer....
Answers.UserDisplayName: Norris
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-12T22:13:08.940Z
Answers.LastActivityDate: 2015-09-22T22:01:06.240Z
Answers.LastEditDate: 2015-09-22T22:01:06.240Z
Answers.UserDisplayName: Norris
Body: <p>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:</p>
  
  <ul>
  <li>An <a href="https://civicrm.stackexchange.com/questions/2616/why-wont-data-entered-into-civicrm-profile-html-snippet-save">HTML snippet</a> is used (I'm working around this by embedding an iframe loading a standalone profile page, with CSS display:none to hide it)
  <li>You load a profile, then delete the cookies for the site
  <li>You load a profile, then wait a few hours before submitting it
  </ul>
  
  <p>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.</p>
  
  <p>Is there a way to remove the dependence of the form submission on a cookie?</p>
  
  <p>If not, is there a way to control what I assume is a cookie timeout, to reduce the incidence of the 3rd condition?  </p>
  
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-12T07:43:45.043Z
Comments.Text: 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!
Comments.UserDisplayName: Norris
Tags: <profile><cookies>
Title: How do I make profile submissions more reliable, or at least not silently fail?
ThreadText: # How do I make profile submissions more reliable, or at least not silently fail?
  
  (Asked by: username_0 on 2015-08-05)
  
  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](https://civicrm.stackexchange.com/questions/2616/why-wont-data-entered-into-civicrm-profile-html-snippet-save) 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.
  
  **Tags:** profile, cookies
  
  > **Comments:**
  > **username_0**: 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!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-09-12. Score: 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?](https://civicrm.stackexchange.com/questions/2616/why-wont-data-entered-into-civicrm-profile-html-snippet-save/6384#6384) ). 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.
  
  > **Comments:**
  > **username_0**: See edit to my answer....  
  
  ---
  
  