title: Dynamic Forms in Netlify
body: <p>I have two components in React that in a sense are both forms. One component is a parent form of some sorts that contains a map function that iterates over a <code>children</code> state item to produce a number of children sub forms. This means that people using the forms can click a button to add a new instance of a ChildSubForm component beneath the button in the parent form.</p>
  <p>My current issue is that I cannot get the form to pick up the children in Netlify forms. I have <code>data-netlify=&quot;true&quot;</code> and the hidden input so the parent form is recognised, however when I submit the form, only the inputs in the parent form are picked up, how can I change my settings or code to allow netlify to detect the dynamic components' values so that they are sent alongside the other data?</p>
  <p>As you can see, I also attempted to store all form data in state items and submit them, but I cannot see the values still. Is it something to do with Netlify building the static site and detecting all form values beforehand?</p>
  <p>BookNow.js (The parent form)</p>
  <pre><code>import React, { Component } from 'react'
  
  import ChildSubForm from './ChildSubForm'
  
  export default class BookNow extends Component {
      state = {
          name: &quot;&quot;,
          email: &quot;&quot;,
          otherInfo: &quot;&quot;,
          children: []
      }
  
      constructor(props) {
          super(props)
          this.addChild = this.addChild.bind(this);
          this.decrementChild = this.decrementChild.bind(this);
          this.handleChange = this.handleChange.bind(this);
          this.handleSubmit = this.handleSubmit.bind(this);
      }
  
      addChild() {
          this.setState({
              children: [...this.state.children, { name: &quot;&quot;, year: &quot;Year 7&quot; }]
          })
      }
  
      decrementChild(i) {
          this.setState({
              children: this.state.children.filter((item, j) =&gt; i !== j)
          })
      }
  
      handleChange(e) {
          if ([&quot;name&quot;, &quot;year&quot;].includes(e.target.className)) {
              let children = [...this.state.children]
              children[e.target.dataset.id][e.target.className] = e.target.value
              this.setState({ children }, () =&gt; console.log(this.state.children))
          } else {
              this.setState({ [e.target.name]: e.target.value })
          }
      }
  
      handleSubmit(e) {
          e.preventDefault()
      }
  
  
      render() {
          if(this.props.isChild) {
              return (
                  &lt;form name=&quot;Booking Form&quot; method=&quot;POST&quot; data-netlify=&quot;true&quot;&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;form-name&quot; value=&quot;Booking Form&quot; /&gt;
                      &lt;input type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;Your Name&quot; /&gt;
                      &lt;select name=&quot;year-group&quot;&gt;
                          &lt;option value=&quot;Year 7&quot;&gt;Year 7&lt;/option&gt;
                          &lt;option value=&quot;Year 8&quot;&gt;Year 8&lt;/option&gt;
                          &lt;option value=&quot;Year 9&quot;&gt;Year 9&lt;/option&gt;
                          &lt;option value=&quot;Year 10&quot;&gt;Year 10&lt;/option&gt;
                          &lt;option value=&quot;Year 11&quot;&gt;Year 11&lt;/option&gt;
                          &lt;option value=&quot;Year 12&quot;&gt;Year 12&lt;/option&gt;
                          &lt;option value=&quot;Year 13&quot;&gt;Year 13&lt;/option&gt;
                          &lt;option value=&quot;GCSE Retake&quot;&gt;GCSE Retake&lt;/option&gt;
                      &lt;/select&gt;&lt;br /&gt;
                      &lt;input type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Your Email Address&quot; /&gt;&lt;br /&gt;
                      &lt;textarea name=&quot;otherInfo&quot; placeholder=&quot;Any more information...&quot; /&gt;&lt;br /&gt;
                      &lt;button type=&quot;submit&quot;&gt;Book Now&lt;/button&gt;
                  &lt;/form&gt;
              )
          } else {
              return (
                  &lt;form onChange={this.handleChange} onSubmit={this.handleSubmit} name=&quot;Booking Form&quot; method=&quot;POST&quot; data-netlify=&quot;true&quot;&gt;
                      &lt;input type=&quot;hidden&quot; name=&quot;form-name&quot; value=&quot;Booking Form&quot; /&gt;
                      &lt;input type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;Your Name&quot; /&gt;&lt;br /&gt;
                      &lt;input type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Your Email Address&quot; /&gt;&lt;br /&gt;
                      &lt;button onClick={this.addChild} name=&quot;add&quot;&gt;+ Add Child&lt;/button&gt;&lt;br /&gt;
                      {
                          this.state.children.map((child, i) =&gt; &lt;ChildSubForm key={i} childNum={i} value={this.state.children[i]} dec={() =&gt; this.decrementChild(i)} /&gt;)
                      }
                      &lt;textarea name=&quot;otherInfo&quot; placeholder=&quot;Any more information...&quot; /&gt;&lt;br /&gt;
                      &lt;button type=&quot;submit&quot;&gt;Book Now&lt;/button&gt;
                  &lt;/form&gt;
              )
          }
      }
  }
  </code></pre>
  <p>ChildSubForm.js</p>
  <pre><code>import React, { Component } from 'react'
  
  export default class ChildSubForm extends Component {
      render() {
          const values = {
              name: `child-name-${this.props.childNum}`,
              year: `child-${this.props.childNum}-year-group`
          }
          return (
              &lt;div className=&quot;ChildSubForm&quot;&gt;
                  &lt;input type=&quot;text&quot; id={values.name} name={values.name} data-id={this.props.childNum} value={this.props.value.name} className=&quot;name&quot; placeholder=&quot;Child's Name&quot; required /&gt;
                  &lt;select name={values.year} id={values.year} data-id={this.props.childNum} id={values.year} value={this.props.value.year} className=&quot;year&quot;&gt;
                      &lt;option value=&quot;Year 7&quot;&gt;Year 7&lt;/option&gt;
                      &lt;option value=&quot;Year 8&quot;&gt;Year 8&lt;/option&gt;
                      &lt;option value=&quot;Year 9&quot;&gt;Year 9&lt;/option&gt;
                      &lt;option value=&quot;Year 10&quot;&gt;Year 10&lt;/option&gt;
                      &lt;option value=&quot;Year 11&quot;&gt;Year 11&lt;/option&gt;
                      &lt;option value=&quot;Year 12&quot;&gt;Year 12&lt;/option&gt;
                      &lt;option value=&quot;Year 13&quot;&gt;Year 13&lt;/option&gt;
                      &lt;option value=&quot;GCSE Retake&quot;&gt;GCSE Retake&lt;/option&gt;
                  &lt;/select&gt;
                  &lt;button onClick={this.props.dec} name=&quot;remove&quot;&gt;- Remove Child&lt;/button&gt;&lt;br /&gt;
              &lt;/div&gt;
          )
      }
  }
  </code></pre>
  <p>UPDATE:</p>
  <p>So I did some reading and found a post looking to do the same thing and the Director of Support for Netlify saying it isn't possible yet unless you predefine all of the form fields beforehand (for each of the mapped components). Has anybody found a workaround for this?</p>
  <p><a href="https://community.netlify.com/t/dynamic-input-of-fields/5825" rel="nofollow noreferrer">Netlify Post</a></p>