frankindelicato
Member
Posted 2 years ago #
I have a textarea on an options page. When the textarea is re-displayed there is always whitespace added before and after the inputed text. The textarea is defined as:
<textarea name='ta_AdminContent' style='width: 80%; height: 100px; dir: LTR;'>
<?php
// _e(apply_filters('format_to_edit', $devOptions['content']));
echo sanitize_text_field($devOptions['content']);
?>
</textarea>
The original code used the apply_filters. I have tried these functions with the echo command:
//format_to_edit($content, true);
//format_to_post($content);
//normalize_whitespace( $str );
//sanitize_text_field($str)
Nothing seems to work. The database does not have any spaces stored with the input string? Any ideas?
Try removing all indenting from the code that you're using to echo the textarea data.
frankindelicato
Member
Posted 2 years ago #
Thank you esmi. I would have NEVER thought of that. That fixed it. I am used to writing C/C++ and not PHP SCRIPTS! Apparently the php processor is adding the whitespace (tabs) before the _e(apply_filters('format_to_edit', $AdminOpts['content']));
or the echo command I had before. Thanks again!
No probs. My local friendly plugin developer happened to read your post over my shoulder and mentioned that he'd had a similar problem that he'd eventually tracked down to the code indentation. So I figured it was worth passing on. Glad to hear that it helped.
oh my god, this has been bugging me for months, (all the while this post was sitting here and i never found it)... stupid *grumbles*
joshuascott94
Member
Posted 1 year ago #
Another way to solve this is by starting your PHP tags directly after the opening textarea tag and right before the closing textarea tag. This allows you to leave things indented the way they are.
I gotta have the indenting because it makes it so much easier to keep my code organized.
Here's an example:
<textarea><?php
TEXT
TEXT
?></textarea>