with one row per field. Hidden inputs
* and datalist elements are emitted before the table; notices before the card,
* submit button after the fields.
*
* Usage:
* echo RsvFormBuilder::create('settings', $action, 'PATCH', 'Saved.')
* ->heading('Settings')
* ->text('name', 'Name', required: true)
* ->email('email', 'Email')
* ->submit('Save');
*/
class RsvFormBuilder
{
private string $form_id;
/** Where the form submits, and how RsvAdminForm should send it. */
private string $action;
private string $rest_method;
private string $success_msg;
/** Optional heading shown inside the card. */
private string $heading = '';
/** @var string[] Rendered before the table (hidden inputs, datalists). */
private array $before = [];
/** @var string[] WP admin notice banners rendered before the card. */
private array $notices = [];
/** @var string[]
elements inside the table. */
private array $rows = [];
/** @var string[] Rendered after the table (submit button). */
private array $after = [];
private function __construct() {}
/**
* @param string $rest_method Verb sent via data-method (POST, PUT, PATCH…).
* @param string $success_msg Message RsvAdminForm shows on success.
*/
public static function create(
string $id,
string $action,
string $rest_method = 'POST',
string $success_msg = ''
): static {
$builder = new static();
$builder->form_id = $id;
$builder->action = $action;
$builder->rest_method = $rest_method;
$builder->success_msg = $success_msg;
return $builder;
}
/** Heading shown inside the card, above the fields. */
public function heading(string $text): static
{
$this->heading = $text;
return $this;
}
// -------------------------------------------------------------------------
// Input fields — each becomes a
';
return $this;
}
/**
* Groups multiple inputs into a single row with a shared label.
*
* The callable receives an RsvFormGroup instance; inputs added to it
* are laid out as a flex row inside the row's