<?php
$form = new Barebone\Form();
$form->is_ajax();
if($form->is_send() && !$form->is_valid()){
$this->ShowZebraDialog('Error', 'Your form has an invalid seckey', 'error');
}
if($form->is_send() && $form->is_valid()){
$this->ShowModal('You send this data:', '<pre>'.print_r($_POST, true).'</pre>');
}
$form->secure_form();
$form->addInput('text', 'ID', 'id', ['disabled' => 'disabled', 'class' => 'form-control']);
$form->addInput('text', 'Name', 'name', ['class' => 'form-control']);
$form->addInput('text', 'State', 'state', ['class' => 'form-control']);
$options = [];
$options[0] = 'No choice made';
$options[1] = '1 choice made';
$options[2] = '2 choice made';
$form->addSelect(
label: 'Choices',
name:'choices',
attributes: ['class' => 'form-control'],
options: $options
);
$form->addButton('submit', 'Save', ['class'=>'btn btn-success', 'style'=>'margin-top: 20px;margin-left: 15px;']);
$this->view->form = $form;
<form role="form" method="POST" action="" onsubmit="$.php( $(this).attr('action'), $(this).serialize() ); return false;">
<input type="hidden" name="CSFR" value="6aa1176aee0ac" />
<div class="form-group">
<label class="col-sm-4" for="id">
ID</label>
<div class="col-sm-8">
<input type="text" name="id" id="id" disabled="disabled" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4" for="name">
Name</label>
<div class="col-sm-8">
<input type="text" name="name" id="name" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4" for="state">
State</label>
<div class="col-sm-8">
<input type="text" name="state" id="state" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="col-sm-4">
Choices</label>
<div class="col-sm-8">
<select name="choices" class="form-control">
<option value="No choice made">
No choice made</option>
<option value="1 choice made">
1 choice made</option>
<option value="2 choice made">
2 choice made</option>
</select>
</div>
</div>
<input type="submit" value="Save" class="btn btn-success" style="margin-top: 20px;margin-left: 15px;" />
</form>
1. Form Creation and Configuration:
$form = new Barebone\Form();: Creates a new form object using a framework or library called
"Barebone."$form->is_ajax();: Sets a flag indicating that the form is designed for AJAX submission
(asynchronous JavaScript submission).2. Form Validation and Security:
if($form->is_send() && !$form->is_valid()){ ... }: Checks if the form has been
submitted and if it's valid. If not valid, displays an error dialog using a custom function ShowZebraDialog.if($form->is_send() && $form->is_valid()){ ... }: If the form is submitted and
valid, displays a modal dialog using a custom function ShowModal, showing the submitted data.$form->secure_form();: Activates a security mechanism within the Barebone framework, likely
a hidden field or token for cross-site request forgery (CSRF) protection.3. Form Input Fields:
$form->addInput('text', 'ID', 'id', ['disabled' => 'disabled']);: Adds a text input
field with the label "ID", name "id", and disabled state (uneditable).$form->addInput('text', 'Name', 'name', []);: Adds a text input field labeled "Name" with
the name "name."$form->addInput('text', 'State', 'state', []);: Adds a text input field labeled "State"
with the name "state."$form->addSelect(...);: Adds a select dropdown with:
4. Submit Button:
$form->addButton('submit', 'Save');: Adds a submit button labeled "Save."5. Pass Form to View:
$this->view->form = $form;: Assigns the created form object to a variable named "form"
in a view object, likely for rendering the form in a template.Key Points: