[SOLVED ]form_remote_tag and validation in sf1.1

Discussion specific to symfony 1.1.x stable

Moderator: hartym

[SOLVED ]form_remote_tag and validation in sf1.1

Postby ringhio » Wed Aug 06, 2008 5:36 pm

Hi, I'm looking for some help with validation of form_remote_tag in Symfony 1.1. Form created from form_remote_tag is not the 1.1 way with new form framework, so I can't use new validation.

But how to validate in Sf1.1 a form_remote_tag? I've created the add_bet.yml and activated compat_10 in the settings.yml, it doesn't works. I don't see nothing in the generated code of the page (about js validation)...

The snippet of the form
Code: Select all
<?php echo form_remote_tag(array(
  'update'   => 'item_list',
  'url'      => '@add_bet',
  'loading'  => "Element.show('indicator')",
  'complete' => "Element.hide('indicator');".visual_effect('highlight', 'item_list'),
)) ?>


add_bet.yml (in the module validate dir)
Code: Select all
fields:
  credits:
    required:
      msg:              The credit field cannot be left blank
    sfNumberValidator:
      nan_error:        Please enter an integer
      min:              1
      min_error:        The value must be at least one
      max:              100
      max_error:        The value must be less than or equal to 100


Some help?

Thanks
Daniel
Last edited by ringhio on Fri Aug 08, 2008 12:45 pm, edited 1 time in total.
User avatar
ringhio
Member
 
Posts: 57
Joined: Wed Aug 06, 2008 9:57 am

Re: form_remote_tag and validation in sf1.1

Postby payacer » Wed Aug 06, 2008 8:47 pm

hm...I just did things the old way:

methods:
post: [nickname, password]

names:
nickname:
required: true
required_msg: your nickname is required
validators: nicknameValidator

password:
required: true
required_msg: your password is required

nicknameValidator:
class: sfStringValidator
param:
min: 5
min_error: nickname must be 5 or more characters


...and it seemed to work for me...

Andrew
payacer
Member
 
Posts: 39
Joined: Sat Jul 05, 2008 7:23 pm
Location: Canada

Re: form_remote_tag and validation in sf1.1

Postby payacer » Wed Aug 06, 2008 8:48 pm

to avoid confusion: need the spaces in there:

Code: Select all
methods:
  post: [nickname, password]

names:
  nickname:
    required:     true
    required_msg: your nickname is required
    validators:   nicknameValidator

  password:
    required:     true
    required_msg: your password is required

nicknameValidator:
    class:        sfStringValidator
    param:
      min:        5
      min_error:  nickname must be 5 or more characters
payacer
Member
 
Posts: 39
Joined: Sat Jul 05, 2008 7:23 pm
Location: Canada

Re: form_remote_tag and validation in sf1.1

Postby ringhio » Wed Aug 06, 2008 10:00 pm

Ok payacer, thanks for the hint. Tomorrow I'll try in that way.

Daniel
User avatar
ringhio
Member
 
Posts: 57
Joined: Wed Aug 06, 2008 9:57 am

Re: form_remote_tag and validation in sf1.1

Postby ringhio » Fri Aug 08, 2008 10:01 am

I can't see any advice for wrong data...maybe I'm doing something wrong...
User avatar
ringhio
Member
 
Posts: 57
Joined: Wed Aug 06, 2008 9:57 am

Re: form_remote_tag and validation in sf1.1

Postby ringhio » Fri Aug 08, 2008 12:44 pm

Problem solved!

Just added in the addError.php some code to display errors catched from validator add.yml:

Code: Select all
<?php if ($sf_request->hasErrors()): ?
  <p>The data you entered seems to be incorrect. Please correct the following errors and resubmit:</p>
  <ul>
    <?php foreach($sf_request->getErrors() as $name => $error): ?>
      <li><?php echo $name ?>: <?php echo $error ?></li>
    <?php endforeach; ?>
  </ul>
<?php endif; ?>
User avatar
ringhio
Member
 
Posts: 57
Joined: Wed Aug 06, 2008 9:57 am


Return to symfony 1.1

Who is online

Users browsing this forum: Google [Bot] and 1 guest