Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created December 6, 2012 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save violetyk/4224127 to your computer and use it in GitHub Desktop.
Save violetyk/4224127 to your computer and use it in GitHub Desktop.
[cakephp]動的フォーム生成
<?= $form->create() ?>
<?= preg_replace_callback(
'/\{(?<type>text|checkbox):(?<name>[^\|}]+){1}(?:(?:\|validate:(?<validate>[\w,]+))?(?:\|class:(?<class>[\w,]+))?)*\}/'
function ($match) use ($form) {
$option = array('type' => $match['type']);
if (isset($match['validate'])) {
// validation
}
if (isset($match['class'])) {
$option['class'] = str_replace(',', ' ', $match['class']);
}
return $form->input($match['name'], $option);
}, $html); ?>
<?= $form->submit() ?>
<?= $form->end() ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment