{"id":56638,"date":"2023-02-09T12:14:09","date_gmt":"2023-02-09T06:44:09","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=56638"},"modified":"2025-12-04T11:21:53","modified_gmt":"2025-12-04T05:51:53","slug":"creating-a-simple-dynamic-form-using-data-from-strapi-cms","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/creating-a-simple-dynamic-form-using-data-from-strapi-cms\/","title":{"rendered":"Creating a Simple Dynamic form Using Data from Strapi CMS"},"content":{"rendered":"<p>In my previous blog, I showed how we could create a collection in <a href=\"https:\/\/strapi.io\/\">Strapi<\/a> that could further be used as input data to a dynamic form component to render a form as per users requirements.<\/p>\n<p><b>Create a React Project\u00a0<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a project using create react app.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Refer <\/span><a href=\"https:\/\/reactjs.org\/docs\/create-a-new-react-app.html\"><span style=\"font-weight: 400;\">https:\/\/reactjs.org\/docs\/create-a-new-react-app.html<\/span><\/a><span style=\"font-weight: 400;\"> in case of any issues.<\/span><\/li>\n<li>Install axios using <strong>npm i axios<\/strong><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<\/ol>\n<p><b>Structure of the React App<\/b><\/p>\n<ol>\n<li>We will create a button upon which click we will fetch data from the <a href=\"https:\/\/strapi.io\/\">Strapi<\/a> server using axios.<\/li>\n<li>Upon successfully fetching the data, we will send that data to our Form component, which will create later.<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56631 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-23-16.png\" alt=\"\" width=\"667\" height=\"602\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-23-16.png 667w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-23-16-300x271.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-23-16-624x563.png 624w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/li>\n<li>Next, we will create our individual Input type components. Here will be creating just three i.e. Button, Dropdown, and Input Field.<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56632 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-25-35.png\" alt=\"\" width=\"483\" height=\"250\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-25-35.png 483w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-25-35-300x155.png 300w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56633 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-26-29.png\" alt=\"\" width=\"702\" height=\"623\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-26-29.png 702w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-26-29-300x266.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-26-29-624x554.png 624w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56634 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-27-29.png\" alt=\"\" width=\"1022\" height=\"406\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-27-29.png 1022w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-27-29-300x119.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-27-29-768x305.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-27-29-624x248.png 624w\" sizes=\"(max-width: 1022px) 100vw, 1022px\" \/><\/li>\n<li>Next, we will be creating our Form Component, which makes use of the above-created components to render the final form to the user:<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56635 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20-1024x884.png\" alt=\"\" width=\"625\" height=\"540\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20-1024x884.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20-300x259.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20-768x663.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20-624x539.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-29-20.png 1049w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/>\n<p>Here is the util file :<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56636 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49-1024x884.png\" alt=\"\" width=\"625\" height=\"540\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49-1024x884.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49-300x259.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49-768x663.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49-624x539.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/Screenshot-from-2023-02-07-17-30-49.png 1049w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<li>This is what our Form looks like:<br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-56637 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page-1024x512.png\" alt=\"\" width=\"625\" height=\"313\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page-1024x512.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page-300x150.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page-768x384.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page-624x312.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/02\/form-page.png 1521w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<\/ol>\n<p><strong>Link to the github repo: https:\/\/github.com\/codeM1997\/react-strapi-form<\/strong><\/p>\n<p><b>Some things to try on your own:\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400;\">1) <\/span><b>Validations<\/b><span style=\"font-weight: 400;\">: Try creating a collection type for validations and use it along your forms by editing the form details structure in content type and builders. You can create validation cases for minimum length, maximum length, required etc.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2) <\/span><b>Using GraphQl for fetching data from Strap<\/b><span style=\"font-weight: 400;\">i: <\/span> <span style=\"font-weight: 400;\">You can use the graphql plugin in <a href=\"https:\/\/strapi.io\/\">Strapi<\/a> and request data as per your need. At the react end, You can use Apollo to fetch data using graphql queries.<br \/>\nYou can refer to this article for the same: <\/span><a href=\"https:\/\/docs.strapi.io\/developer-docs\/latest\/developer-resources\/content-api\/integrations\/graphql.html#examples-2\"><span style=\"font-weight: 400;\">https:\/\/docs.strapi.io\/developer-docs\/latest\/developer-resources\/content-api\/integrations\/graphql.html#examples-2<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>In my previous blog, I showed how we could create a collection in Strapi that could further be used as input data to a dynamic form component to render a form as per users requirements. Create a React Project\u00a0 Create a project using create react app. Refer https:\/\/reactjs.org\/docs\/create-a-new-react-app.html in case of any issues. Install axios [&hellip;]<\/p>\n","protected":false},"author":1540,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":380},"categories":[3038,1994],"tags":[5102],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56638"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1540"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=56638"}],"version-history":[{"count":5,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56638\/revisions"}],"predecessor-version":[{"id":76979,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56638\/revisions\/76979"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=56638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=56638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=56638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}