Development

#483 (sfFillInFormFilter omits default values)

You must first sign up to be able to contribute.

Ticket #483 (closed defect: worksforme)

Opened 3 years ago

Last modified 2 years ago

sfFillInFormFilter omits default values

Reported by: anonymous Assigned to: pookey@pookey.co.uk
Priority: major Milestone: 0.6.3
Component: Version: 0.6.2
Keywords: Cc:
Qualification:

Description

Example:

echo checkbox_tag('search-notes', '1', true)

The checkbox is unchecked by default (the form hasn't been submitted yet) when using sfFillInFormFilter to fill the form.

Change History

05/24/06 01:11:52 changed by Ian P. Christian <pookey@pookey.co.uk>

I personally consider this expected behaviour, which might seem odd to you, but here goes....

If you want to use values shown in the template, don't load the fillin filter, if you wnat to use things from the request to fill in your form, then load the fillin filter.

If you want to use a bit from both, then perhaps ticket #573 mihgt be of interest to you, where you can specifically stop the fillin filter from filling in a certain field.

Does this help? Please close this ticket if you are happy with this comment

05/27/06 13:17:22 changed by anonymous

I haven't caught the point. I want to use values from the request, but only if there is any chance, the values make sense (the form was submitted). How can I specify default values, when the form hasn't been submitted yet? I would expect the sfFillInFormFilter to take action only in case a user submits the form.

05/29/06 07:35:18 changed by Ian

I agree with anonymous here Ian, the fillInFilter should only populate form fields IF the request variable for that field exists. If it does not exist and filter is enabled, we must assume that the form has never been submitted and thus populate the field with the default value.

05/29/06 17:39:19 changed by pookey@pookey.co.uk

  • owner set to pookey@pookey.co.uk.

yeah, you're right, I'll fix this :)

05/29/06 22:59:42 changed by Ian P. Christian <pookey@pookey.co.uk>

  • owner changed from pookey@pookey.co.uk to anonymous.
  • status changed from new to assigned.

try this...

Index: lib/filter/sfFillInFormFilter.class.php
===================================================================
--- lib/filter/sfFillInFormFilter.class.php     (revision 1389)
+++ lib/filter/sfFillInFormFilter.class.php     (working copy)
@@ -62,7 +62,7 @@
       foreach($xpath->query($query, $form) as $element)
       {
         // skip fields specified in the 'skip_fields' attribute
-        if ($request->hasParameter($element->getAttribute('name')) && in_array($element->getAttribute('name'), $skip_fields))
+        if (!($request->hasParameter($element->getAttribute('name'))) || in_array($element->getAttribute('name'), $skip_fields))
         {
           continue;
         }
@@ -145,4 +145,4 @@
   }
 }

-?>
\ No newline at end of file
+?>

this has been checked into my branch in r1390

05/29/06 23:01:55 changed by Ian P. Christian <pookey@pookey.co.uk>

  • owner changed from anonymous to pookey@pookey.co.uk.
  • status changed from assigned to new.

06/16/06 09:46:47 changed by fabien

  • milestone changed from 0.6.4 to 0.6.3.

06/16/06 09:46:48 changed by fabien

  • milestone changed from 0.6.4 to 0.6.3.

06/21/06 12:24:42 changed by fabien

  • status changed from new to closed.
  • resolution set to worksforme.

If I try:

actions.class.php

  public function executeIndex()
  {
  }

  public function handleErrorIndex()
  {
    return sfView::SUCCESS;
  }

validate/index.yml

methods:
  post: [...]

fillin:
  activate: on

templates/indexSuccess.php

<?php echo form_tag('test/index') ?>
<?php echo input_tag('test', 2) ?>
<?php echo checkbox_tag('test1', '1', true) ?>
<?php echo submit_tag() ?>
</form>

It works as expected. The first time I call the index page (GET), the checkbox is checked.