在表单提交时发送 div 的值

Ark*_*ken 6 html javascript php

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

这是“文本区域”:

<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>
Run Code Online (Sandbox Code Playgroud)

表单只是一个普通的表单,带有method=post。

这是PHP:

$newShoutTextarea = $_POST['dash_new_shout_textarea'];
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助

Luc*_*emy 1

你可以做的是:

<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>
Run Code Online (Sandbox Code Playgroud)