Advertisement
cng

Controller/Form/Output v2

cng
Dec 17th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 7.16 KB | None | 0 0
  1. #CNG::Controller::Form::Booking
  2.  
  3. has "form" => (
  4.         is      => 'rw',
  5.         lazy    => 1,
  6.         builder => '_build_form',
  7. );
  8. sub _build_form {
  9.         my $self = shift;
  10.     warn "USING BUILD for Controller::BookingRequests->_build_form\n";
  11.         return CNG::HTML::FormHandler::Form::BR_Test->new(  );
  12. }
  13. sub get_form {
  14.         my $self = shift;
  15.  
  16.     warn "Before clearing item: \n";
  17.     $self->form->dump;
  18.     $self->form->clear_item;
  19.     warn "After clearing item: \n";
  20.     $self->form->dump;
  21.     $self->form->clear;
  22.     warn "After clearing form: \n";
  23.     $self->form->dump;
  24.  
  25.         return $self->form;
  26. }
  27.  
  28. sub start :Chained('base') :PathPart('booking') :Args(0) : GET {
  29.         my ($self, $c) = @_;
  30.         (my $form = $self->get_form())->process( schema => $c->model('DBIC')->schema );
  31.         $c->stash(
  32.                 template => $self->templates->{create},
  33.                 form     => $form,
  34.         );
  35. }
  36.  
  37. sub submit :Chained('base') :PathPart('booking') :Args(0) : POST {
  38.     my ($self, $c) = @_;
  39.  
  40.     my $item;
  41.   {
  42.     local $ENV{DBIC_NULLABLE_KEY_NOWARN} = 1;
  43.     $item = $c->model('DBIC::BookingRequest')->new_result({});
  44.   }
  45.     unless ($item) {
  46.         $c->detach('/not_found');
  47.     }
  48.  
  49.     my $form = $self->get_form();
  50.  
  51.     $c->stash(
  52.         template => $self->templates->{create},
  53.         item     => $item,
  54.         form     => $form,
  55.     );
  56.  
  57.     if ( $form->process( item => $item, params => $c->request->params, ip_addr => $c->request->address ) ) {   
  58.         $c->response->redirect($c->uri_for_action('/bookingrequests/review', [$item->id]));
  59.         $c->detach;
  60.     }
  61. }
  62.  
  63.  
  64. #CNG::HTML::FormHandler::Form::BR_Test
  65.  
  66. package CNG::HTML::FormHandler::Form::BR_Test;
  67.  
  68. use Moose;
  69. use namespace::autoclean;
  70. use utf8;
  71.  
  72. use HTML::FormHandler::Moose;
  73.  
  74. extends qw'HTML::FormHandler';
  75. with   qw'HTML::FormHandler::TraitFor::Model::DBIC
  76.          CNG::HTML::FormHandler::Component::Actions ';
  77.  
  78. has '+item_class'      => ( default => 'BookingRequest' );
  79.  
  80. has_field 'group_name' => ( type => 'Text',  label => 'Full Organisation/Church Name',
  81.     inactive => 0,      size => 36,
  82.     required => 1,      maxlength => 120,
  83. );
  84.  
  85. has_field 'addr_locality_id' => (
  86.     type     => 'Hidden',
  87.     inactive => 0,
  88.     default    => '16633',
  89.     do_wrapper => 0,
  90. );
  91.  
  92. no HTML::FormHandler::Moose;
  93.  
  94. __PACKAGE__->meta->make_immutable(inline_constructor => 0);
  95.  
  96. 1;
  97.  
  98.  
  99. # output after starting up server
  100.  
  101. Before clearing item:
  102. USING BUILD for Controller::BookingRequests->_build_form
  103. HFH: ------- fields for form16-------
  104. HFH: -----  group_name -----
  105. HFH: type: Text
  106. HFH: required: 1
  107. HFH: label: Full Organisation/Church Name
  108. HFH: widget: Text
  109. HFH: -----  addr_locality_id -----
  110. HFH: type: Hidden
  111. HFH: required: 0
  112. HFH: label: Addr locality id
  113. HFH: widget: Hidden
  114. HFH: value: $VAR1 = '16633';
  115. HFH: init_value: $VAR1 = '16633';
  116. HFH: fif: $VAR1 = '16633';
  117. HFH: ------- fields for form_actions-------
  118. HFH: -----  save -----
  119. HFH: type: Submit
  120. HFH: required: 0
  121. HFH: label: Save
  122. HFH: widget: Submit
  123. HFH: value: $VAR1 = 'Save';
  124. HFH: -----  cancel -----
  125. HFH: type: Reset
  126. HFH: required: 0
  127. HFH: label: Cancel
  128. HFH: widget: Reset
  129. HFH: value: $VAR1 = 'Cancel';
  130. HFH: ------- end fields -------
  131. HFH: ------- end fields -------
  132. After clearing item:
  133. HFH: ------- fields for form16-------
  134. HFH: -----  group_name -----
  135. HFH: type: Text
  136. HFH: required: 1
  137. HFH: label: Full Organisation/Church Name
  138. HFH: widget: Text
  139. HFH: -----  addr_locality_id -----
  140. HFH: type: Hidden
  141. HFH: required: 0
  142. HFH: label: Addr locality id
  143. HFH: widget: Hidden
  144. HFH: value: $VAR1 = '16633';
  145. HFH: init_value: $VAR1 = '16633';
  146. HFH: fif: $VAR1 = '16633';
  147. HFH: ------- fields for form_actions-------
  148. HFH: -----  save -----
  149. HFH: type: Submit
  150. HFH: required: 0
  151. HFH: label: Save
  152. HFH: widget: Submit
  153. HFH: value: $VAR1 = 'Save';
  154. HFH: -----  cancel -----
  155. HFH: type: Reset
  156. HFH: required: 0
  157. HFH: label: Cancel
  158. HFH: widget: Reset
  159. HFH: value: $VAR1 = 'Cancel';
  160. HFH: ------- end fields -------
  161. HFH: ------- end fields -------
  162. After clearing form:
  163. HFH: ------- fields for form16-------
  164. HFH: -----  group_name -----
  165. HFH: type: Text
  166. HFH: required: 1
  167. HFH: label: Full Organisation/Church Name
  168. HFH: widget: Text
  169. HFH: -----  addr_locality_id -----
  170. HFH: type: Hidden
  171. HFH: required: 0
  172. HFH: label: Addr locality id
  173. HFH: widget: Hidden
  174. HFH: init_value: $VAR1 = '16633';
  175. HFH: ------- fields for form_actions-------
  176. HFH: -----  save -----
  177. HFH: type: Submit
  178. HFH: required: 0
  179. HFH: label: Save
  180. HFH: widget: Submit
  181. HFH: value: $VAR1 = 'Save';
  182. HFH: -----  cancel -----
  183. HFH: type: Reset
  184. HFH: required: 0
  185. HFH: label: Cancel
  186. HFH: widget: Reset
  187. HFH: value: $VAR1 = 'Cancel';
  188. HFH: ------- end fields -------
  189. HFH: ------- end fields -------
  190. Rendering template "booking_requests/new.tt2"
  191.  
  192.  
  193.  
  194. ## submit form, then return to `start`
  195.  
  196. Before clearing item:
  197. HFH: ------- fields for form587-------
  198. HFH: -----  group_name -----
  199. HFH: type: Text
  200. HFH: required: 1
  201. HFH: label: Full Organisation/Church Name
  202. HFH: widget: Text
  203. HFH: value: $VAR1 = 'SCR';
  204. HFH: input: $VAR1 = 'SCR';
  205. HFH: fif: $VAR1 = 'SCR';
  206. HFH: -----  addr_locality_id -----
  207. HFH: type: Hidden
  208. HFH: required: 0
  209. HFH: label: Addr locality id
  210. HFH: widget: Hidden
  211. HFH: value: $VAR1 = '16633';
  212. HFH: input: $VAR1 = '16633';
  213. HFH: fif: $VAR1 = '16633';
  214. HFH: ------- fields for form_actions-------
  215. HFH: -----  save -----
  216. HFH: type: Submit
  217. HFH: required: 0
  218. HFH: label: Save
  219. HFH: widget: Submit
  220. HFH: value: $VAR1 = 'Save';
  221. HFH: input: $VAR1 = 'Save';
  222. HFH: -----  cancel -----
  223. HFH: type: Reset
  224. HFH: required: 0
  225. HFH: label: Cancel
  226. HFH: widget: Reset
  227. HFH: value: $VAR1 = 'Cancel';
  228. HFH: ------- end fields -------
  229. HFH: ------- end fields -------
  230. After clearing item:
  231. HFH: ------- fields for form587-------
  232. HFH: -----  group_name -----
  233. HFH: type: Text
  234. HFH: required: 1
  235. HFH: label: Full Organisation/Church Name
  236. HFH: widget: Text
  237. HFH: value: $VAR1 = 'SCR';
  238. HFH: input: $VAR1 = 'SCR';
  239. HFH: fif: $VAR1 = 'SCR';
  240. HFH: -----  addr_locality_id -----
  241. HFH: type: Hidden
  242. HFH: required: 0
  243. HFH: label: Addr locality id
  244. HFH: widget: Hidden
  245. HFH: value: $VAR1 = '16633';
  246. HFH: input: $VAR1 = '16633';
  247. HFH: fif: $VAR1 = '16633';
  248. HFH: ------- fields for form_actions-------
  249. HFH: -----  save -----
  250. HFH: type: Submit
  251. HFH: required: 0
  252. HFH: label: Save
  253. HFH: widget: Submit
  254. HFH: value: $VAR1 = 'Save';
  255. HFH: input: $VAR1 = 'Save';
  256. HFH: -----  cancel -----
  257. HFH: type: Reset
  258. HFH: required: 0
  259. HFH: label: Cancel
  260. HFH: widget: Reset
  261. HFH: value: $VAR1 = 'Cancel';
  262. HFH: ------- end fields -------
  263. HFH: ------- end fields -------
  264. After clearing form:
  265. HFH: ------- fields for form587-------
  266. HFH: -----  group_name -----
  267. HFH: type: Text
  268. HFH: required: 1
  269. HFH: label: Full Organisation/Church Name
  270. HFH: widget: Text
  271. HFH: -----  addr_locality_id -----
  272. HFH: type: Hidden
  273. HFH: required: 0
  274. HFH: label: Addr locality id
  275. HFH: widget: Hidden
  276. HFH: ------- fields for form_actions-------
  277. HFH: -----  save -----
  278. HFH: type: Submit
  279. HFH: required: 0
  280. HFH: label: Save
  281. HFH: widget: Submit
  282. HFH: value: $VAR1 = 'Save';
  283. HFH: -----  cancel -----
  284. HFH: type: Reset
  285. HFH: required: 0
  286. HFH: label: Cancel
  287. HFH: widget: Reset
  288. HFH: value: $VAR1 = 'Cancel';
  289. HFH: ------- end fields -------
  290. HFH: ------- end fields -------
  291. Rendering template "booking_requests/new.tt2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement