myjw3b/php-bootstrap-form-class

为 Bootstrap 4 & 5 提供一些表单构建辅助工具

安装: 28

依赖者: 0

建议者: 0

安全: 0

星星: 0

关注者: 0

分支: 1

类型:项目

1.1.0 2024-07-18 21:57 UTC

This package is auto-updated.

Last update: 2024-09-24 01:26:44 UTC


README

使用包装器快速简单地构建所有表单的 HTML,只需几个变量即可构建。

我们可以向每个元素添加浮动标签、输入组或使用行/列组合。

免责声明

在浮动标签类的一些最近更改后,我没有使用输入组。

函数

95% 的函数将返回 $this 以实现链式调用。

__construct()

新 form() 构造函数的默认选项。

$options = [
			'id'            => '',  // id of the form element
			'url'           => '/ajax', // the forms action value
			'method'        => 'post', // get or post
			'form_classes'  => 'mf-forms', // classes to be added to the form tag
			'input_classes' => 'form-control', // classes to be added to the input elements
			'row_classes'   => 'mb-3', // classes to be added to each container row
			'form_attr'     => [], // additional form attributes
			'ensure_row'    => true // ensure the rows are closed before each new element
		]

->set_opts($key, $value)

你可以覆盖由构造函数最初设置的一些选项 返回 $this 以实现链式调用。

->get_opts($key)

返回选项键的值,因此不能链式调用。

->add_html($html, $close_row=false)

在表单内添加额外的 HTML

->floating($additional_classes='')

开始一个浮动标签块

->new_row($row_class='')

->set_name($input_name_and_id_value='')

你可以在名称值中放置 ['key'] 以便与单选按钮和复选框一起使用。

元素

浮动标签将自动添加到输入标签之后

/**
	 *  @param (str) type = 'input', 'button', 'textarea', 'select', 'file', 'day', 'time':		
	 * 	@param (str) value of input
	 *  @param (ary) attr for the input
	 *  @param (ary) b4_element - input
	 *  @param (ary) after_element - input
	 * 
	 * return $this
	 */

示例

    $new_form = new form([
		'id' => 'register-form',
		'url' => '/ajax/register-form',
		'form_classes' => 'col-lg-6 mx-auto'
	]);
	$inc = $new_form
		->floating()
			->set_name('uUsername')
			->element('input', '', ['placeholder' => 'My Crazy Name', 'required' => 'required'])
		->end_floating()
		->floating()
			->set_name('uEmail')
			->element('input', '', ['type' => 'email', 'placeholder' => 'Real Email', 'required' => 'required'])
		->end_floating()
		->floating()
			->set_name('uPass')
			->element('input', '', ['type' => 'password', 'placeholder' => 'Password', 'required' => 'required'])
		->end_floating()
		->floating()
			->set_name('uPassCon')
			->element('input', '', ['type' => 'password', 'placeholder' => 'Confirm Password', 'required' => 'required'])
		->end_floating()
		->actions();

更多示例即将推出