On 08.05.2009, at 12:58, [email protected] wrote:

Hi all,

I have a form which is to accept image uploads and need some help with the following:

1. My form allows a maximum of 3 images to be uploaded. I'm wondering if it is necessary for me to check that not more than 3 are uploaded?

If yes, how do I do this? My input fields are called data[images] [1], data[images][2]... etc - I tried checking these fields using the array length validator as below, but it always fails (even when the validation conditions are met).

      <validator class="arraylength">
        <arguments base="data[Images][]">
          <argument/>
        </arguments>
        <errors>
          <error>Error</error>
        </errors>
        <ae:parameters>
          <ae:parameter name="required">false</ae:parameter>
          <ae:parameter name="min">0</ae:parameter>
          <ae:parameter name="max">3</ae:parameter>
        </ae:parameters>
      </validator>

Not like that. If you use an arguments base, then that simply means that every element in the base will be run against the validator. Not what you want in this case.

What you want to do is simply check for the length of the images array:
<argument>data[images]</argument>


2. Is there any Agavi config variable that returns the full path to the pub/ dir? Right now I'm using

        $target = AgaviConfig::get('core.app_dir') . '/../pub/';

but is there a better way?

You could set that in settings.xml (or if you want to realpath() it, in app/config.php) as "core.pub_dir". Wouldn't that work?
<setting name="pub_dir">%core.app_dir%/../pub/</setting>


3. I need to validate two fields together ie. sale price min and max and return an error if min > max. I have absolutely no clue how to do this :) except possibly to use an 'and' validator somehow...my initial attempts all blew up in my face.

I don't think there is a validator that does this out of the box. You need to write a little custom validator that takes two arguments and compares them. AgaviEqualsValidator might be a good template (although it has this "asparam" stuff you can ignore). In case of doubt, hop on IRC to get help with this, there's always someone around to lend you a hand in "real time".


4. If the code in my Action throws and catches an Exception, how do I pass the Exception message forward to the view? For example, in the below code, I'd like to read $e->message and have that displayed in the Error view

public function executeWrite(AgaviRequestDataHolder $rd)
{
      try {
        // initialize object
        $listing = new Listing();
        // populate with validated input
        $listing->fromArray($rd->getParameter('data'));
        $listing->DisplayStatus = 0;
        $listing->save();
          return 'Success';
      } catch (Exception $e) {
          // $msg = $e->getMessage();
          return 'Error';
        }
  }

Why don't you simply set the exception or the message as an attribute!?

-  David

Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

Reply via email to