本文整理匯總了PHP中FormUI::control_id方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormUI::control_id方法的具體用法?PHP FormUI::control_id怎麽用?PHP FormUI::control_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FormUI
的用法示例。
在下文中一共展示了FormUI::control_id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: from_html
/**
* Create a form with controls from HTML
* @param string $name Name of the form
* @param string $html HTML of a form
* @return FormUI The form created from the supplied HTML
*/
public static function from_html($name, $html)
{
$dom = new HTMLDoc($html);
$form = new FormUI($name);
// Set the form to render using the output of the HTMLDoc
$form->settings['norender'] = true;
$form->settings['content'] = function () use($dom) {
return $dom->get();
};
$form->dom = $dom;
// This form's id is an MD5 hash of the original HTML
$form->settings['control_id'] = md5($html);
// Add the _form_id and WSSE elements to the form
// Note that these additional fields must be XML-safe, or they won't be added
$dom->find_one('form')->append_html(Utils::setup_wsse());
$dom->find_one('form')->append_html('<input type="hidden" name="_form_id" value="' . $form->control_id() . '" />');
// Add synthetic controls for any found inputs
foreach ($dom->find('input') as $input) {
/** @var FormControl $control */
$form->append($control = FormControlDom::create($input->name)->set_node($input));
if ($input->data_validators) {
foreach (explode(' ', $input->data_validators) as $validator) {
$control->add_validator($validator);
}
}
}
foreach ($dom->find('textarea') as $input) {
/** @var FormControl $control */
$form->append($control = FormControlDom::create($input->name)->set_node($input));
if (!empty($input->data_validators)) {
foreach (explode(' ', $input->data_validators) as $validator) {
$control->add_validator($validator);
}
}
}
return $form;
}