Development

Changeset 28020

You must first sign up to be able to contribute.

Changeset 28020

Show
Ignore:
Timestamp:
02/14/10 10:06:15 (3 years ago)
Author:
Krapulator
Message:

Started re-engineering plugin to add support for embedded forms and to clean up the code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfJqueryFormValidationPlugin/lib/filter/sfJqueryFormValidationFilter.class.php

    r21528 r28020  
    33class sfJqueryFormValidationFilter extends sfFilter 
    44{ 
    5  public function execute($filterChain)  
     5  public function execute($filterChain)  
    66  { 
    77    $filterChain->execute(); 
     
    1111      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')))) 
    1212      { 
     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         
    1329        $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())); 
    1531      } 
    1632    } 
  • plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/actions/actions.class.php

    r18363 r28020  
    1010     
    1111    // 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)); 
    1314     
    14     // make sure the class name provided is actually a symfony form 
    15     $this->forward404Unless(is_subclass_of($form, 'sfForm')); 
     15    // create an instance of the sfJqueryFormValidationRules object 
     16    $this->sf_jq_rules = new sfJqueryFormValidationRules(new $form); 
    1617     
    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    } 
    1926     
    20     // put the form name into a variable for easier reading of code in view 
    21     $this->name = $this->form->getName(); 
    22      
    23     // put the field objects into a variable 
    24     $this->fields = $this->form->getValidatorSchema()->getFields(); 
    25      
    26     // remove the csrf token from the field list if it exists 
    27     unset($this->fields['_csrf_token']); 
    2827  } 
     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   
    2935} 
  • plugins/sfJqueryFormValidationPlugin/modules/sfJqueryFormVal/templates/indexSuccess.php

    r21528 r28020  
    1 <?php  
    2   use_helper('JqueryFormVal'); 
    3   $fields = $sf_data->getRaw('fields'); 
    4   $field_total = sizeof($fields); 
    5   $counter = 1; 
    6 ?> 
    7  
    81jQuery(function($){ 
    92   
    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() ?>, 
    326    wrapper: 'ul class=error_list', 
    337    errorElement: 'li', 
     
    4620  }); 
    4721   
    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 ?> 
    5125 
    5226});