Change default form error message

546 views
Skip to first unread message

Jim S

unread,
Jul 7, 2013, 1:09:35 PM7/7/13
to web...@googlegroups.com
If I have an error in my form the default error message is displayed.  It reads:

Errors in form, please check it out.

I want to change this globally to 'Submission failed!  Please review highlighted fields'.  Is there a way I can do this globally?

-Jim

shapova...@gmail.com

unread,
Jul 7, 2013, 1:30:14 PM7/7/13
to web...@googlegroups.com
Hi!

Try looking in languages/default.py or <lang-lang>.py.

Jim S

unread,
Jul 7, 2013, 2:01:52 PM7/7/13
to web...@googlegroups.com
Dang, why didn't I think of that.  Thanks, that is exactly what I needed.

-Jim

Alan Etkin

unread,
Jul 7, 2013, 4:19:31 PM7/7/13
to web...@googlegroups.com
Dang, why didn't I think of that.  Thanks, that is exactly what I needed.

This is better because you don't have to deal with the language files:

# process passes the kwarg to form.validate, so form.validate(message_...) is also valid.
form
.process(message_onfailure = T("Wait a minute! This bird wouldn't voom if you put four million volts through it!"))

This syntax is supported by FORM and SQLFORM, and CRUD methods. For .smartgrid and .grid, I think you have to use the formargs kwarg (a dictionary like {"message_...": <value>}

Jim Steil

unread,
Jul 7, 2013, 4:21:00 PM7/7/13
to web...@googlegroups.com
But then wouldn't I have to alter ALL of my grids/forms to override the message?

-Jim




--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/fUBLKVYdUZ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alan Etkin

unread,
Jul 7, 2013, 4:38:07 PM7/7/13
to web...@googlegroups.com
But then wouldn't I have to alter ALL of my grids/forms to override the message?
 
Oops, yes. For many forms, looks like the language file approach is better.

Alan Etkin

unread,
Jul 7, 2013, 4:46:05 PM7/7/13
to web...@googlegroups.com

But then wouldn't I have to alter ALL of my grids/forms to override the message?
 
Oops, yes. For many forms, looks like the language file approach is better.

BTW. I think this is an example of why CRUD should not be deprecated. It could be easily modified to support something like

crud = CRUD(db)
crud.messages.on_failure = ...

Anthony

unread,
Jul 7, 2013, 8:50:18 PM7/7/13
to web...@googlegroups.com

BTW. I think this is an example of why CRUD should not be deprecated. It could be easily modified to support something like

crud = CRUD(db)
crud.messages.on_failure = ...

I don't think we need CRUD just for that. We should allow something like that for regular forms and the grid as well.

Anthony 

Jim Steil

unread,
Jul 7, 2013, 11:17:39 PM7/7/13
to web...@googlegroups.com
The language file worked fine for me.  Is that not a good way to solve the problem?

-Jim



Anthony 

--

Anthony

unread,
Jul 8, 2013, 8:56:58 AM7/8/13
to web...@googlegroups.com
On Sunday, July 7, 2013 11:17:39 PM UTC-4, Jim S wrote:
The language file worked fine for me.  Is that not a good way to solve the problem?

Sure, but I'd call that a hack (looks odd to translate an English phrase to a completely different English phrase, plus adds an unnecessary operation -- why do a translation lookup when you don't need to?). I think it's reasonable to want to specify app-wide forms messages without having to repeat the relevant code for every form.

Anthony
Reply all
Reply to author
Forward
0 new messages