Not a very snappy forum title, but it's difficult to explain in one sentence! ;)
I have used webform to create a contact form on my customer's site. You can see it at
http://www.lucy-connelly.com/mmu/contact .
There are several select-type input fields - eg. Title: Mr | Mrs | Ms etc.
I don't want any particular value to be selected to start with, so I have added the option "-select-" at the top of my list of values, and this is what's displayed in the select before the user chooses anything.
I want the user to enter a value in this field, so I have made it mandatory. But of course this doesn't work, as "-select-" is also a value - the user can just leave the field set to "-select-" !
How can I have no option or a dummy option displayed to start with, and still make the user select a real option?
Comments
This'll help
The solution, thanks to Salvatored: http://drupal.org/node/71047
Thanks - it's a start
Thanks Caesar - I think this is probably the right track, but I'm not quite there yet.
I have added the workaround, and added a taxonomy category with Mr, Ms, Mrs etc in it.
But the category appears on the contact form edit page (of course) and not the contact form itself.
So I guess I should be adding a similar workaround somewhere in the webform code, rather than the taxonomy code? (I don't really understand drupal very well yet.) Any ideas?
Lucy C
I don't use webform myself,
I don't use webform myself, so this is a small amount of guesswork... But if you look at the form id that creates the form, it'll have a form_id_submit and a form_id_validate hook with it. You can then use the validate hook to create a form_error if the form data returns "-select-".
Should work...
Pobster
*cough*
*cough* http://cvs.drupal.org/viewcvs/drupal/contributions/modules/webform/webfo...
Pobster
I confess I am confused by
I confess I am confused by the whole thing, but isn't this function used when filling in the form to *edit* the webform, rather than when filling in the form that webform *produces*? (my brain hurts ;)
Lucy C
Probably naughty solution
OK, I have done something nasty and probably naughty to fix this problem. In form.inc, function _form_validate, after
instead of salvatored's lines I have put
- so if I have an option "-select-" in my select field, it won't be allowed.
A bit dirty but I have to be pragmatic!
Thanks for everyone's help.
Lucy C
There's nothing wrong with
There's nothing wrong with doing it that way... The only downside to it is that you'll not be able to have "-select-" as valid on any form_select items not just the webform, which I guess isn't a downside at all... As that'd never be a selection you'd want anyway? Sleep well knowing that your 'naughty' fix isn't so naughty after all! ;o)
Pobster
This seems to work with the
This seems to work with the select lists, but for some reason no matter what I do, if I add a "select" component to my form, they are not being validated and even if nothing is checked, the form is allowed to be submitted...anything I'm missing here?
Later, I changed this
On some later testing I realised I had a couple of mistakes in this:
1) I left out the if($elements['required']) check, so it was checking all selects, even if they weren't mandatory
2) Complaining if an element value was 0 was unnecessary, as my selects have a value of "-select-". Checking for 0 was interfering with some other selects (eg. when trying to select "" as a forum parent.)
So I changed my edit to:
Lucy C
yep!
worked fine for me :) thanks!