I have questions on my form that end in a questions mark, however it seems to automatically add a colon at the end of every label, so each of my questions ends in "?:"
How do I stop it from adding the colon?
Thank you for your help.
I have questions on my form that end in a questions mark, however it seems to automatically add a colon at the end of every label, so each of my questions ends in "?:"
How do I stop it from adding the colon?
Thank you for your help.
Comments
Comment #1
cybermache commentedPaste this in your template.php in 'sites/all/themes/your_theme/' replacing 'theme' with the title of your theme folder.
Original code can be found in includes/form.inc
it looks like this
This will be a site wide change affecting all forms the same way. I just add ':' when I need to. Works out well for me. I've only tried this on 5.x but this is code from 6.x and should work the same way. Hope this helps.
Comment #2
flavor commentedI tried this it creates an error tells me that the function has already been declared in includes/form.inc and cannot be redeclared in template.php
Comment #3
kvbbro commentedTo follow this suggestion for making a site wide change then you would need to make the change to the includes/form.inc file itself. Just remove the colon after !title: in the theme_form_element() method (2 places).
Comment #4
Anonymous (not verified) commentedI think that you probably just didn't change the function name to replace 'theme' with your theme's name. Hacking core is never a good idea.
Comment #5
cybermache commentedSorry, flavor
If I wasn't clear in the beginning. The error you received telling you that that function has already been called is because both functions are titled the same. So to be more specific you must replace the 'theme' part of theme_form_element with the title of the folder in which your active theme is kept. So if your theme folder is titled "nancy' then your function in your template.php file should look like this "nancy_form_element". If you wanted all active themes to use this function then 'theme' should be replaced by 'phptemplate' (instead of 'nancy' in this example) and I believe the template.php file should be outside the individual theme folders but inside the sites theme folder. Glancing at the Drupal handbook on theming should clarify that. Of course it's also functional to paste this in each theme's template file also, just more to manage that way.
Hope this helps
Comment #6
amanda commentedThanks, by the way.
I'd like to figure out how to apply this only to forms generated by the webforms module but it is a huge start.
Comment #7
decibel.places commentedThis method does not work for me either, to remove colons from the field labels in webforms
I hacked the includes/form.inc code to remove the colons, removing the colons from $t('!title: to make them $t('!title in function theme_form_element lines 2202 and 2205, ( http://drupal.org/node/376345 ) but of course that was lost upgrading to core 6.11
so I devised a DHTML method - paste this script into the webform body
I suppose this snippet could also go in a theme file, probably page.tpl.php
I only have one webform, so it is more efficient for me to put the code in the webform body
Comment #8
cdale commented#201941: How to remove punctuation from the end of a form field label?
Comment #9
cdale commented#201941: How to remove punctuation from the end of a form field label?
Comment #10
decibel.places commentedsorry, I'm not sure what these last two posts mean
this is not a duplicate of #201941, although I posted there first about hacking the form.inc file
I pointed to the DHTML code I posted here from that thread, as this thread is more on the topic of my issue
Comment #11
esmartwave commentedThis was super helpful. I dropped it into the body and it works great. Thank you.
Comment #12
mineshaftgap commentedFor those where this is not working, don't forget to flush your cache!
Comment #13
halloffame commentedI only want to get rid of the colon that goes along with "Username:" and "Password:" in the login field not make a site wide change.
Comment #14
tordrup commentedHere's a javascript solution that only removes the colon if the label contains a question mark. (#7 removes all colons).
Comment #15
jdwfly commentedThank you to cooperwd in #14. Works great.
If you have trouble getting it to work make sure to check your input filter settings. I had to set mine to none for the script to work properly.
Comment #16
decibel.places commentedre: filters
enabling the PHP filter for admins then setting input format to PHP filter default usually works
@#14 nice use of replace function, but I would test for presence of ":" rather than "?" before invoking it
Comment #17
tordrup commentedThanks decibel.places! But I'm confused. The module appends a colon to the end of every label, so why test for the presence of a colon? Instead, we want to test for the presence of a question mark -- only then do we want to remove the colon. Maybe I'm misunderstanding?
Comment #18
decibel.places commented@#17 - you're absolutely correct, cooperwd
testing for "?" is necessary to remove the colon after question mark
although we can "assume" that your module adds a colon always, I still think it's good practice to test for it too to prevent unexpected problems - I've seen assumptions break many routines
Comment #19
ruplThe fix in #1 works as of Drupal 6.14, thank you!
Comment #20
sakiland commentedIf you want to remove colon on specific label, here is jQuery code (example for two text field):
Just set $('#edit-....-wrapper > label') to appropriate id of textfield.
Comment #21
xjmTracking.
Comment #22
birdy commentedThe script from sakiland applied on all label in a form :
Comment #23
awm6392 commentedI used this snippet in #7 in my webform and it worked perfectly except for one problem: i have a label without text in it (value = ). this was the main reason i was looking into this issue in the first place. this method removes all colons except for the label without any text in it, which just appears as a colon with nothing else next to it. how can i fix this?
Comment #24
decibel.places commented@awm6392 #23
I suspect that #7 has a problem with blank labels and length
try #22 which does not rely on length. It assumes you have the jQuery library loaded, which is added in a Drupal installation in the misc directory.
Comment #25
szstar commented#22 works great - thanks birdy! Don't forget to replace "#myform-id" with your own
Comment #26
flamingvan commentedHere's my non-JavaScript solution to remove the colon only from webform fields. This code goes in your template.php file and you need to replace "mythemename" with your theme name in the function declaration. It works for me in Drupal 6.11
Comment #27
lsancheztapia commentedHello :
I solved using this jquery code:
Regards,
Luis.
Comment #28
BenPoole commentedSolution #1 worked great (using Drupal 6), thanks! And yes, as mentioned above, don't forget to do two things:
1) In the first line, replace the function name: "mytheme_form_element($element, $value)", with your theme's name like this: "mytheme_form_element($element, $value)"
2) flush your cache
Greatly appreciated,
Ben
P.S. The JQuery solutions looked good as well, except for one thing - don't they strip out colons that are supposed to be there, too?
Comment #29
msathesh commented@flamingvan thanks for the code
Comment #30
iamjon commentedI landed here when looking to remove colons, it seems there is now a module for this
http://drupal.org/project/no_colons
Comment #31
dineshpal commentedNice, Very usefull posting thanks so much for share this.i used this and its working well.once again thanks so much.
Comment #32
vikramaditya234 commentedthanks all, this post really helped :)
i tried #1 (read #28) and #14 both worked
Comment #33
doublejosh commentedBTW: http://drupal.org/project/no_colons
Comment #34
aubjr_drupal commentedI didn't want to deal with testing and getting an entire module into a production environment (with weekly updates) just to get this kind of functionality to work, and I liked the jQuery solution in #22 here. I wanted to improve on it a bit in order to:
Here's my solution (using regex):
If you want to remove the last colon from all the elements, this should work as well:
Caveats: 1) I'm using a Zen subtheme in D6 along with the Webform module, so your [selector] may vary. 2) I didn't do any kind of performance testing on it (assuming the .replace function with regex is slow).
Comment #35
GregoryM commentedDrupal 7
I came across this thread looking to make a modification in my custom template (much better than a jQuery solution if you can cope with writing templates). However the function will not work in Drupal 7+ as the $value parameter has been dropped.
See http://api.drupal.org/api/drupal/includes!form.inc/function/theme_form_e...
Copy the code into your template.php file, rename the function to YourTemplate_form_element, make desired changes, and you're done.
I actually wanted to swap the label and the element order around. This seems to be done via a setting, but I have no idea where to change that setting in the admin so I've hard-coded it.
Comment #36
sstedman commentedRe: #14 tordrup, you are my hero! I love Drupal and everything, but this is one very aggravating choice baked into Drupal, with the only workarounds being extremely heavy-handed. I'll borrow your lightweight script and call it a day.