{"id":1249,"date":"2021-10-15T13:40:06","date_gmt":"2021-10-15T12:40:06","guid":{"rendered":"https:\/\/wearesmile.com\/help\/?post_type=ht_kb&#038;p=1249"},"modified":"2021-10-22T16:38:06","modified_gmt":"2021-10-22T15:38:06","slug":"how-to-require-data-capture-before-viewing-a-post","status":"publish","type":"ht_kb","link":"https:\/\/wearesmile.com\/help\/documentation\/how-to-require-data-capture-before-viewing-a-post\/","title":{"rendered":"How to require data capture before viewing a post"},"content":{"rendered":"\n<p>You may wish to restrict access to a post to only those who have completed a data capture form. A practical example can be found on the SMILE website. We publish roundups from our webinars which include a recording, slides, links, questions etc. But we require that you be signed up to our mailing list in order to access it.<\/p>\n\n\n\n<p>This article will show you how to do similar.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">This approach requires the use of cookies<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Requirements<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>You must be able to access &#8220;<strong>Custom fields<\/strong>&#8221; in the edit screen<\/li><li>You must have the <strong><a href=\"https:\/\/www.gravityforms.com\/\">Gravity Forms<\/a><\/strong> and <strong><a href=\"https:\/\/gravitywiz.com\/submit-gravity-form-access-content\/\">Gravity Forms Submit to Access<\/a><\/strong> enabled (both are available for <a href=\"https:\/\/wearesmile.com\/help\/article-categories\/happypress\/\">HappyPress subscribers<\/a> at no additional cost)<\/li><li>You must have the <a href=\"https:\/\/wordpress.org\/plugins\/redirection\/\">Redirection<\/a> plugin enabled (available for <a href=\"https:\/\/wearesmile.com\/help\/article-categories\/happypress\/\">HappyPress subscribers<\/a> at no additinoal cost)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Set-up<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a form that you want users to fill out in order to access your post. Make a note of the form ID. You can find this in the list of forms.<\/li><li>Create and publish a page with your form added in the main body. We will redirect users to this page if they have not filled out the form before. Make a note of the URL to this page.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Restricting access<\/h2>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>Add the following custom fields to the post you wish to restrict&#8230;<ol><li>Name: <code>gwsa_require_submission<\/code><br>Value: <code>1<\/code><\/li><li>Name: <code>gwsa_form_ids<\/code><br>Value: Set this to the form ID that you require the user to have completed in order to access this post. If you require multiple forms, simply add a comma separated list of values (Example: <code>1,2,3<\/code>)<\/li><li>Name: <code>bypass_cache<\/code><br>Value: <code>true<\/code><br><em>This sends the post data via AJAX,  in order to avoid the cache. Note: this does not always work &#8211; especially on HappyPress. There is an optional tip at the end of this list which will ensure you bypass the cache.<\/em><\/li><li><s>Name: <code>gwsa_requires_submission_redirect<\/code><br>Value: The URL to the page where your form is hosted<\/s><br><em>Don&#8217;t do this, as it damages your RSS feed!<\/em><\/li><\/ol><\/li><li><strong>OPTIONAL<\/strong> (<em>recommended for HappyPress subscribers<\/em>): Add a redirect under <code>Tools > Redirection<\/code> for the post you have restricted access to.<ol><li>Source URL: The URL to the post you wish to access<\/li><li>Query Parameters: <code>Exact match in any order<\/code><\/li><li>Target URL: The URL to the post you wish to access, appended by <code>\/?subscribers-only<\/code><ol><li>In truth, any query parameter here is fine. We like this one because its semantically obvious for newcomers to understand. But all this is doing is hitting a rule in HappyPress that means the page will not be server-side cached. As a result, this technique is not great for posts that may have very high numbers of concurrent users.<\/li><\/ol><\/li><\/ol><\/li><\/ol>\n\n\n\n<p>Now your users will be redirected to the form if they have not previously filled it out. When they do, a cookie will be added to their device so that they do not get redirected again in the future. They will then be able to access the post.<\/p>\n\n\n\n<p>For more options in the Gravity Forms Submit to Access plugin, please visit the <a href=\"https:\/\/gravitywiz.com\/submit-gravity-form-access-content\/\">Gravity Perks website<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may wish to restrict access to a post to only those who have completed a data capture form. A practical example can be found on the SMILE website. We publish roundups from our webinars which include a recording, slides, links, questions etc. But we require that you be signed&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_searchwp_excluded":"","footnotes":""},"ht-kb-category":[88],"ht-kb-tag":[],"class_list":["post-1249","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-happypress"],"_links":{"self":[{"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb\/1249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/comments?post=1249"}],"version-history":[{"count":4,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb\/1249\/revisions"}],"predecessor-version":[{"id":1266,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb\/1249\/revisions\/1266"}],"wp:attachment":[{"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/media?parent=1249"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb-category?post=1249"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/wearesmile.com\/help\/wp-json\/wp\/v2\/ht-kb-tag?post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}