Search code examples
wordpresscontact-form-7

Contact Form 7 labels missing in REST


I have a form fetched using the endpoint e.g.: /wp-json/contact-form-7/v1/contact-forms/161

In the admin, the template is defined as follows:

<label> Nom
  [text* your-name] </label>

<label> Adresse e-mail
  [email* your-email] </label>

<label> Message
  [textarea* your-message] </label>

[submit "Envoyer"]

The problem is that the labels are missing, or rather, they are only available within the content property.

The labels property is filled for the submit button, but it makes no sense to me why they make it available on the submit button. Semantically, I would have thought that is its value.

Is there some configuration I am missing to make this REST response more useful, or am I going to have to parse the content?

{
  id: 161,
  slug: "contact-form",
  title: "Formulaire de contact",
  locale: "en_US",
  properties: {
    form: {
      content: "<label> Nom\n  [text* your-name] </label>\n\n<label> Adresse e-mail\n  [email* your-email] </label>\n\n<label> Message\n  [textarea* your-message] </label>\n\n[submit \"Envoyer\"]",
      fields: [
        {
          type: "text*",
          basetype: "text",
          name: "your-name",
          options: [],
          raw_values: [],
          labels: [],
          values: [],
          pipes: [],
          content: ""
        },
        {
          type: "email*",
          basetype: "email",
          name: "your-email",
          options: [],
          raw_values: [],
          labels: [],
          values: [],
          pipes: [],
          content: ""
        },
        {
          type: "textarea*",
          basetype: "textarea",
          name: "your-message",
          options: [],
          raw_values: [],
          labels: [],
          values: [],
          pipes: [],
          content: ""
        },
        {
          type: "submit",
          basetype: "submit",
          name: "",
          options: [],
          raw_values: [
            "Envoyer"
          ],
          labels: [
            "Envoyer"
          ],
          values: [
            "Envoyer"
          ],
          pipes: [
            [
              "Envoyer",
              "Envoyer"
            ]
          ],
          content: ""
        }
      ]
    },
    mail: {},
    mail_2: {},
    messages: {},
    additional_settings: {}
  }
}

Solution

  • The labels don't seem to be what you think they are. It seems to be representing the default value according to the Form tag generator. With this in mind, I will simply use the default value to represent the label when consuming CF7 from an API.

    [text* your-name "Nom"]
    [email* your-email "Adresse Email"]
    [textarea* your-message "Message"]
    [submit "Envoyer"]