Changeset 28020
- Timestamp:
- 02/14/10 10:06:15 (3 years ago)
- Files:
-
- plugins/sfJqueryFormValidationPlugin/lib/filter/sfJqueryFormValidationFilter.class.php (modified) (2 diffs)
- plugins/sfJqueryFormValidationPlugin/lib/sfJqueryFormValidationRules.class.php (added)
- plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/actions/actions.class.php (modified) (1 diff)
- plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/templates/indexSuccess.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfJqueryFormValidationPlugin/lib/filter/sfJqueryFormValidationFilter.class.php
r21528 r28020 3 3 class sfJqueryFormValidationFilter extends sfFilter 4 4 { 5 public function execute($filterChain)5 public function execute($filterChain) 6 6 { 7 7 $filterChain->execute(); … … 11 11 if ($value instanceof sfForm && (sfConfig::get('app_sf_jquery_form_validation_default') !== 'disabled' || in_array(get_class($value), sfConfig::get('app_sf_jquery_form_validation_forms')))) 12 12 { 13 $url_params = array( 14 'module' => 'sfJqueryFormVal', 15 'action' => 'index', 16 'form' => get_class($value), 17 ); 18 19 $embedded_forms = array(); 20 foreach($value->getEmbeddedForms() as $name => $embedded_form) 21 { 22 $url_params['embedded_form'][$name] = get_class($embedded_form); 23 } 24 if(sizeof($embedded_forms) > 0) 25 { 26 $url_params['embedded_form'] = $embedded_forms; 27 } 28 13 29 $response = $this->getContext()->getResponse(); 14 $response->setContent(str_ireplace('</head>', '<script type="text/javascript" src="' . url_for( 'sfJqueryFormVal/index?form=' . get_class($value)) . '"></script></head>',$response->getContent()));30 $response->setContent(str_ireplace('</head>', '<script type="text/javascript" src="' . url_for($url_params) . '"></script></head>',$response->getContent())); 15 31 } 16 32 } plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/actions/actions.class.php
r18363 r28020 10 10 11 11 // make sure that the form class specified actually exists 12 $this->forward404Unless(class_exists($form)); 12 // and it is really a symfony form 13 $this->forward404Unless($this->isValidSfFormName($form)); 13 14 14 // make sure the class name provided is actually a symfony form15 $this-> forward404Unless(is_subclass_of($form, 'sfForm'));15 // create an instance of the sfJqueryFormValidationRules object 16 $this->sf_jq_rules = new sfJqueryFormValidationRules(new $form); 16 17 17 // instantiate an instance of the form 18 $this->form = new $form; 18 // add embedded forms 19 foreach($request->getParameter('embedded_form') as $name => $form) 20 { 21 if($this->isValidSfFormName($form)) 22 { 23 $this->sf_jq_rules->addEmbeddedForm($name, new $form); 24 } 25 } 19 26 20 // put the form name into a variable for easier reading of code in view21 $this->name = $this->form->getName();22 23 // put the field objects into a variable24 $this->fields = $this->form->getValidatorSchema()->getFields();25 26 // remove the csrf token from the field list if it exists27 unset($this->fields['_csrf_token']);28 27 } 28 29 30 private function isValidSfFormName($form_class_name) 31 { 32 return class_exists($form_class_name) && is_subclass_of($form_class_name, 'sfForm'); 33 } 34 29 35 } plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/templates/indexSuccess.php
r21528 r28020 1 <?php2 use_helper('JqueryFormVal');3 $fields = $sf_data->getRaw('fields');4 $field_total = sizeof($fields);5 $counter = 1;6 ?>7 8 1 jQuery(function($){ 9 2 10 $('#<?php echo strlen($name) > 0 ? $name . '_' . key($fields) : key($fields) ?>').parents('form').validate({ 11 rules: { 12 <?php foreach($fields as $fieldname => $field): ?> 13 14 '<?php echo (strlen($name) > 0 ? $name . '[' . $fieldname . ']' : $fieldname ) . '\': { 15 ' ?> 16 <?php echo function_exists(get_class($field) . '_rules') ? call_user_func(get_class($field) . '_rules', $field) : '' ?> 17 18 }<?php echo $counter < $field_total ? ',' : '' ?> 19 <?php $counter++ ?><?php endforeach ?> 20 },<?php $counter = 1 ?> 21 22 messages: { 23 <?php foreach($fields as $fieldname => $field): ?> 24 '<?php echo (strlen($name) > 0 ? $name . '[' . $fieldname . ']' : $fieldname ) . '\': { 25 ' ?> 26 <?php echo sf_form_messages($field, $name . '[' . $fieldname . ']') ?> 27 28 }<?php echo $counter < $field_total ? ',' : '' ?> 29 30 <?php $counter++ ?><?php endforeach; ?> 31 }, 3 $('#<?php echo $sf_jq_rules->getFirstFieldHtmlId() ?>').parents('form').validate({ 4 rules: <?php echo $sf_jq_rules->generateRules() ?>, 5 messages: <?php echo $sf_jq_rules->generateMessages() ?>, 32 6 wrapper: 'ul class=error_list', 33 7 errorElement: 'li', … … 46 20 }); 47 21 48 <?php if($post_validator = $form->getValidatorSchema()->getPostValidator()): ?>49 <?php echo function_exists(get_class($post_validator) . '_process') ? call_user_func(get_class($post_validator) . '_process', $post_validator, $name) : '' ?>50 <?php endif ?>22 <?php //if($post_validator = $form->getValidatorSchema()->getPostValidator()): ?> 23 <?php //echo function_exists(get_class($post_validator) . '_process') ? call_user_func(get_class($post_validator) . '_process', $post_validator, $name) : '' ?> 24 <?php //endif ?> 51 25 52 26 });