[dev] Weather block; need advice/help

Rick Emery rick at emery.homelinux.net
Thu Jan 15 09:18:41 PST 2004


Quoting Chuck Hagenbuch <chuck at horde.org>:

> Quoting Rick Emery <rick at emery.homelinux.net>:
>
> > The pear Services_Weather module searches for the location ID by receiving
> > a location string (for example, "Sanford, FL") and querying the web
service.
> >
> > It returns either a) a pear error if the location isn't found, b) a string
> > containing the ID of the location, or c) an array of possible matches.
>
> [snip]
>
> > It would be great if there were a way to query Services_Weather with the
> > location, evaluate the return, and present appropriate feedback to the
> > user while still inside the layout.
>
> The ideal thing would be to use Horde_Form validation to mark the form as
> invalid if the location isn't an exact match (validate the location when the
> params are saved). Either say completely not found, or present the list of
> possible matches, and only consider the form valid once you get a match.
>
>
> Quoting Rick Emery <rick at emery.homelinux.net>:
>
> > That sounds perfect. Is there a file I can look at to see an example of
> > Horde_Form validation in action?
>
> Any app that uses it - whups, etc. You'll probably need to create a custom
> Horde_Form_Type_weatherdotcom or some such, and you'll want to look at the
> type validate() functions in Form.php.
>
> -chuck

Sorry to bother you guys, but it would appear that I need a little (a lot?)
more hand-holding.

I added a new type to Form.php (Horde_Form_Type_weather). I basically just
copied the one for text, and changed the "isValid" function to meet my needs.
(sends the value to weather.com and receives a PEAR error, an array, or the
location ID).

I thought I might be lucky enough to simply change the "type" in the params
array of the block from "text" to "weather", but that didn't work; in the
layout for the block, I no longer get a textbox into which to type the
location.

I tried looking at some examples of form validation (like signup.php and a
couple of files in whups) and ended up thoroughly confused; I couldn't figure
out how to adapt what I saw to my little weather portal block (there isn't any
kind of rendering for the layout portion of the block, only the content; the
layout, I guess, is built somewhere else from the params array).

Any pointers would be great. Am I even close?

Thanks in advance!
Rick

--
Rick Emery

"When once you have tasted flight, you will forever walk the Earth
 with your eyes turned skyward, for there you have been, and there
 you will always long to return"
                                              -- Leonardo Da Vinci



More information about the dev mailing list