Wonder if anyone else is interested in this...
I think I got it part way,,, code still ugly not working yet, likely a noob mistake in it.
I think it would be useful to be able to validate that webform component is not a day of the week
and maybe later similar not a date....
Anyone else interested... maybe I'll sandbox if we get further...
cat webform_validation_notday.module
function webform_validation_notday_webform_validation_validators() {
return array(
'not_day' => array(
'name' => "Not Day of Week",
'component_types' => array(
'date',
),
'custom_error' => TRUE,
'custom_data' => array(
'label' => t('Day of week not accepted'),
'description' => t('Insert one Day of week not accepted, Sunday - Saturday')
),
'description' => t('Validates that date is not a specific day of the week for example you may be closed Monday.'),
),
);
}
function webform_validation_notday_webform_validation_validate($validator_name, $items, $components, $rule) {
if ($items) {
$errors = array(); // may not want this line, since it is in the webform_validation module orig.
switch ($validator_name) {
case 'not_day':
$notday = _webform_notday_check_data($rule['data']); // use function to verify good day to validate with;
foreach ($items as $key => $val) {
// test val, see if val is a day of the week not allowed, if so set error.
//$dw = date( "l", strtotime($val));
if ($dw = $notday) {
$errors[$key] = t("%item is a day of the week, $notday, that is not valid", array('%item' => $components[$key]['name']));
}
} //end foreach
return $errors;
break;
} //end switch
} //end if
} //end function
/**
* Process the day value provided in the not_day validator options
*/
function _webform_notday_check_data($data) {
$daysINweek = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
// if no value was specified, nothing to validate
if ($data == '') {
return $data;
}
// if value does not matches day of week return Notaday for now, later make an error thingy?
if (in_array($data, $daysINweek)){
return $data;
} else {
$data = "Notaday";
return $data;
}
}
Comments
Comment #1
webengr commentedOMG... :)
it sort works now... ignore the above code...
big thing I assumed was the value stored for date component was in a date format,
but it is not, it is in array like
Array ( [year] => 2012 [month] => 2 [day] => 16 )
which needs to implode before comparing with php date function.
cat *.module
Comment #2
webengr commentedOKAY, while it would be great to not even allow input of unwanted dates or days..
at least here may be a way to not validate them.
sandbox for module that does NOT DAY:
http://drupal.org/sandbox/webengr/1429582
sandbox for module that does NOT DATE:
http://drupal.org/sandbox/webengr/1429636
Comment #3
webengr commentedI put two sandboxes up for validating against day of week and against a date.
I am changing from support request to feature request. If you think these features
should not be part of webform validation, then later I will consider changing the sandboxes to full projects.
-tia.
Comment #4
Andino commentedTia -
This very issue has been driving me nuts for the past two months, to the point where I was prepared to programatically generate new webforms (and views) for each possible date. What would be great would be if they included this code with a date picker (for yes and no days) in the validation module. Thanks for this!
Comment #5
webengr commentedthanks...
I have not heard anything about it going into core..
If I do promote to full project, I would leave it "dev" for a long while till some more people pound on it.
I doubt the code is robust nor elegant... but it does seem to work for me. Let us know if you find
issues.. like timezones etc...
Likely the pattern matching could be better and use GNU formatting for day of week also....
.. wonder if it could have select radials and list the seven days... rather than having to use it upto 6 times to blackout
all but one day of week...
Comment #6
webengr commented.... erase ....
---------- weird, it double posted ---------
Comment #7
liam morlandPlease provide this code as a patch.
Comment #8
webengr commentedAgreed a patch should be considered,
Like putting the bell on the cat, this mouse was 2 busy.... IF someone wants to make the patch - go ahead and let us know... else maybe in the future I will get around 2 it, but not for a couple months.
Comment #9
skalmes commentedI'd like to support the statement Andino made above,
I'm working on a form where I have to validate against a weekly closure daty (sunday) but would as well like to validate against a date field against a content type where I have a date field for holidays as well, with a mixture of non-repeating and repeating dates.
While that last one may be a step to complicated for me, the option to have only dates pickable and validated on the allowed weekdays would certainly get me in a satisfactory direction.
I wonder why I can't seem to find more questions for a feature like this. Nor approaches to my dissapointment...
I'm trying this one for sure, it's as you say at least a validation rule that certainly is useful, while it would be perfect to be able to have control over the input on the datefield (and have a datepicker to visualize valid dates).
Comment #10
liam morlandI think what you are asking for can be done with the specific values validator and the negate option.