3

I have a webform that contains a date field. I need to run some code that checks to make sure the date is not already in use (i.e. that no one else has submitted a webform with that particular date). I already have the webform validation module installed, and I know I could use that (create a custom module with custom validators), but the validations don't run until the form is submitted. Because there's a required file upload, I'd rather be able to allow the user to check if the date is available before doing the upload.

Is this possible? How would I go about it?

1

You have to use AJAX to check if the date is available.

In your form add a button to check for the date, for example:

  $form['submit-check'] = array(
    '#type' => 'submit',
    '#value' => '('Check date'),
    '#ajax' => array(
      'callback' => 'mymodule_check_date_callback',
      'wrapper' => 'datecheck-result-wrp',
    ),
  );

When user clicks on the button, an AJAX call is made. inside the AJAX callback you can check the date availability and return the result in the callback fucntion (mymodule_check_date_callback() in the above example).

AJAX forms are beyond a simple answer, you'll have to check the documentation. I recoomend the Drupal 7 AJAX Forms documentation, the Example for Developers module that includes AJAX form examples and the Form API Internal Workflow Illustration

0

You could look at doing it through the Clientside Validation module, which also works with Webform/Webform validation. Since this module's validation is client-side, you can give feedback sooner rather than later. Please note that I don't know off the top of my head whether it supports out-of-the-box the specific date-checking functionality you are looking for.

  • I looked at that, but the issue isn't that date is a complex field type, it's that I need to do a database query to get the value to validate against. I don't know that this module supports that any more than the webform validation one does. – EmmyS May 8 '12 at 15:39
  • In that case, what about just making a separate little widget to check the date first? Then, if it validates, it redirects to the webform and prefills the value; if not, it prompts you to input another day. – Patrick Kenny May 8 '12 at 15:44
  • That sounds like it would do what I need. I'm pretty new to Drupal - how would I do that? – EmmyS May 8 '12 at 15:46
  • That would require writing some custom code which is beyond what I can provide here as part of my answer. Perhaps someone else knows how to get what you want using one of the contributed modules. – Patrick Kenny May 8 '12 at 15:48
  • I'm not asking you to write the code, but what would be the basic setup? A custom module that displays a form in a block? – EmmyS May 8 '12 at 15:59
0

A possible approach might be to use the Availability Calendars module, and then take advantage of the Webform integration of this module (from its project page):

Kick off booking process for customers (booking formlet sub-module):

  • Select start and end date in the calendar itself and click "book now".
  • Prefilled start and end date based on e.g. an earlier availability search.
  • Integrates with webform for further booking details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.