On Wed, 7 May 2008, Andreas Schamberger wrote:
> today I started to convert some of my forms to use UserInput. Generally
> this is a great component. But there are two major show stoppers in my
> eyes that force a programmer to write a lot of unnecessary duplicate
> code. And surprisingly there are already two issues for them:
>
> #012345: ezcInputForm->isValid()
> http://issues.ez.no/IssueView.php?Id=12345&activeItem=3
>
> #011394: UserInput::emptyValue
> http://issues.ez.no/IssueView.php?Id=11394&activeItem=2
>
> Without these two little features it's really annoying as you have to
> check also the case of a valid form with an additional foreach loop.
> "if( empty( $form->getInvalidProperties() ) )" works only if you allow
> empty strings and is still ugly as the bug reporter already notes in
> issue #012345.
We'll make sure to include those in the next release then (which will
not be 2008.1 as we've already passed the add-feature deadline for
that).
> I also like to have "require_string" as a filter_type:
> In my eyes it does not make sense to add callbacks for this but instead
> only strip the 'require_' part of the filter name and check the result
> afterwards:
>
> $checkEmpty = false;
> $filterName = $inputElement->filterName;
> if ( substr( $filterName, 0, 8 ) === 'require_' )
> {
> $checkEmpty = true;
> $filterName = substr( $filterName, 8 );
> }
> // filter_input call ...
> if ( ( $value !== null && $checkEmpty === false ) || ( $value !== null
> && !empty( $value ) ) )
> {
> $this->properties[$elementName] = ezcInputForm::VALID;
> // ...
>
> This way the require can also be used to require other filters that
> output an empty string and not NULL and it doesn't add too much
> complexity. The usage of "require_" could of course also be restricted
> to them to make the usage clearer.
Could you file an issue for this please?
>
> With these two issues fixed the component is more intuitive to use:
>
> if ( $form->isValid() )
> {
> // submit to db ...
> }
> else
> {
> // form is not valid, send data to template of this form ...
> $properties = array();
> $warnings = array();
> foreach ( $definition as $name => $dummy )
> {
> if ( $form->hasValidData( $name ) )
> {
> $properties[$name] = $form->$name;
> }
> else
> {
> $properties[$name] = htmlspecialchars( $form->getUnsafeRawData(
> $name ) );
> $warnings[$name] = 'invalid_form';
> }
> }
> }
>
> I know it's already late in the release cycle for the 2008.1 release but
> could these two still make it into the next release? The code changes
> are really small and also no existing APIs are touched.
I can't promise it - but I will see whether I've enough time to do this
before the beta.
regards,
Derick
k
--
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components