在表单提交上发送div的值 [英] Send value of div on form submit

查看:57
本文介绍了在表单提交上发送div的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提交包含几个不同输入的表单,这些输入都可以正常工作.但是,输入之一是文本区域(某种).我不得不将其更改为内容可编辑的div,这主要是因为我创建了自己的粗体,斜体和下划线按钮,这些按钮不适用于普通文本区域.问题是提交时的表单没有将文本发送到php,我想知道如何才能在php中获取div的值.

I am trying to submit a form with a couple of different inputs, which all work fine. However, one of the inputs is a textarea (sort of). I had to alter it into a content editable div, mainly because I created my own bold, italic and underline buttons which wouldn't work with normal textareas. The problem is that the form on submit is not sending the text to the php and i was wondering what i could do to get the value of the div in the php.

这是文本区域":

<div id="dash_new_shout_textarea" name="dash_new_shout_textarea" 
     class="dash_new_shout_textarea" contenteditable="true" 
     placeholder="Write your shout..." name="dash_new_shout_textarea" 
     value="<?php echo isset($_POST['dash_new_shout_textarea']) ?
     $_POST['dash_new_shout_textarea'] : '' ?>"></div>

该表单只是带有method = post的普通表单.

The form is just a normal form with method=post.

这是php:

$newShoutTextarea = $_POST['dash_new_shout_textarea'];

感谢您的帮助

推荐答案

您可以做的是这样:

<div id="dash_new_shout_textarea"></div>
<input type="hidden" name="dash_new_shout_textarea" id="dash_new_shout_textarea_hidden" />
<script type="text/javascript">
setInterval(function () {
  document.getElementById("dash_new_shout_textarea_hidden").value = document.getElementById("dash_new_shout_textarea").innerHTML;
}, 5);
</script>

这篇关于在表单提交上发送div的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆