Hi,
Im a newb to drupal.
When i submit a registration form on drupal without filling the fields, i get
# Username field is required.
# E-mail address field is required.
# First Name field is required.
# Last Name field is required.
# Address 1 field is required.
# State field is required.
# City field is required.
# Zipcode field is required.

Those are mandatory fields.
How do i remove the big list and display "All mandatory fields are required" instead of displaying each and every field for required.

Thank u

Comments

matt2000’s picture

Component: forms system » profile.module
Category: task » support
Status: Active » Fixed

That's not possible in the core UI.

But assuming you're a coder and have grasped the basics of Drupal development:

You'll need to create a custom module implementing hook_form_alter to specify a new validation function, which will call form_set_errors with $reset=TRUE.

http://api.drupal.org/api/function/form_set_error/6
http://api.drupal.org/api/file/developer/topics/forms_api.html

Sandymaguire’s picture

Status: Active » Fixed
Sandymaguire’s picture

Status: Fixed » Active

Thanks matt for ur help...
It explains validation of all the custom made forms rather than the profile registration form which is out of the box in drupal.
I want to modify the registration form validation errors to be "All mandatory fields are req" rather than displaying errors stating
"... field is required"
"... field is required"
"... field is required"
"... field is required"
"... field is required"
"... field is required"
"... field is required"

thank u

stevenpatz’s picture

Priority: Critical » Normal
Status: Fixed » Active
matt2000’s picture

You can use hook_form_alter on pre-exisiting forms. That's its point.

http://api.drupal.org/api/function/hook_form_alter/6

When you call form_set_error() with $rest=TRUE, it should remove the 'default' error messages, so you can insert your own in their place.

The links I provided weren't intended to walk you through a solution; they provide the general background information you'll need to understand in order to implement the solution I suggested.

Everyone says Drupal has a steep learning curve, and everyone who follows through with it has said it was worth it.

Good Luck!

ainigma32’s picture

Assigned: Sandymaguire » Unassigned
Status: Active » Postponed (maintainer needs more info)

@Sandymaguire: Did you manage to implement your changes using matt2000's pointers?

- Arie

Sandymaguire’s picture

Actually No...
There was a variable $messages that holds the html code like

  • Name field is required
  • Password fields is required

It seems the value of $messages varies for each page.
Was working on how to break the $messages, put conditions and render our own messages.

matt2000’s picture

form_set_errors() populates $messages .

You're going about it the hard way, but if you really want to do that, use drupal_get_messages() :

http://api.drupal.org/api/function/drupal_get_messages/6

But really, use hook_form_alter() and form_set_errors(). Anything else is a waste of time that you will probably regret later.

ainigma32’s picture

@Sandymaguire: Any luck in resolving this issue yet?

- Arie

Sandymaguire’s picture

No, im still working on it..

maxferrario’s picture

I have a far from perfect solution, but it works for me (I'm using drupal 6).
In the "Webforms advanced Setting"/"Additional validation" field of the webform put the following code:

<?php
// if the form raised one or more errors, $hashFormErrors will be populated
$hashFormErrors = form_get_errors();

// delete ALL drupal errors
drupal_get_messages('error');

// now add your own error message
if (! empty($hashFormErrors)) {
    form_set_error('', t('Please check the highlighted fields.'));
}
?>

Please note that this code suppresses the output of every Drupal error, not only errors raised by the webform module nor "mandatory field" errors only. So you will have to validate some fields by yourself, as all the messages from the module are gone.

Hope this helps.

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Closing this issue because of a lack of activity.