Answers.Body: <p>I managed to get this to work by creating a custom text field in Civi. I then included this text field in the webform as a hidden component and set a default value. This value then gets set (for the text field) only when the form is submitted. I can then test the field to see if it has the set value or not and use this to hide or block the webform from the user.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-28T12:58:25.557Z
Answers.LastActivityDate: 2018-09-28T12:58:25.557Z
Answers.UserDisplayName: Ben
Answers.Body: <p>There are Drupal permissions that can prevent certain Roles seeing Submitted forms which may deal with "The reason is I want to allow users to access and edit the information in the webform, but find a way of preventing them from accessing/editing the form once it has been "submitted".</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-28T12:54:18.980Z
Answers.Text: Thanks for the suggestion Pete, I did have a look at this but couldn't get it to work. I think I have found a fairly simple solution. I can create a custom text field which can be hidden on the form and have a default value set in the webform (not Civi) that gets set when the form is submitted. Then I can tell if the form has been submitted or not. I had tried this with a radio select field and couldn't get it to work, but I have got a straight text field to work.
Answers.UserDisplayName: Ben
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-28T02:17:14.773Z
Answers.LastActivityDate: 2018-09-28T02:17:14.773Z
Answers.UserDisplayName: petednz - fuzion
Body: <p>I want to set a value on a field in a CiviCRM webform only when the form is submitted and not when saved as draft. The field is a CiviCRM field that appears in the webform but is not shown to the user. </p>
  
  <p>The reason is I want to allow users to access and edit the information in the webform, but find a way of preventing them from accessing/editing the form once it has been "submitted".  So I had created a yes/no field in Civi which I could set to yes when they submit the form and then prevent them from accessing the form if the value for the field was yes. </p>
  
  <p>I was trying to set the value of the field using hook_webform_submission_presave but kept on getting errors. Not sure if this was because the form is split up into several pages and is using the "Save Draft" functionality. I'm not sure also if this is the right approach for CiviCRM enabled webforms. </p>
  
  <p>This webform could be for either creating a new CiviCase record or editing an existing one. </p>
  
  <p>Am open to suggestions of any other ways of preventing users from accessing the form after they have already submitted it.</p>
  
  <p>I am using CiviCRM 5.3.1 with Drupal 7.59.</p>
  
Tags: <webform-civicrm>
Title: Set Hidden Field Value on Webform Connected to CiviCRM on Submit
ThreadText: # Set Hidden Field Value on Webform Connected to CiviCRM on Submit
  
  (Asked by: username_0 on 2018-09-27)
  
  I want to set a value on a field in a CiviCRM webform only when the form is submitted and not when saved as draft. The field is a CiviCRM field that appears in the webform but is not shown to the user.
  
  The reason is I want to allow users to access and edit the information in the webform, but find a way of preventing them from accessing/editing the form once it has been "submitted". So I had created a yes/no field in Civi which I could set to yes when they submit the form and then prevent them from accessing the form if the value for the field was yes.
  
  I was trying to set the value of the field using hook\_webform\_submission\_presave but kept on getting errors. Not sure if this was because the form is split up into several pages and is using the "Save Draft" functionality. I'm not sure also if this is the right approach for CiviCRM enabled webforms.
  
  This webform could be for either creating a new CiviCase record or editing an existing one.
  
  Am open to suggestions of any other ways of preventing users from accessing the form after they have already submitted it.
  
  I am using CiviCRM 5.3.1 with Drupal 7.59.
  
  **Tags:** webform-civicrm
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-09-28. Score: 2
  
  I managed to get this to work by creating a custom text field in Civi. I then included this text field in the webform as a hidden component and set a default value. This value then gets set (for the text field) only when the form is submitted. I can then test the field to see if it has the set value or not and use this to hide or block the webform from the user.
  
  
  ---
  
  ### Answer by username_1 on 2018-09-28. Score: 0
  
  There are Drupal permissions that can prevent certain Roles seeing Submitted forms which may deal with "The reason is I want to allow users to access and edit the information in the webform, but find a way of preventing them from accessing/editing the form once it has been "submitted".
  
  > **Comments:**
  > **username_0**: Thanks for the suggestion Pete, I did have a look at this but couldn't get it to work. I think I have found a fairly simple solution. I can create a custom text field which can be hidden on the form and have a default value set in the webform (not Civi) that gets set when the form is submitted. Then I can tell if the form has been submitted or not. I had tried this with a radio select field and couldn't get it to work, but I have got a straight text field to work.  
  
  ---
  
  