Form fields with the same label are being overwritten on email notifications

  • Site: contigoerp

Context
I have a form with some fields with the same label. It submits well and Netlify UI shows all the fields even the repeated ones. The problem is that in the email notification it’s not sending all the fields, the ones that are repeated are beign overwritten:


Left side is netlify UI and right side is email notification.

I tried to fix it changing to a stateful react form, but even when I’m sending an object with different properties it is still taking the label values as propertie names so in the email notification it keeps overwritting.

CODE
function ReferredForm() {
const [formData, setFormData] = useState({})

  const handleChange = ({ target }) => {
    setFormData({ ...formData, [target.name]: target.value })
  }

  const encode = data => {
    return Object.keys(data)
      .map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
      .join("&")
  }
  const handleSubmit = e => {
    fetch("/", {
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      body: encode({ "form-name": "contigoerp-referido", ...formData }),
    })
      .then(() => navigate("/gracias"))
      .catch(error => alert(error))

    e.preventDefault()
  }

  const referrerData = (
    <>
      <label htmlFor="referrerName">
        Nombre completo *
        <input
          id="referrerName"
          name="referrerName"
          type="text"
          aria-label="referrerName"
          placeholder="Nombre"
          value={formData.referrerName || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referrerId">
        Cédula *
        <input
          id="referrerId"
          name="referrerId"
          type="number"
          aria-label="referrerId"
          placeholder="Cédula"
          value={formData.referrerId || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referrerPhone">
        Celular *
        <input
          id="referrerPhone"
          name="referrerPhone"
          type="tel"
          aria-label="referrerPhone"
          placeholder="Celular"
          pattern="[0-9]{7,10}"
          value={formData.referrerPhone || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referrerEmail">
        Correo electrónico *
        <input
          id="referrerEmail"
          name="referrerEmail"
          type="email"
          aria-label="referrerEmail"
          placeholder="Correo electrónico"
          value={formData.referrerEmail || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referrerAccount">
        Nro de cuenta
        <input
          id="referrerAccount"
          name="referrerAccount"
          type="number"
          aria-label="referrerAccount"
          placeholder="Nro de cuenta"
          value={formData.referrerAccount || ""}
          onChange={e => handleChange(e)}
        />
      </label>
      <label htmlFor="referrerAccountType">
        Tipo de cuenta
        <input
          id="referrerAccountType"
          name="referrerAccountType"
          type="text"
          aria-label="referrerAccountType"
          placeholder="Ahorros | Corriente"
          value={formData.referrerAccountType || ""}
          onChange={e => handleChange(e)}
        />
      </label>
      <label htmlFor="referrerBank">
        Banco
        <input
          id="referrerBank"
          name="referrerBank"
          type="text"
          aria-label="referrerBank"
          placeholder="Banco"
          value={formData.referrerBank || ""}
          onChange={e => handleChange(e)}
        />
      </label>
      <label htmlFor="referrerPosition">
        Ocupación
        <input
          id="referrerPosition"
          name="referrerPosition"
          type="text"
          aria-label="referrerPosition"
          placeholder="Ocupación"
          value={formData.referrerPosition || ""}
          onChange={e => handleChange(e)}
        />
      </label>
    </>
  )

  const referredData = (
    <>
      <label htmlFor="referredName">
        Nombre completo *
        <input
          id="referredName"
          name="referredName"
          type="text"
          aria-label="referredName"
          placeholder="Nombre"
          value={formData.referredName || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referredPhone">
        Celular *
        <input
          id="referredPhone"
          name="referredPhone"
          type="tel"
          aria-label="referredPhone"
          placeholder="Celular"
          pattern="[0-9]{7,10}"
          value={formData.referredPhone || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>
      <label htmlFor="referredEmail">
        Correo electrónico *
        <input
          id="referredEmail"
          name="referredEmail"
          type="email"
          aria-label="referredEmail"
          placeholder="Correo electrónico"
          value={formData.referredEmail || ""}
          onChange={e => handleChange(e)}
          required
        />
      </label>

      <label htmlFor="referredCompanyName">
        Nombre de la empresa
        <input
          id="referredCompanyName"
          name="referredCompanyName"
          type="text"
          aria-label="referredCompanyName"
          placeholder="Empresa"
          value={formData.referredCompanyName || ""}
          onChange={e => handleChange(e)}
        />
      </label>
    </>
  )

  return (
    <Form id="referido" onSubmit={handleSubmit}>
      <input type="hidden" aria-label="antispam" name="bot-field" />
      <input
        type="hidden"
        aria-label="form-name"
        name="contigoerp-referido"
        value="Referido"
      />
      <h1 style={{ marginTop: "1em" }}>
        Refiere a alguien que esté interesado en ContigoERP
      </h1>
      <fieldset style={{ marginBottom: "3em" }}>
        <h2>Datos del referente</h2>
        <section className="fields">{referrerData}</section>
      </fieldset>
      <fieldset>
        <h2>Datos del referido</h2>
        <section className="fields">{referredData}</section>
      </fieldset>
      <section className="actions">
        <Button type="submit" mb="0">
          Enviar
        </Button>
      </section>
    </Form>
  )
}

Thanks in advance for your help.

Hi @jmedina2930,

This is a known issue and I’ve added this post to the issue tracking it. We’ll update once we have a fix out for it. Thank you for reporting the issue.

Hi @Dennis , this issue is 2 years old and still exists. Is there a work-around for this?

This is what the form looks like, and the code:

site can be accessed here: Los Pinos Hardware Co

              <div class="form-row">
                <div class="form-group col-md-12 d-flex align-items-center">
                  <span class="mr-2" style="line-height: 18px;">Are you a US citizen?</span>
                  <div class="custom-control custom-radio  ml-1 mr-3">
                    <input class="custom-control-input" type="radio" required="true" name="citizen" id="citizen-yes"
                      value="citizen-yes" />
                    <label class="custom-control-label" for="citizen-yes">Yes</label>
                  </div>
                  <div class="custom-control custom-radio ">
                    <input class="custom-control-input" type="radio" required="true" name="citizen" id="citizen-no"
                      value="citizen-no" />
                    <label class="custom-control-label" for="citizen-no">No</label>
                  </div>
                </div>
              </div>

              <div class="form-row">
                <div class="form-group col-md-12 d-flex align-items-center">
                  <span class="mr-2" style="line-height: 18px;">Have you ever been convicted of a felony?</span>
                  <div class="custom-control custom-radio ml-1 mr-3">
                    <input class="custom-control-input" type="radio" required="true" name="felony" id="felony-yes"
                      value="felony-yes">
                    <label class="custom-control-label" for="felony-yes">Yes</label>
                  </div>
                  <div class="custom-control custom-radio">
                    <input class="custom-control-input" type="radio" required="true" name="felony" id="felony-no"
                      value="felony-no">
                    <label class="custom-control-label" for="felony-no">No</label>
                  </div>
                </div>
              </div>

              <div class="form-row">
                <div class="form-group col-md-12 d-flex align-items-center">
                  <span class="mr-2" style="line-height: 18px;">
                    If selected for employment are you willing to submit to a pre-employment drug
                    screening test?
                  </span>
                  <div class="custom-control custom-radio ml-1 mr-3">
                    <input class="custom-control-input" type="radio" required="true" name="drug-screening"
                      id="drug-screening-yes" value="drug-screening-yes">
                    <label class="custom-control-label" for="drug-screening-yes">Yes</label>
                  </div>
                  <div class="custom-control custom-radio">
                    <input class="custom-control-input" type="radio" required="true" name="drug-screening"
                      id="drug-screening-no" value="drug-screening-no">
                    <label class="custom-control-label" for="drug-screening-no">No</label>
                  </div>
                </div>
              </div>

 <!-- other code -->

              <div class="form-row">
                <div class="form-group col-md-12 d-flex align-items-center">
                  <span class="mr-2" style="line-height: 18px;">
                    If selected for employment are you willing to submit to a pre-employment drug
                    screening test?
                  </span>
                  <div class="custom-control custom-radio ml-1 mr-3">
                    <input class="custom-control-input" type="radio" required="true" name="drug-screening"
                      id="drug-screening-yes" value="drug-screening-yes">
                    <label class="custom-control-label" for="drug-screening-yes">Yes</label>
                  </div>
                  <div class="custom-control custom-radio">
                    <input class="custom-control-input" type="radio" required="true" name="drug-screening"
                      id="drug-screening-no" value="drug-screening-no">
                    <label class="custom-control-label" for="drug-screening-no">No</label>
                  </div>
                </div>
              </div>

There’s no current known workaround for this. You’d most likely have to name everything uniquely.