2

I am making an edit form in wordpress. This is my code. My trim() function is not working.

<div class = "input-group">
    <label for = "business_meta_title"><?php _e('Meta Title', 'wcd');
?></label>
    <textarea type="text" name="business_meta_title" id="business_meta_title" class="form-control">
        <?php echo trim(get_field('business_meta_title', $deal_id)); ?>
    </textarea>
</div>

<div class="input-group">
    <label for="business_meta_description"><?php _e('Meta Description', 'wcd'); ?></label>
    <textarea type="text" name="business_meta_description" id="business_meta_description" class="form-control">
        <?php echo trim(get_field('business_meta_description', $deal_id)); ?>
    </textarea>
</div>

<div class="input-group">
    <label for="business_meta_keywords"><?php _e('Meta Keywords', 'wcd'); ?></label>
    <textarea type="text" name="business_meta_keywords" id="business_meta_keywords" class="form-control">
        <?php echo trim(get_field('business_meta_keywords', $deal_id)); ?>
    </textarea>
</div>

I am getting output like this.

enter image description here

Any thoughts? What should I do?

Ali Zia
  • 3,825
  • 5
  • 29
  • 77
  • 1
    `trim()` has nothing to do with it. `trim()` just removes leading and trailing whitespaces from the returned text of the php function/variable. What you have is a styling issue, not a php issue – Pieter Goosen Jan 19 '16 at 07:44
  • 1
    remove spaces in `textarea` `` see http://stackoverflow.com/questions/2202999/why-is-textarea-filled-with-mysterious-white-spaces – Tintu C Raju Jan 19 '16 at 07:44
  • Thankyou so much. It worked. – Ali Zia Jan 19 '16 at 07:52

3 Answers3

2

Please re-write your textareas by having no spaces in them, trim works fine but you are adding the extra spaces after opening textarea tag in your HTML:

<div class = "input-group">
    <label for = "business_meta_title"><?php _e('Meta Title', 'wcd');
?></label>
    <textarea type="text" name="business_meta_title" id="business_meta_title" class="form-control"><?php echo trim(get_field('business_meta_title', $deal_id)); ?></textarea>
</div>

<div class="input-group">
    <label for="business_meta_description"><?php _e('Meta Description', 'wcd'); ?></label>
    <textarea type="text" name="business_meta_description" id="business_meta_description" class="form-control"><?php echo trim(get_field('business_meta_description', $deal_id)); ?></textarea>
</div>

<div class="input-group">
    <label for="business_meta_keywords"><?php _e('Meta Keywords', 'wcd'); ?></label>
    <textarea type="text" name="business_meta_keywords" id="business_meta_keywords" class="form-control"><?php echo trim(get_field('business_meta_keywords', $deal_id)); ?></textarea>
</div>
Saqib Amin
  • 1,171
  • 7
  • 16
1

Use without spaces between value in tag as:

<textarea type="text" name="business_meta_keywords" id="business_meta_keywords" class="form-control"><?php echo trim(get_field('business_meta_keywords', $deal_id)); ?></textarea>
devpro
  • 16,184
  • 3
  • 27
  • 38
0

I suggest you two changes point which may solve your issue:
1. If you working with wordpress then please use wordpress provided wp_trim_words instead trim().

2. Remove spacing between value and <textarea> tag

wp_trim_words() function trims text to a certain number of words and returns the trimmed text.

Community
  • 1
  • 1
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • 1
    `wp_trim_words()` and `trim()` is completely different. `trim()` removes leading and trailing white spaces from a string, `wp_trim_words()` trim the amount of words in a string, it does not remove white spaces in the beginning and end of a string. Your answer is totally wrong – Pieter Goosen Jan 19 '16 at 07:49