[development] Skipping validation on date field

Randy Fay randy at randyfay.com
Thu Mar 17 17:20:58 UTC 2011


Without completely understanding what you're up to:

1. I think you should be using a date *element* to do this if you're not
already, so you validate the element as you would expect. But you probably
already knew that. (And doesn't the date module provide this?)  If not, and
you want to roll your own, form_example_elements.inc
<http://api.drupal.org/api/examples/form_example--form_example_elements.inc/6/source>in
the Examples Form Example shows how to do it. You could then use a
'#validate' function to short-circuit validation...

2. If you're already using a date element to do this, you probably need to
make a #validate that mushes the values into nothing when they haven't
selected anything. I suspect that you're currently getting a value that
doesn't equate to empty after you've changed those form elements.

Sorry if I've missed the point, but one of those two ought to help.

-Randy

On Thu, Mar 17, 2011 at 10:40 AM, Jeff Hartman <lists at jeffhartman.com>wrote:

> Sorry. Drupal 6.
>
> On Mar 17, 2011, at 11:38 AM, Randy Fay wrote:
>
> > Hi Jeff, and everybody: When you post a question like this, please say
> what version of Drupal you're talking about. The D7 answer to this question
> is a fair bit different from the D6 answer.
> >
> > -Randy
> >
> > On Thu, Mar 17, 2011 at 9:53 AM, Jeff Hartman <lists at jeffhartman.com>
> wrote:
> > I have a birthdate date field in a form where I am using #after_build to
> modify. The modifications to the drop down values are:
> > - add a "select month", "select day", and "select year" options to their
> respective drop downs
> > - change the range of years in the year drop down
> >
> > This field(s) is not required. However, if I don't select anything  in
> the drop downs and leave each on the "select month/day/year" values, Drupal
> validation tells me that the selected date is not valid.
> >
> > How can I tell Drupal to skip this validation? Even if I try to validate
> this field in hook_form_validate it still tells me the data is invalid.
> >
> > Jeff
>
>


-- 
Randy Fay
Drupal Module and Site Development
randy at randyfay.com
+1  970.462.7450
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110317/f3a8314b/attachment-0001.html 


More information about the development mailing list