Hi all

I have a strange problem. I have a search form which is submitting
data via GET. When submitted with invalid data, the validator error
messages don't appear. However, when i change the method to POST and
the Action's executeRead to executeWrite, the messages show up. Can
someone advise why this is happening and how to correct it?

Code below. Thanks

Vikram



Template:

<form action="<?php echo $ro->gen('listing.search'); ?>" method="get">
  <fieldset style="width:60%">
    <legend>Criteria</legend>
        Color:
        <input id="color" type="text" name="color" style="width:80px" />

        Year:
        <input id="year" type="text" name="year" size="4" style="width:80px" />
        
        Price:
        <input id="price" type="text" name="price" style="width:80px" />
        
    <button id="search" type="submit"/>
        </fieldset>
</form>

Action:

<?php

class Listing_SearchAction extends WASPListingBaseAction
{
        public function executeRead(AgaviRequestDataHolder $rd)
        {       
    try {
      // create base query
      $q = Doctrine_Query::create()
            ->from('Listing l')
            ->leftJoin('l.Manufacturer m')
            ->leftJoin('l.Country c');

      // add criteria
      if ($rd->getParameter('color')) {
        $q->addWhere('l.VehicleColor LIKE ?', sprintf('%%%s%%',
$rd->getParameter('color')));
      }

      if ($rd->getParameter('year')) {
        $q->addWhere('l.VehicleYear = ?', $rd->getParameter('year'));
      }

      if ($rd->getParameter('price')) {
        $q->addWhere('? BETWEEN l.VehicleSalePriceMin AND
l.VehicleSalePriceMax', $rd->getParameter('price'));
      }

      // execute query and assign results to template variable
      $results = $q->fetchArray();
      $this->setAttribute('records', $results);
      return 'Success';
    } catch (Exception $e) {
      $this->setAttribute('error', $e->getMessage());
      return 'Error';
    }
        }
        
        public function getDefaultViewName()
        {
    return 'Success';   
  }
        
}

?>

Validators:

<?xml version="1.0" encoding="UTF-8"?>
<ae:configurations
        xmlns="http://agavi.org/agavi/config/parts/validators/1.0";
        xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0";
        parent="%core.module_dir%/Listing/config/validators.xml"
>
        <ae:configuration>
                
    <validators>

      <validator class="string">
        <arguments>
          <argument>color</argument>
        </arguments>
        <errors>
          <error>ERROR: Vehicle color is invalid</error>
        </errors>
        <ae:parameters>
          <ae:parameter name="required">false</ae:parameter>
        </ae:parameters>
      </validator>

      <validator class="number">
        <arguments>
          <argument>year</argument>
        </arguments>
        <errors>
          <error for="type">ERROR: Vehicle year of manufacture is
invalid</error>
          <error for="min">ERROR: Vehicle year of manufacture is
before 1900</error>
          <error for="max">ERROR: Vehicle year of manufacture is after
2020</error>
        </errors>
        <ae:parameters>
          <ae:parameter name="type">int</ae:parameter>
          <ae:parameter name="min">1901</ae:parameter>
          <ae:parameter name="max">2020</ae:parameter>
          <ae:parameter name="required">false</ae:parameter>
        </ae:parameters>
      </validator>

      <validator class="number">
        <arguments>
          <argument>price</argument>
        </arguments>
        <errors>
          <error>ERROR: Vehicle price is invalid</error>
        </errors>
        <ae:parameters>
          <ae:parameter name="type">int</ae:parameter>
          <ae:parameter name="min">0</ae:parameter>
          <ae:parameter name="required">false</ae:parameter>
        </ae:parameters>
      </validator>

                </validators>
                
        </ae:configuration>
</ae:configurations>

_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to