6.3)
* each option can be individually updated with $form->setOptions();
*/
protected $bs3_options = array(
'ajax' => false,
'deferScripts' => true,
'formInlineClass' => 'form-inline',
'formHorizontalClass' => 'form-horizontal',
'formVerticalClass' => '',
'elementsWrapper' => '
';
} else {
$element .= '
';
}
}
$element .= $this->getHtmlElementContent($btnGroupName, 'before');
if ($btn_alone === true) {
if (isset($this->input_wrapper[$btn_name])) {
$element .= $this->defineWrapper($this->input_wrapper[$btn_name], 'start'); // input-group-btn
}
}
for ($i=0; $i < count($this->btn[$btnGroupName]['type']); $i++) {
$btn_type = $this->btn[$btnGroupName]['type'][$i];
$btn_name = $this->btn[$btnGroupName]['name'][$i];
$btn_value = $this->btn[$btnGroupName]['value'][$i];
$btn_text = $this->btn[$btnGroupName]['text'][$i];
$btn_attr = $this->btn[$btnGroupName]['attr'][$i];
$btn_attr = $this->getAttributes($btn_attr); // returns linearised attributes (with ID)
$btn_value = $this->getValue($btn_name, $btn_value);
$element .= '';
}
if (isset($this->input_wrapper[$btn_name])) {
$element .= $this->getError($btn_name, true);
$element .= $this->defineWrapper($this->input_wrapper[$btn_name], 'end'); // end input-group-btn
}
$element .= $this->getHtmlElementContent($btnGroupName, 'after');
if (!empty($this->options['btnGroupClass']) && $btn_alone === false) {
$element .= '
';
}
$end_col .= $this->getElementCol('end', 'button', $label);
$end_wrapper .= $this->setInputGroup($btn_name, 'end', 'buttonWrapper');
$this->html .= $this->outputElement($start_wrapper, $end_wrapper, $start_label, $end_label, $start_col, $end_col, $element, false);
return $this;
}
/**
* Starts a fieldset tag.
* @param string $legend (Optional) Legend of the fieldset.
* @param string $fieldset_attr (Optional) Fieldset attributes.
* @param string $legend_attr (Optional) Legend attributes.
* @return $this
*/
public function startFieldset($legend = '', $fieldset_attr = '', $legend_attr = '')
{
if (!empty($fieldset_attr)) {
$fieldset_attr = ' ' . $this->getAttributes($fieldset_attr);
}
if (!empty($legend_attr)) {
$legend_attr = ' ' . $this->getAttributes($legend_attr);
}
$this->html .= '
';
return $this;
}
/**
* Adds a Google Invisible Recaptcha field
* @param [string] $sitekey Google recaptcha key
* @return $this
*/
public function addInvisibleRecaptcha($sitekey)
{
$callback_function = 'recaptchaCb' . substr(str_shuffle(MD5(microtime())), 0, 6);
$this->recaptcha_js_callback = '';
$this->addPlugin('invisible-recaptcha', '#' . $this->form_ID, 'default', array('%sitekey%' => $sitekey, '%callback_function%' => $callback_function));
if ($this->has_recaptcha_error == true) {
$this->addHtml('
' . $this->recaptcha_error_text . '
');
}
return $this;
}
/**
* Adds a Google Invisible Recaptcha field
* @param [string] $sitekey Google recaptcha key
* @return $this
*/
public function addRecaptchaV3($sitekey, $action = 'default', $response_fieldname = 'g-recaptcha-response', $xml_config = 'default')
{
$action = str_replace('-', '_', $action);
if (!preg_match('`^[a-zA-Z_0-9]+$`', $action)) {
$this->buildErrorMsg('Recaptcha V3 Action contains invalid characters. Allowed characters: lowercase, uppercase, underscore');
} else {
$this->addInput('hidden', $response_fieldname);
$this->addPlugin('recaptcha-v3', '#' . $this->form_ID, $xml_config, array('%sitekey%' => $sitekey, '%action%' => $action, '%response_fieldname%' => $response_fieldname));
if ($this->has_recaptcha_error == true) {
$this->addHtml('
' . $this->recaptcha_error_text . '
');
}
}
return $this;
}
/**
* Adds a Google recaptcha field
* @param [string] $sitekey Google recaptcha key
* @param [boolean] $center Center recaptcha (false|true)
* @return $this
*/
public function addRecaptchaV2($sitekey, $recaptcha_id = 'recaptcha', $center = false)
{
$start_wrapper = $this->setInputGroup('', 'start', 'elementsWrapper');
$start_col = $this->getElementCol('start', 'recaptcha');
$end_col = $this->getElementCol('end', 'recaptcha');
$end_wrapper = $this->setInputGroup('', 'end', 'elementsWrapper');
$this->addHtml($start_wrapper);
$this->addHtml($start_col);
$center_css = '';
$center_style = '';
if ($center === true) {
$center_css = ' text-align:center;';
$center_style = ' style="text-align:center;"';
}
$this->addHtml('
');
if ($this->has_recaptcha_error == true) {
$this->addHtml('
' . $this->recaptcha_error_text . '
');
}
$this->addHtml('
');
$this->addHtml($end_col);
$this->addHtml($end_wrapper);
// recaptcha callback must be defined before including Google's recaptcha/api.js
// that's why it's added to the form html output.
$this->recaptcha_js_callback = '';
$this->addPlugin('recaptcha-v2', '#' . $recaptcha_id . '', 'default');
return $this;
}
/**
* for backward compatibility. Recommended function is now addRecaptchav2()
* Adds a Google recaptcha V2 field
* @param [string] $sitekey Google recaptcha key
* @param [boolean] $center Center recaptcha (false|true)
* @return $this
*/
public function addRecaptcha($sitekey, $recaptcha_id = 'recaptcha', $center = false)
{
$this->addRecaptchav2($sitekey, $recaptcha_id, $center);
}
/**
* shortcut to prepend or append any adon to an input
* @param string $input_name the name of target input
* @param string $addon_html addon html code
* @param string $pos before | after
* @return $this
*/
public function addAddon($input_name, $addon_html, $pos)
{
if ($this->framework == 'bs3' || $this->framework == 'bs4' || $this->framework == 'foundation') {
$this->addInputWrapper('
', $input_name);
} elseif ($this->framework == 'material') {
$class = 'addon-' . $pos;
$addon_html = $this->addClass($class, $addon_html);
}
if ($this->framework == 'bs4') {
if ($pos == 'before') {
$input_group_addon_class = 'input-group-prepend';
} else {
$input_group_addon_class = 'input-group-append';
}
$this->addHtml('
' . $addon_html . '
', $input_name, $pos);
} elseif (!empty($this->options['inputGroupAddonClass'])) {
$input_group_addon_class = $this->options['inputGroupAddonClass'];
if ($this->framework == 'bs3') {
if (preg_match('`