Markup for the AI (syntax)

For developersVersion 1.0.0Last updated:

A form is a normal <form> with data-bos-form. The fields are <input>, <select> and <textarea> with a name attribute.

<form class="contact-form" data-bos-form="contacto" data-bos-name="Formulario de contacto"
      data-bos-success="¡Gracias! Te responderemos en menos de 24 horas."
      data-bos-subject="Nuevo contacto de {nombre}">

  <p class="field">
    <label for="contacto-nombre" data-bos-edit="text" data-bos-id="form-name-label" data-bos-name="Etiqueta: nombre">Nombre</label>
    <input id="contacto-nombre" type="text" name="nombre" autocomplete="name" placeholder="Tu nombre" required maxlength="120">
  </p>

  <p class="field">
    <label for="contacto-email" data-bos-edit="text" data-bos-id="form-email-label" data-bos-name="Etiqueta: email">Email</label>
    <input id="contacto-email" type="email" name="email" autocomplete="email" required>
  </p>

  <p class="field">
    <label for="contacto-servicio" data-bos-edit="text" data-bos-id="form-service-label" data-bos-name="Etiqueta: servicio">¿Qué necesitas?</label>
    <select id="contacto-servicio" name="servicio">
      <option value="">Elige una opción</option>
      <option value="web">Diseño web</option>
      <option value="seo">SEO</option>
    </select>
  </p>

  <p class="field">
    <label for="contacto-mensaje" data-bos-edit="text" data-bos-id="form-message-label" data-bos-name="Etiqueta: mensaje">Mensaje</label>
    <textarea id="contacto-mensaje" name="mensaje" rows="5" required maxlength="5000"></textarea>
  </p>

  <p class="consent">
    <label><input type="checkbox" name="privacidad" value="1" required data-bos-consent>
      <span data-bos-edit="text" data-bos-id="form-consent" data-bos-name="Texto de consentimiento">Acepto que uséis mis datos para responder a mi mensaje.</span></label>
  </p>

  <button type="submit" class="btn"><span data-bos-edit="text" data-bos-id="form-submit" data-bos-name="Botón enviar">Enviar mensaje</span></button>
  <div data-bos-form-message></div>
</form>

<form> attributes

AttributeUse
data-bos-formRequired. Stable form id (contacto, presupuesto…). Unique within the section. Don’t change it once in production: settings and messages are saved with it.
data-bos-nameName the administrator sees (list, emails, messages).
data-bos-successSuccess message in the HTML’s language. It can be changed per language in the panel.
data-bos-redirectOptional. Page to go to after submitting: a URL or gracias.html (a package page; its version in the visitor’s language is used).
data-bos-subjectOptional. Subject of the email notification. Supports {campo}, {form}, {site}, {page} and {lang}.
data-bos-reply-toOptional. name of the email field to reply to. Defaults to the first type="email".
data-bos-error-messageOptional. General message when there are errors. Defaults to “Check the highlighted fields.”

Field attributes

AttributeUse
nameRequired. Letters, numbers, - and _, starting with a letter (nombre, e-mail, servicios[]). Don’t use dots or spaces. Names that start with _bos are reserved.
requiredRequired field (also validated on the server).
typetext, email, tel, url, number, date, textarea, select, checkbox, radio, file, hidden… email, tel, url, number and date are validated on the server.
maxlength, minlength, min, max, patternRespected on the server. Without maxlength, the limit is 1000 characters (10,000 in textarea).
data-bos-consentConsent checkbox (GDPR). The accepted text and the date are saved.
data-bos-labelOptional. Label for the email and the panel if the field has no <label>.
acceptOn type="file", limits the extensions (.pdf,.png or image/*).
data-bos-errorThe field’s own error message. It replaces the validation ones (also in package forms).
data-bos-requiredRequired checkbox group: checking one is enough. With required, the browser would force you to check them all.
  • Labels: taken from <label for="id">, from the <label> that wraps the field, from aria-label or from the placeholder, in this order. In radio and checkbox groups (name="servicios[]"), from the <fieldset>‘s <legend>.
  • Message: the result is shown in the element with data-bos-form-message. If there isn’t one, one is added at the end of the form.
  • Multiple values: checkboxes with name="x[]" and <select multiple> save all the chosen options.

Editable and translatable texts

  • Labels, the consent text and the button are normal BuilderOS fields: mark them with data-bos-edit="text" (or richtext if they contain a link), with data-bos-id and data-bos-name. They’re edited in the visual editor and translated in i18n/<idioma>.json like any other field.
  • In the button, put the text in a <span data-bos-edit="text"> inside the <button> (editing text directly on a <button> causes problems in some browsers).
  • What isn’t an element’s content (placeholders, <option> texts, success message and redirect) is translated in the reserved key _forms of i18n/<idioma>.json, by form id:
{
  "contact": {
    "form-name-label": "Name",
    "form-submit": "Send message"
  },
  "_forms": {
    "contacto": {
      "success": "Thank you! We will get back to you within 24 hours.",
      "redirect": "thanks.html",
      "placeholders": { "nombre": "Your name", "mensaje": "Tell us about your project" },
      "options": { "servicio": { "": "Choose an option", "web": "Web design", "seo": "SEO" } }
    }
  }
}
  • The validation messages (“This field is required”…) come out in the page’s language: Spanish, English, Portuguese, French, German and Italian are included; the rest use English. You can change them with the builder_os_forms_messages filter.

❌ What NOT to do

  • Don’t set action, method or your own submission JavaScript: BuilderOS replaces them.
  • Don’t put the form inside a text, richtext or shortcode field (they replace all their content).
  • Don’t use data-bos-edit on <input>, <select> or <textarea>: the editable fields are the labels and the button.
  • Don’t use data-bos-form on anything that isn’t a <form>.