问题
How do I allow HTML to be submitted from textarea, I am really desparate on this, every answer I found gives me poor info, coz I don't have idea what to do.
I have this textarea:
<input id="mytextarea" name="mytextarea" type="text" value="" placeholder="<?php _e('iframe'); ?>">
or:
<textarea id="mytextarea" name="mytextarea" type="text" placeholder="<?php _e('iframe'); ?>"></textarea>
I want HTML to stay as it is after submission, in my case html is removed.
回答1:
The HTML tag only accepts plain (unformatted) text. Even if you add HTML to it, or try to format it, it will be removed. What you need to do is use a Rich Text Editor. There are many you can use, for example CKEditor and TinyMCE. You can use these editors in HTML mode (source code mode) and do what you’re trying to do.
回答2:
Textarea accepts any text to be stored in TEXT, VARCHAR etc. field in database. To see HTML formatted text use "html_entity_decode" in php.
For example to HTML format WP descripton:
In database - in wp_options table change 'option_value' field from VARCHAR to TEXT
In header change:
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
to
<h2 class="site-description"><?php echo html_entity_decode(get_bloginfo('description')); ?></h2>
In admin you can change
<td><textarea name="blogdescription" type="textarea" id="blogdescription" class="regular-text" cols="67" rows="7" /><?php form_option('blogdescription'); ?>"</textarea>
Now the 'textarea' stores all text you entered including HTML tags and you can see formatted text on your Blog header
Hope I got your point and it helps
回答3:
If you are using ejs you can format your tag like: <%- ... %> rather than <%= ... %>.
来源:https://stackoverflow.com/questions/17756573/allow-html-to-be-submitted-from-textarea-input