Enable fillin for one single action (without validation)

Social code snippet repository

Moderators: dwhittle, Ian

Enable fillin for one single action (without validation)

Postby roga » Tue Feb 13, 2007 6:12 pm

The challenge:
My application uses a dynamically generated form - therefore I have to use a custom validationXXX() method to validate form input because the field names will change on each request.

There is currently no way to enable the fillin filter for only one single action, if you use a custom validationXXX() method.

The solution:
You have two choices to enable fillin filter:
METHOD 1: add the fillin filter in filters.yml
-> drawback: it will be executed for every action -> overhead)

METHOD 2: create a .yml validation file and enable fillin
Code: Select all
./validate/xxx.yml:

fillin:
  enabled: on


This will throw an exception because symfony looks for a "fields" key.

So I tried:
Code: Select all
./validate/xxx.yml:

fillin:
  enabled: on

fields: []


No error, but also no fillin filter. It's disabled automatically because symfony doesn't find any validation fields.

So the solution is to use a hidden input field:
Code: Select all
./validate/xxx.yml:

fillin:
  enabled: on

fields:
  hiddenfield:
    required: yes

./templates/myactionSuccess.php:

...
<?php echo hidden_tag('hiddenfield', 1); ?>
...
Last edited by roga on Tue Feb 13, 2007 6:12 pm, edited 1 time in total.
roga
Member
 
Posts: 55
Joined: Thu Dec 28, 2006 8:45 pm

Re: Enable fillin for one single action (without validation)

Postby Stegnation » Fri Mar 16, 2007 1:50 am

I did it like this:
Code: Select all
methods:
  post: [anything]

names:
  anything:
    required:     false

fillin:
  enabled: on
Stegnation
Junior Member
 
Posts: 17
Joined: Thu Jul 06, 2006 12:11 pm
Location: Netherlands


Return to snipeet

Who is online

Users browsing this forum: No registered users and 1 guest