Form Component — sgcHTML | eSeGeCe

Form

TsgcHTMLComponent_Form — a data-driven form builder that renders Bootstrap 5 forms with text, select, checkbox, radio, file, date and range fields, validation, vertical/horizontal/inline layouts and AI form generation, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_Form

A form component that builds a Bootstrap <form> from a Fields collection. Add fields (or bind a dataset), pick a layout, then read the HTML property.

Component class

TsgcHTMLComponent_Form

Renders

Bootstrap 5 <form> markup

Languages

Delphi, C++ Builder, .NET

Create it, add fields, render it

Set Action, Method and Layout, add one or more Fields, then read HTML (or drop it into a TsgcHTMLTemplate_Bootstrap page).

uses
  sgcHTML_Enums, sgcHTML_Component_Form;

var
  oForm: TsgcHTMLComponent_Form;
  oField: TsgcHTMLFormField;
begin
  oForm := TsgcHTMLComponent_Form.Create(nil);
  try
    oForm.Action := '/contact';
    oForm.Method := fmPost;
    oForm.Layout := flVertical;
    oForm.SubmitText := 'Send';
    oForm.SubmitStyle := bsPrimary;
    oForm.ShowReset := True;

    oField := oForm.Fields.Add;
    oField.FieldType := ftText;
    oField.Name := 'name';
    oField.Label_ := 'Full name';
    oField.Required := True;

    oField := oForm.Fields.Add;
    oField.FieldType := ftEmail;
    oField.Name := 'email';
    oField.Label_ := 'Email';
    oField.Placeholder := 'you@example.com';

    WebModule.Response := oForm.HTML;   // Bootstrap <form> markup
  finally
    oForm.Free;
  end;
end;

// Or build the fields straight from a dataset:
oForm.LoadFromDataSet(qryCustomer);
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Form.hpp

TsgcHTMLComponent_Form *oForm = new TsgcHTMLComponent_Form(NULL);
try
{
  oForm->Action = "/contact";
  oForm->Method = fmPost;
  oForm->Layout = flVertical;
  oForm->SubmitText = "Send";
  oForm->SubmitStyle = bsPrimary;
  oForm->ShowReset = true;

  TsgcHTMLFormField *oField = oForm->Fields->Add();
  oField->FieldType = ftText;
  oField->Name = "name";
  oField->Label_ = "Full name";
  oField->Required = true;

  oField = oForm->Fields->Add();
  oField->FieldType = ftEmail;
  oField->Name = "email";
  oField->Label_ = "Email";
  oField->Placeholder = "you@example.com";

  String html = oForm->HTML;   // Bootstrap <form> markup
}
__finally
{
  delete oForm;
}
using esegece.sgcWebSockets;

var form = new TsgcHTMLComponent_Form();
form.Action = "/contact";
form.Method = TsgcHTMLFormMethod.fmPost;
form.Layout = TsgcHTMLFormLayout.flVertical;
form.SubmitText = "Send";
form.SubmitStyle = TsgcHTMLButtonStyle.bsPrimary;
form.ShowReset = true;

var field = form.Fields.Add();
field.FieldType = TsgcHTMLFieldType.ftText;
field.Name = "name";
field.Label_ = "Full name";
field.Required = true;

field = form.Fields.Add();
field.FieldType = TsgcHTMLFieldType.ftEmail;
field.Name = "email";
field.Label_ = "Email";
field.Placeholder = "you@example.com";

string html = form.HTML;   // Bootstrap <form> markup

Key properties & methods

The members you reach for most often.

Fields

Fields is a collection of TsgcHTMLFormField; call Fields.Add and set FieldType (ftText, ftEmail, ftSelect, ftCheckbox, ftRadio, ftFile, ftDate, ftRange and more), Name, Label_, Value and Required.

Submission

Action and Method (fmGet / fmPost) target the post; FormID identifies the form element.

Layout

Layout picks flVertical, flHorizontal or flInline; LabelColWidth and FieldColWidth size the columns of a horizontal layout.

Buttons

SubmitText, SubmitStyle (a TsgcHTMLButtonStyle), ShowReset and ResetText control the action buttons.

Dataset binding

LoadFromDataSet(aDataSet) generates fields from a query's columns; LoadValuesFromDataSet(aDataSet) refills existing fields with the current row's values.

AI form builder

AIBuildEnabled and AIBuildPlaceholder add a prompt bar; BuildFromAIDescription(aDescription) raises OnAIBuildForm and LoadFieldsFromJSON(aJSON) populates fields from a JSON definition.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.