How would I add a prefix to a text field? For example, I have a field called "website" which is currently displayed like this:
website: ____________
Where _ is the input field. With the module "field markup" i can add prefix and suffixes but they apppear AFTER the _ or before the website part. I need to end up with:
website: http:// ____________
Any ideas how to do this?
You can use hook_form_alter to modify a textfield's #field_prefix (as opposed to #prefix). You could also use the CCK Link module to provide a proper URL field, that'll add http:// as necessary and validate the URL's format.
You have to do it using the '#after-build' mechanism so that CCK has already constructed the form elements.
<?php
function your_module_form_alter(&$form, &$form_state, $form_id) {
$form['#after_build'][] = 'your_module_form_after_build_function';
}
function your_module_form_after_build_function($form, &$form_state) {
$form['field_your_field_name'][0]['value']['#field_prefix'] = t('Example Prefix');
$form['field_your_field_name'][0]['value']['#field_suffix'] = t('Example Suffix');
}
?>
You may also need to adjust the CSS so that the text field doesn't clear (if you want your prefix or suffix to appear on the same line as the textfield).
See #after-build in the forms api reference:
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#after_build
Also the Form Builder module allows you to do this.
You can do it with Simple Field Formatter module, see the below screenshot
Which allows site administrators to easily control the display of
field values with following features
Prepend the field value with specified text/HTML
Append the field value with specified text/HTML
Reverse the Field Value
Trim the Field Value
Convert the field value to lowercase letters
Convert the field value to uppercase letters
Convert the first character of the field value to uppercase
Convert the first character of each word in the field value to uppercase (7.x-1.x-dev)
Replace some characters with some other characters in the field value (7.x-1.x-dev)
Link the field value to node(7.x-2.x-dev)
Related
I have a WordPress site with a form that people can fill out. The data is put into the database and used to create a simple one-page website. If the user wants to edit the website, the data is pulled out of the database and used to pre-populate the original form, where the user can change what they want and resubmit the form. The problem is that if the text entered into the form contains an apostrophe, as in "You'll love this product" when the text is read from the database and put into the value attribute for the input element, it displays in the form as "You\'ll love this product." An if that is submitted, the next time it comes back out of the database and into the form it's "You\\\'ll love this product.
How should I be handling this form text to keep these "\" escape characters from being generated and displayed?
Have you tried stripslashes(), regarding the line breaks just use the nl2br() function.
Example:
$yourString = "That\'s all\n folks";
$yourString = stripslashes(nl2br($yourString));
echo $yourString;
Note: \ double slashes will turn to \ single slashes
You should probably set-up your own function, something like:
$yourString = "That\'s all\n folks";
function escapeString($string) {
return stripslashes(nl2br($string));
}
echo escapeString($yourString);
I am trying to figure out how to make the replacement parts fields data show up in all uppercase when the email is received. This form will be used for entering serial numbers containing alphanumeric characters which makes it hard to read when lowercase letters are used.
Is there an override that can accomplish this or will the mailer template need to be modified? How would you resolve this?
Assuming the field has the id 'replacement-parts', add a custom script adapter with the key code:
request.form['replacement-parts'] = request.form.get('replacement-parts', '').upper())
Make sure it's above your mailer, as the action adapters are executed in folder-contents order.
How to escape multiline wordpress shortcode?
[accordion_item title="Item 2"]
item content
[/accordion_item]
We could use double brakets, but "/" sign brokes everything. Can't belive WP guys lost this case (
[[accordion_item title="Item 3"]]
item content
[[accordion_item]]
this works, but code below doesn't escaped properly
[[accordion_item title="Item 3"]]
item content
[[/accordion_item]]
Don't want to replace manually brakets with html codes. (and WP automatically get them back after user switch editor mode to visual)
Thanks in advance.
Function get_shortcode_regex() in shortcodes.php makes all logic with escaping shortcodes parsing (capture group 1 and 5)
For example with
[[new_something my_attr="test"]And have content!! [vc_tabs][/vc_tabs][/new_something]]
After preg_match_all you will get that
first capture group is not empty and it is "[" (so you can know that this shortcode is not for rendering)
second capture group will show shortcode name "new_something"
third capture group will show everything in attributes " my_attr="test""
four capture group will show content And have content!! [vc_tabs][/vc_tabs]
Five capture group will show that escape characters has at end.
Basically this means that all information is known when you write escape like this: [[your_shortcode]content[/your_shortcode]]
the Answer: replacing [ by [ and ] by ]
Link: https://wordpress.stackexchange.com/questions/33960/how-do-i-escape-a-in-a-short-code
Side Note:
Wysiwyg <=> text transition causing html encoding is, and always be a problem. I would recommend just getting rig of the visual editor all together!
i checked out the documentation for the replace filter in twig. my problem is that, suppose i have a variable say contvariable, and the content passed through that variable from the controller is dynamic
return $this->render('RodasysFormstudyBundle:Default:addclientname.html.twig', array('contvariable' =>$sometext));
this $sometext variable will contain texts like
$sometext='%Sun% rises in the East';
the text inside the %% should be displayed as an input field in the browser. I did not find any examples in the web like to replace the content inside the %% (what ever the content be whether its sun or the moon). Is this possible to do this using replace filter or should i follow some other method such as to replace the content in controller before sending it to twig..
please help..
You could do something like that (with the 'raw' filter) :
{{ "%foo% rises in the East"|replace({'%foo%': "<input type='text' name='"~foo~"' value='"~foo~"'/>"})|raw }}
foo is a variable sent by your controller, with the value of your choice.
I installed the String Overrides module and I have two entries in Site Configuration, one for Arabic and the other for English. I had put "Create Advertisement" inside of "Original field (English)" and some Arabic text inside "Replacement field." Nothing happened; no replacement was done.
I know there is something about wrapping the text in the t() function, but I do not know where to do it from. It is easy to do that in the case of replacing a field name but not here in this case. Can I have some help from you? I am using Drupal 6.19.
As reported in the project page, String Overrides can be used to replace anything that is passed through t(); if the English string is not used from any modules, you will not see the Arabic string being used.
If you are using "Create Advertisement" in your module, then the module should contain a call to t("Create Advertisement"). t() is case sensitive; if you are overriding "Create Advertisement," but the string used is "Create advertisement," then the string it will not be shown in Arabic.
I also think Arabic must be the language set for the page being shown.