Answers.Body: <p>The way I've done this is:</p>
  <ol>
  <li><p>in preProcess, <code>if (!empty($_GET['reset'])) {</code> then inspect GET for the initialisation data, and if it's valid, store it using <code>$this-&gt;set('key', $validData)</code>. I've also set some object properties in this stage, but these will only be around for one request, including a <code>showForm</code> one. I have called <code>setMessage()</code> with any initiation data validation errors.</p>
  </li>
  <li><p>in <code>buildQuickForm</code>, I've reduced this to adding just the form elements I need to display. (I was previously using hidden elements to store the authorised/parsed initiation data.) I also <code>$this-&gt;assign('showForm', $this-&gt;_showForm);</code></p>
  </li>
  <li><p>in my <code>.tpl</code> file I wrap the whole thing in <code>{if $showForm}</code>.</p>
  </li>
  <li><p>in <code>postProcess</code> I fetch data using <code>$this-&gt;get('contactID');</code> and user submitted form values from <code>$this-&gt;exportValues()</code>. I process that and use <code>setStatus</code>. I then set <code>$this-&gt;_showForm = FALSE</code> (might not be necessary) and do a redirect to the same path but without any query data.</p>
  </li>
  <li><p>on the redirect, without any GET data, my default FALSE <code>showForm</code> variable is not changed, and the form does not display, except for the <code>setMessage</code> messages.</p>
  </li>
  </ol>
  <p>Phew.</p>
  <p>I'm not sure this is the right way. But it seems to work. Other answers very welcome!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-04T09:07:21.603Z
Answers.LastActivityDate: 2020-12-04T09:07:21.603Z
Answers.UserDisplayName: artfulrobot
Body: <p>I'm writing an extension with a quickform form. It takes <code>_GET</code> parameters to set itself up. I've done this in buildQuickForm (not sure when I'd choose to use preProcess instead?)</p>
  <p>I've got the quickform to display and to be processed ok, but once it's processed ok I'd just like to display a &quot;ta very much, love&quot; message to confirm it's all finished.</p>
  <p>I'm using <code>CRM_Core_Session::setStatus()</code> to display the message.</p>
  <p>The problem is that after processing it seems to issue an HTTP redirect to which then goes back to the build phase, which then gives errors because there's no <code>_GET</code> data this time.</p>
  <p>I've tried (to no avail)</p>
  <ul>
  <li><p>using <code>$this-&gt;set('isCompleted', TRUE)</code> in the <code>postProcess()</code> function and then checking for that using <code>$this-&gt;get('isCompleted')</code> in the <code>buildQuickForm()</code> function, but it get unset.</p>
  </li>
  <li><p>using <code>CRM_Core_Session::pushUserContext('civicrm/myform?isCompleted=1')</code> thinking that this might cause a redirect to that URL. It doesn't.</p>
  </li>
  <li><p>setting a property on the form in post, but it's not there when the form is re-fetched.</p>
  </li>
  <li><p>using <code>CRM_Utils_System::redirect()</code> to redirect to <code>civicrm/myform/?isCompleted=1</code>, which does redirect, but not until the build has re-run and generated errors on the session.</p>
  </li>
  </ul>
  
Tags: <quickform>
Title: Display thank you message in QuickForm
ThreadText: # Display thank you message in QuickForm
  
  (Asked by: username_0 on 2020-12-04)
  
  I'm writing an extension with a quickform form. It takes `_GET` parameters to set itself up. I've done this in buildQuickForm (not sure when I'd choose to use preProcess instead?)
  
  I've got the quickform to display and to be processed ok, but once it's processed ok I'd just like to display a "ta very much, love" message to confirm it's all finished.
  
  I'm using `CRM_Core_Session::setStatus()` to display the message.
  
  The problem is that after processing it seems to issue an HTTP redirect to which then goes back to the build phase, which then gives errors because there's no `_GET` data this time.
  
  I've tried (to no avail)
  
  * using `$this->set('isCompleted', TRUE)` in the `postProcess()` function and then checking for that using `$this->get('isCompleted')` in the `buildQuickForm()` function, but it get unset.
  * using `CRM_Core_Session::pushUserContext('civicrm/myform?isCompleted=1')` thinking that this might cause a redirect to that URL. It doesn't.
  * setting a property on the form in post, but it's not there when the form is re-fetched.
  * using `CRM_Utils_System::redirect()` to redirect to `civicrm/myform/?isCompleted=1`, which does redirect, but not until the build has re-run and generated errors on the session.
  
  **Tags:** quickform
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-12-04. Score: 1
  
  The way I've done this is:
  
  1. in preProcess, `if (!empty($_GET['reset'])) {` then inspect GET for the initialisation data, and if it's valid, store it using `$this->set('key', $validData)`. I've also set some object properties in this stage, but these will only be around for one request, including a `showForm` one. I have called `setMessage()` with any initiation data validation errors.
  2. in `buildQuickForm`, I've reduced this to adding just the form elements I need to display. (I was previously using hidden elements to store the authorised/parsed initiation data.) I also `$this->assign('showForm', $this->_showForm);`
  3. in my `.tpl` file I wrap the whole thing in `{if $showForm}`.
  4. in `postProcess` I fetch data using `$this->get('contactID');` and user submitted form values from `$this->exportValues()`. I process that and use `setStatus`. I then set `$this->_showForm = FALSE` (might not be necessary) and do a redirect to the same path but without any query data.
  5. on the redirect, without any GET data, my default FALSE `showForm` variable is not changed, and the form does not display, except for the `setMessage` messages.
  
  Phew.
  
  I'm not sure this is the right way. But it seems to work. Other answers very welcome!
  
  
  ---
  
  