Conn2Flow
Docs navigation

Reference / Libraries

formulario.php library

The public form processor (validation, anti-bot, CAPTCHA, per-IP limits, storage and e-mail), injecting forms into the page and validating admin panel forms.

Path in the Gestor bibliotecas/formulario.php

Three roles:

  1. Public forms (those of the forms module): formulario_controlador() prepares the page and formulario_processador() receives the submission.

  2. Admin panel form validation: formulario_validacao() builds the browser-side rules, used by interface.php and several modules.

  3. Forms' own CAPTCHA and per-IP limits.

On the page: formulario_controlador()

formulario_controlador(['formId' => 'contact']);            // or ['contact', 'newsletter']

It builds each form's configuration (formulario_montar_js_vars(): fields, rules, texts, CAPTCHA) and exposes it in gestor.form[<id>]; with a single id, also in the old flat format. It includes the library JS once. In ~1% of calls, it cleans expired accesses (formulario_acessos_limpeza()).

On submission: formulario_processador()

It answers over AJAX ($_GESTOR['ajax-json']) to the form POST (_formId and the fields), in this order:

  1. Honeypot: a filled honeypot field = bot.

  2. Submission age: the browser-sent timestamp must be at most 2 days old.

  3. Definition of the form in the forms table (current language): name, fields_schema and status (inactive = rejected).

  4. Per-IP limit (formulario_acesso_verificar()), per form: bloqueado rejects.

  5. CAPTCHA (seguranca.php): with Turnstile, always; with reCAPTCHA, from the antispam status on or when the schema has force_recaptcha: true; a failed v3 can fall back to v2 (status: require_v2) if v2 is active.

  6. Schema fields: required ones, valid e-mail and URL, minimum length (3 for text, or the one in Options) and maximum (254 for text/email/password/url, 10000 for textarea, 1000 for the rest), number and date ranges from Options (formulario_parse_limits(): min:, max:, step:).

  7. Stores into forms_submissions (submission name from the schema's field_name, the name field or the first text field). password fields are stored empty.

  8. Counts the submission in the per-IP limit (formulario_acesso_cadastrar()).

  9. Notification e-mail: recipients from the schema's email.recipients (separated by ;, accepting Name <email>), or the .env sender; subject, reply-to (the first valid e-mail of the submission) and the form's message component, falling back to forms-prepared-email (formulario_email_*). Before sending, the formulario.email.mensagem filter (hooks) can change the HTML, and site images become embedded attachments (formulario_email_processar_imagens()).

  10. Stores email_status in the submission and returns success with the redirect (/sucesso/ by default).

Limits from the .env: FORMULARIOS_MAXIMO_CADASTROS and FORMULARIOS_MAXIMO_CADASTROS_SIMPLES (overridable by access_max and access_max_simple in the schema), plus the block and cleanup times (formularios-* in global variables). The logic is the same as the attempt control, in formulario_acesso_verificar(), formulario_acesso_cadastrar() and formulario_acesso_falha().

Admin panel validation: formulario_validacao()

formulario_validacao([
    'formId' => 'form-usuarios',
    'validacao' => [
        ['regra' => 'email', 'campo' => 'email', 'label' => 'E-mail'],
        ['regra' => 'texto-obrigatorio', 'campo' => 'nome', 'label' => 'Name'],
    ],
]);

It builds the Fomantic UI rules for the form, with error texts from the variables. Rules: nao-vazio, texto-obrigatorio, texto-obrigatorio-verificar-campo, selecao-obrigatorio, email, email-comparacao, email-comparacao-verificar-campo, senha, senha-comparacao and manual. formulario_validacao_campos_obrigatorios() does the server-side check and, if something is missing, shows the alert and redirects. formulario_incluir_js() includes the validation script.

Legacy reCAPTCHA

formulario_google_recaptcha() and formulario_google_recaptcha_tipo() return the public key and the type (v2/v3) when reCAPTCHA is active. They have no callers in the core: the current CAPTCHA goes through gestor_captcha_validar().

Internal helpers: formulario_email_cabecalho_normalizar(), formulario_form_action_resolver() (an empty action points to the canonical processor), formulario_email_reply_to_resolver(), formulario_email_reply_to_nome_resolver(), formulario_email_assunto_resolver(), formulario_email_mensagem_resolver(), formulario_email_template_processar().

Functions

Generated from gestor/bibliotecas/formulario.php · 21 functions

21 of 21

formulario_parse_limits

view source · line 28 ↗
formulario_parse_limits(mixed $options): array

Extrai diretivas de limite (min/max/step) das linhas do campo "Opções" de um campo de formulário. Aceita string multilinha ou array de linhas no formato min:X, max:Y, step:Z.

Parameters

$optionsmixed
Conteúdo do campo options.

Returns

array
['min'=>string|null, 'max'=>string|null, 'step'=>string|null]

formulario_email_processar_imagens

view source · line 229 ↗
formulario_email_processar_imagens(string $html): array

Processa imagens locais no HTML do email para embedding automático.

Parameters

$htmlstring
HTML do email a ser processado.

Returns

array
Array com HTML processado e array de imagens para embedding.

formulario_montar_js_vars

view source · line 303 ↗
formulario_montar_js_vars(array $formIds, string|null $formAjaxOpcao = null): array

Monta as variáveis JS (gestor.form[id]) de um ou mais formulários.

Parameters

$formIdsarray
Lista de IDs de formulário.
$formAjaxOpcaostring|null
Opção AJAX (opcional).

Returns

array
Configurações indexadas por ID do formulário.

formulario_acesso_verificar

view source · line 1123 ↗
formulario_acesso_verificar(array|false $params = false): array

Verifica estado de acesso para formulários com proteção anti-spam.

Parameters

$paramsarray|false
Parâmetros (tipo obrigatório).

Returns

array
Estado do acesso com 'permitido' e 'status'.

formulario_acesso_cadastrar

view source · line 1191 ↗
formulario_acesso_cadastrar(array|false $params = false): void

Cadastra tentativa de acesso para formulários com controle anti-spam.

Parameters

$paramsarray|false
Parâmetros (tipo obrigatório, antispam opcional, maximoCadastros opcional, maximoCadastrosSimples opcional).

Returns

void

formulario_acesso_falha

view source · line 1346 ↗
formulario_acesso_falha(array|false $params = false): void

Registra falha de acesso para formulários.

Parameters

$paramsarray|false
Parâmetros (tipo obrigatório, maximoCadastros opcional, maximoCadastrosSimples opcional).

Returns

void

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting