{"id":160,"date":"2024-05-28T11:02:13","date_gmt":"2024-05-28T15:02:13","guid":{"rendered":"https:\/\/htmlformsplugin.test\/?p=160"},"modified":"2024-05-31T11:40:48","modified_gmt":"2024-05-31T15:40:48","slug":"conditional-elements","status":"publish","type":"post","link":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/","title":{"rendered":"Conditional Elements"},"content":{"rendered":"\n<p>Conditional elements are supported in <a href=\"https:\/\/htmlformsplugin.com\/\" data-type=\"link\" data-id=\"https:\/\/htmlformsplugin.com\/\">HTML Forms<\/a> by using two special attributes:\u00a0<code>data-show-if<\/code>\u00a0and\u00a0<code>data-hide-if<\/code>.<\/p>\n\n\n\n<p>Using these attributes allows you to hide or show parts of your form by referencing the name attribute of a field in your form.<\/p>\n\n\n\n<p>For example, you could choose to only show the submit button after the email field is filled.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"\" class=\"\">&lt;input type=\"email\" name=\"EMAIL\" required \/>\n&lt;input type=\"submit\" value=\"Send\" data-show-if=\"EMAIL\" \/><\/code><\/pre>\n\n\n\n<p>Let\u2019s do another example where you have a help text is hidden after someone starts typing in the field it describes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"\" class=\"\">&lt;input type=\"text\" name=\"NAME\" \/>\n&lt;p data-hide-if=\"NAME\">Enter your name in the field above.&lt;\/p><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Specifying an Exact Value<\/h2>\n\n\n\n<p>The examples above will show or hide an element whenever the field that it is depending on contains any value, regardless of the actual value.<\/p>\n\n\n\n<p>Sometimes you want to depend on an exact value though. This can be done by following the field name with a colon and the value you need, like this:&nbsp;<code>NAME:VALUE<\/code>.<\/p>\n\n\n\n<p>Let\u2019s build a form with a list of checkboxes, where a message shows up only when one particular choice is selected.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"\" class=\"\">&lt;input type=\"checkbox\" name=\"JOB\" value=\"Marketeer\" \/> Marketeer\n&lt;input type=\"checkbox\" name=\"JOB\" value=\"Developer\" \/> Developer\n&lt;input type=\"checkbox\" name=\"JOB\" value=\"Recruiter\" \/> Recruiter\n\n&lt;div data-show-if=\"JOB:Recruiter\">\n    Hi, recruiter!\n&lt;\/div><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"specifying-multiple-values\">Specifying Multiple Values<\/h2>\n\n\n\n<p>Continuing with the above example, what if you wanted to show part of your form for both developers and marketeers?<\/p>\n\n\n\n<p>You can specify multiple expected values by separating them with a\u00a0<code>|<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">&lt;input type=\"checkbox\" name=\"JOB\" value=\"Marketeer\" \/> Marketeer\n&lt;input type=\"checkbox\" name=\"JOB\" value=\"Developer\" \/> Developer\n&lt;input type=\"checkbox\" name=\"JOB\" value=\"Recruiter\" \/> Recruiter\n\n&lt;div data-show-if=\"JOB:Marketeer|Developer\">\n    Hi, marketeer or developer!\n&lt;\/div><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>HTML Forms supports conditional elements that you can use to hide or show parts of your forms.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[6],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-kb","tag-advanced"],"yoast_head":"<title>Conditional Elements - HTML Forms WordPress Plugin<\/title>\n<meta name=\"description\" content=\"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conditional Elements\" \/>\n<meta property=\"og:description\" content=\"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/\" \/>\n<meta property=\"og:site_name\" content=\"HTML Forms WordPress Plugin\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-28T15:02:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-31T15:40:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/open-graph-html-forms.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Conditional Elements\" \/>\n<meta name=\"twitter:description\" content=\"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/person\\\/91bdb8fe3d28e069afcaa14af31ce932\"},\"headline\":\"Conditional Elements\",\"datePublished\":\"2024-05-28T15:02:13+00:00\",\"dateModified\":\"2024-05-31T15:40:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/\"},\"wordCount\":193,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\"},\"keywords\":[\"Advanced\"],\"articleSection\":[\"Knowledge Base\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/\",\"name\":\"Conditional Elements - HTML Forms WordPress Plugin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#website\"},\"datePublished\":\"2024-05-28T15:02:13+00:00\",\"dateModified\":\"2024-05-31T15:40:48+00:00\",\"description\":\"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/kb\\\/conditional-elements\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/htmlformsplugin.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Conditional Elements\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#website\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/\",\"name\":\"HTML Forms WordPress Plugin\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/htmlformsplugin.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#organization\",\"name\":\"HTML Forms WordPress Plugin\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/html-forms-logo.png\",\"contentUrl\":\"https:\\\/\\\/htmlformsplugin.com\\\/wp-content\\\/uploads\\\/2024\\\/05\\\/html-forms-logo.png\",\"width\":256,\"height\":256,\"caption\":\"HTML Forms WordPress Plugin\"},\"image\":{\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/htmlformsplugin.com\\\/#\\\/schema\\\/person\\\/91bdb8fe3d28e069afcaa14af31ce932\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/htmlformsplugin.com\"],\"url\":\"https:\\\/\\\/htmlformsplugin.com\\\/author\\\/admin\\\/\"}]}<\/script>","yoast_head_json":{"title":"Conditional Elements - HTML Forms WordPress Plugin","description":"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/","og_locale":"en_US","og_type":"article","og_title":"Conditional Elements","og_description":"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.","og_url":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/","og_site_name":"HTML Forms WordPress Plugin","article_published_time":"2024-05-28T15:02:13+00:00","article_modified_time":"2024-05-31T15:40:48+00:00","og_image":[{"width":1200,"height":600,"url":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/open-graph-html-forms.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_title":"Conditional Elements","twitter_description":"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/#article","isPartOf":{"@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/"},"author":{"name":"admin","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/person\/91bdb8fe3d28e069afcaa14af31ce932"},"headline":"Conditional Elements","datePublished":"2024-05-28T15:02:13+00:00","dateModified":"2024-05-31T15:40:48+00:00","mainEntityOfPage":{"@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/"},"wordCount":193,"commentCount":0,"publisher":{"@id":"https:\/\/htmlformsplugin.com\/#organization"},"keywords":["Advanced"],"articleSection":["Knowledge Base"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/","url":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/","name":"Conditional Elements - HTML Forms WordPress Plugin","isPartOf":{"@id":"https:\/\/htmlformsplugin.com\/#website"},"datePublished":"2024-05-28T15:02:13+00:00","dateModified":"2024-05-31T15:40:48+00:00","description":"HTML Forms supports conditional elements that you can use to hide or show parts of your forms.","breadcrumb":{"@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/htmlformsplugin.com\/kb\/conditional-elements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/htmlformsplugin.com\/"},{"@type":"ListItem","position":2,"name":"Conditional Elements"}]},{"@type":"WebSite","@id":"https:\/\/htmlformsplugin.com\/#website","url":"https:\/\/htmlformsplugin.com\/","name":"HTML Forms WordPress Plugin","description":"","publisher":{"@id":"https:\/\/htmlformsplugin.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/htmlformsplugin.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/htmlformsplugin.com\/#organization","name":"HTML Forms WordPress Plugin","url":"https:\/\/htmlformsplugin.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/logo\/image\/","url":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/html-forms-logo.png","contentUrl":"https:\/\/htmlformsplugin.com\/wp-content\/uploads\/2024\/05\/html-forms-logo.png","width":256,"height":256,"caption":"HTML Forms WordPress Plugin"},"image":{"@id":"https:\/\/htmlformsplugin.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/htmlformsplugin.com\/#\/schema\/person\/91bdb8fe3d28e069afcaa14af31ce932","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0a4e20dbdeef8b13256313af7321c678398555dcdb38d24a93099545d83010c7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/htmlformsplugin.com"],"url":"https:\/\/htmlformsplugin.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":5,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/posts\/160\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/htmlformsplugin.com\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}