Stop input field code from being escaped in SilverStripe - silverstripe

I have a text field that needs to have code posted in it. Unfortunately in SilverStripe the code is automatically escaped, which just shows that code itself in the front end.
Is there a way to make it execute the code instead?
I have tried the following:
public static $db = array(
'Code' => 'Text'
);

Okay found a way to do this you need to append a RAW method to his in the template, like so : $Code.RAW

I think an alternative solution to this would be to make the type of your field HTMLText instead of Text. In that case you wouldn't have to use RAW.

Related

Wordpress text editor input validation. Prevent save when certain characters are used on input

I'm trying to create a function on my theme's functions.php file that accomplishes that goal.
I want the editor to prevent saving or updating new posts when certain characters are used on the editor. Characters like non-breaking space, certain brackets and aposthrophes and encoded html entities.
I've managed to create a function to sanitize the input after the post was saved to the database, getting rid of all these undesired characters. I did this by writing a function that includes
$wpdb->update('wp_posts', ['post_excerpt' =>$sanitized_post_excerpt], ['id' => $post_id]);
and then adding the function as a hook to save_post:
add_action('save_post', 'sm_sanitize_HTML_entities', 99, 3);
Is there a way to prevent the input of the characters being saved (maybe even displaying a message to the user), rather than updating a sanitized version of the data after it's already been saved?
What da butt? enter code here
Blockquo [enter link description here][1]
Olá
[1]: https://%20xpt.

Drupal 7 path_save with a query arguments

I've searched all over for examples of this, but I haven't found any. I'm trying to create an alias for path which includes query arguments, like profile?arg1=113.
It doesn't matter if I provide path_save() with the plain string representation of the path, or if I provide it with url().
url('profile', array('query' => array('arg1' => $uid)))
Either way, ? and = show up as escaped characters on the URL aliases admin page, which naturally means the path can't be found.
How can I keep the ? and = from being escaped?
12/19/12 Edit 1: the larger context is that I'm trying to set up the alias when a Profile2 profile is being saved (i.e., in mymodule_profile2_presave()) - that's when I'll have all the information I need to programmatically set up the alias.
12/19/12 Edit 2: I just realized that the problem isn't on the insert side - the url_alias table actually has unescaped characters in it. The problem is that Drupal doesn't urldecode the path before using it...
12/20/12 Edit 3: Found a solution using Redirect instead of path aliases. Redirect properly decodes the query string!
You cannot attach the query string to the destination of an alias. The code executed from drupal_path_initialize() doesn't handle the query string correctly.
The function contains the following code.
$_GET['q'] = drupal_get_normal_path($_GET['q']);
Suppose that you have "example" as path alias that points to "node/93?uid=1"; that code would set $_GET['q'] to 'node/93?uid=1', while you are expecting $_GET['q'] to get 'node/93', and $_GET['uid'] to be set to 1.
What you could do is implementing hook_inbound_alter() with code similar to the following one.
function mymodule_url_inbound_alter(&$path, $original_path, $path_language) {
list ($path, $query) = explode('?', $path);
$_GET += drupal_get_query_array($query);
}

I want to use the question mark in the auto-generated path aliases

I want to use the question mark the automatically generated path aliases, but when I write the question mark, it is changed to %3f.
How can I fix this?
The URL you are trying to use appears to be used as a proper delimiter of path vs. query string. You should not attempt to add the question mark yourself, but instead implement the section after the question mark as query string. For example:
l(t('My Link'), 'campaign/resurfacing-seminar', array(
'query' => array(
'campid' => '70150000000Tbdk',
'eloqua' => 'SEM-110604-SyracuseNY-Lowe',
),
));
Drupal's url() function is better if you are incorporating it in a form action or a drupal_goto() function.
Here is the link to the function explanation:
http://api.drupal.org/api/drupal/includes--common.inc/function/url/6
You really can't if you want things to work correctly. The "?" is a special character that signifies the end of the URI and the beginning of the query string. Doing what you suggest would break a lot of your other drupal pages.

Can't read output of httpservice

I have an HTTPservice
id="myhttp"
url="site.com/script.php"
method="POST"
resultFormat="xml"
The script it uses returns
$output = '<worked>' . $worked . '</worked>';
echo $output;
Problem is when I try to read worked, it tells me the variable worked is not there
event.result.worked
myhttp.lastResult.worked
The only thing that works is using toString()
myhttp.lastResult.toString()
or event.result.toString()
What am I doing wrong?
I plan to add other variables to the output time, so need to access each time and worked separately.
I may also need to return multiple responses each with their own worked and time values. How do I do that. I was thinking to not use XML. Is there a more lightweight option. Flex shows I have the following options: array e4x flashvars object text xml
You should use e4x as your return type. By declaring your return type as xml, you tell flex to handle it as an XMLNode, which is legacy and shouldn't be used.
If you need to use XMLNode for some unknown reason, you can get the value of the text by using event.result.nodeValue.
Should your return type be e4x?

CCK field prefixes?

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)

Resources