Hi,
I am using profile date field on the registration form, the field is required and i want the default option which is listed to be day, month, year instead currents day.
I tried using the hook_form_alter, but when printing the $form it doesn't gives the options for the date field.
I have searched in the forums found this post http://drupal.org/node/223845, which is drupal core hack.
The solution which looking for is an extended module (form_alter or some other hook).
Also in years it gives the listing of years till 2050, I did some research and found a function in form.inc which i think will take care of this but don't know how to proceed with this.
Could anyone please help on this.
Regards
Sagar
Comments
I have same problem few days
I have same problem few days ago, and spent 2 hours finding a solution.
Never hack the core!!!
Date element is parent of three child select element and you need to set your own process function, just like override theme function
in my example only older than 14 can register:
Thank you for helping me, it
Thank you for helping me, it Works for the date range.
My first issue was to show 'Day' , 'Month' and 'Year' as the default option listed if nothing is selected.
The code which you have provided list the date as 19 may 1996.
My profile date has been set to required, could please help me with this also.
Regards
Sagar
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
the fix...
I didn't like the date fields populated with the current date. It looks like the field is already filled out and a lazy user can just skip the field. Here's my method. The form will fail validation if the date field is not touched by the user, so this will make the field a required field.
The previous poster provided the information you need to make the fix but I made a few changes to minimize code. It's a two-step process. First, you need to add 'day', 'month' and 'year' to the options lists. Second, you need to set them as the default value.
I used hook_form_alter() on the actual user profile form so it doesn't get called on every form. Replace ['Personal information']['profile_birthdate'] with the your actual category and field name.
The drupal function expand_date() is used to create and populate the drop down list. It works well, so I reused it but altered the output to prepend the new default values to each array and remove the years that are in the future, which don't make sense for a birthdate field.
Hope this helps you...
This is exactly what I'm
This is exactly what I'm looking for. Unfortunately, from just your code snippets, I'm not sure exactly how to implement the changes. Where should I be inserting/modifying this code?
Any help is appreciated!
Hi, You need to create a
Hi,
You need to create a module and paste this code in .module file. For more info on developing module check this out :
http://drupal.org/developing/modules
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
Quite simply, thank you :-)
Quite simply, thank you :-)
Some notes on this usage:
Two problems:
First, the default values you are setting are strings. checkdate(); will not play nice with these and serve an error like "warning: checkdate() expects parameter 1 to be long" So change the strings to:
Also a date of 0/0/0 will not validate. So if someone decides not to share their birthday, the form will serve an error. This is fine if profile_birthdate is a required field, but if you want to make it optional you'll have to remove or change validation on the element.
Removal by setting it to an empty array is a quick and dirty fix but it is a security problem.
Better yet, provide your own date validation that accepts 0/0/0 as a valid date.
See http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.... for information on writing custom validation hooks in D6.