Opened 9 years ago
Closed 6 months ago
#40786 closed defect (bug) (invalid)
Leading spaces are added to custom textarea metabox
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | administration | Cc: |
Description
I am using esc_atr(ltrim(rtrim(br2nl($meta_value)))) to place the value of post meta in textarea metabox I have created in my custom post type.
<textarea id="<?php echo $id_name; ?>" name="<?php echo $id_name; ?>" rows="7" cols="80" style="width:100%" maxlength="<?php echo $maxlength; ?>" placeholder="<?php echo $placeholder_text; ?>" <?php if($is_required){ ?>required<?php } ?>> <?php echo esc_attr(ltrim( rtrim( br2nl($input_value)) ) ); ?> </textarea>
But whenever I go to edit the post, inside all textarea metaboxes values are pre-loaded with leading spaces (exactly 10 spaces) and additional line breaks!
Also tried esc_atr(trim(br2nl($meta_value))) with no avail.
Attachments (1)
Change History (5)
#1
@
9 years ago
- Resolution set to invalid
- Status changed from new to closed
Hello @subrataemfluence,
Sorry for the trouble you currently have but this Trac is only used for enhancements and bug reporting for the WordPress core software.
Our support forums are a better place to get help with your issue: http://wordpress.org/support
#2
@
9 years ago
- Resolution invalid deleted
- Status changed from closed to reopened
I believe this is something related to core. I did not use any plugin to create the custom post type and it was done pure WP way.
#3
@
9 years ago
You should remove new line or space between the <textarea> open tag and textarea content
<textarea>Hello world</textarea>
instead of
<textarea>
Hello world
</textarea>
#4
@
6 months ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from reopened to closed
- Version 4.7.5 deleted
You cannot simply add HTML code with the identation you like in the code and not find unexpected behaviour like this. As @truongwp has commented, one solution is just doing a one liner for the textarea part
Another solution is to use ob_start
Like this:
ob_start(); echo esc_attr(ltrim(rtrim(br2nl($input_value)))); $textarea_content = ob_get_clean(); echo trim($textarea_content);
Inside the textarea section, then you can maintain your textarea indentation.
Closing this ticket as its more of a support ticket for the forums than an issue for Trac.
Leading spaces and extra line breaks