It is said that the Shenzhen 2011 Universiade is not coming, so I was arrested by the Youth League Committee to serve as a volunteer service station. A small form toolkit is written in the process. The verification function is not implemented by myself. it depends on Kohana_Validate (Kohana V3.0x branch ). However, according to The J2EE disgusting mode, I got a synchronization token to prevent repeated forms from being submitted. This component also sets the abstraction layer. I think the verification code can also be integrated as a token subclass. But now there is no time to get it done. first, share the code and wait for it to be made ~
- Namespace Form;
- Use Volunteer \ Form \ AbstractForm;
- Class NewsPoster extends AbstractForm
- {
- /**
- * Add all preset form elements
- *
- * @ Abstract
- */
- Public function bindAllElement ()
- {
- $ This-> bindToken ('valid _ token ')
- -> AddElement ('news title', 'title ',
- Array (
- 'Not _ empty' => null,
- 'Max _ length' => array (60)
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('thumbnail url ', 'urlname ',
- Array (
- 'Max _ length' => array (50 ),
- 'Regex' => array ('~ ^ [A-zA-Z0-9 \-%] + $ ~ ')
- ),
- Array (
- 'Trim' => null,
- 'Urlencode' => null,
- ))
- -> AddElement ('keyword', 'keyword ',
- Array (
- 'Max _ length' => array (100 ),
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('author & reporter ', 'author ',
- Array (
- 'Max _ length' => array (60 ),
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('news editor', 'editor ',
- Array (
- 'Max _ length' => array (60 ),
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('news source', 'source ',
- Array (
- 'Max _ length' => array (60 ),
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('news category', 'Category ',
- Array (
- 'Not _ empty' => null,
- 'Digit' => null,
- 'Regex' => array ('~ ^ [1-9] \ d * $ ~ ')
- ),
- Array ())
- -> AddElement ('cover image', 'cover _ image ',
- Array (),
- Array (
- 'Trim' => null,
- 'Urlencode' => null,
- ))
- -> AddElement ('containing media information', 'mediatag ',
- Array (
- 'Not _ empty' => null,
- 'Digit' => null,
- 'Regex' => array ('~ ^ [1, 0123] $ ~ ')
- ),
- Array ())
- -> AddElement ('news summary', 'summary ',
- Array (
- 'Max _ length' => array (255 ),
- ),
- Array (
- 'Trim' => null,
- 'Htmlspecialchars' => array (ENT_QUOTES ),
- ))
- -> AddElement ('publication status', 'State ',
- Array (
- 'Not _ empty' => null,
- 'Digit' => null,
- 'Regex' => array ('~ ^ [01] $ ~ ')
- ),
- Array ())
- -> AddElement ('Show on Homepage? ', 'showinhome ',
- Array (
- 'Boolean' => null,
- ),
- Array ())
- -> AddElement ('news content', 'content ',
- Array (
- 'Not _ empty' => null,
- ),
- Array (
- 'Tidy _ parse_string '=> array (
- Array (
- 'Indent '=> true,
- 'Output-xhtml '=> true,
- 'Clean' => true,
- 'Drop-font-tags' => true,
- 'Show-body-only' => true
- ), 'Utf8 '),
- 'Trim' => null
- ));
- }
- }
- Public function action_GET ()
- {
- // Obtain the ID in the url
- $ Id = $ this-> request-> param ('id', null );
- // Send the token to the view layer (put it in the hidden field of the form)
- $ This-> view ['token'] = Form \ NewsPoster: getToken ()-> useToken ();
- }
- Public function action_POST ()
- {
- $ Id = $ this-> request-> param ('id', null );
- $ Form = Form \ NewsPoster: factory ($ _ POST );
- $ Form-> bindAllElement ();
- If ($ form-> checkForm ()){
- // After the verification is passed, call the domain model to perform the operation ~
- $ This-> view ['success'] = true;
- } Else {
- $ This-> view ['success'] = false;
- // Send the error message back to the view layer
- $ This-> view ['message'] = array_values ($ form-> getMessage ());
- }
- }
|