我正在使用 ckeditor 来编辑屏幕上看到的文本。该信息从数据库中获取并写入 div 元素中的屏幕,并且可以通过双击来编辑信息。但是,编辑后我无法获取编辑后的信息。这是我的代码,我尝试添加一个包含 div 元素的表单,但它不起作用。
<form method="post">
<p>
Double-click any of the following <code><div></code> elements to transform them into
editor instances.</p>
<?php
$makeleSql = 'SELECT * FROM makale';
$makaleRs = $con->func_query($makeleSql);
while ($makaleRow = mysql_fetch_array($makaleRs)) {
?>
<div class = "editable" id = <?php echo "content".$makaleRow['id'];?> style="display:none">
<?php
$contentSql = 'SELECT * FROM content WHERE makale_id ='.$makaleRow['id'];
$contentRs = $con->func_query($contentSql);
while ($contentRow = mysql_fetch_array($contentRs)) {
echo $contentRow['icerik'].$makaleRow['id'];
}
?>
</div>
<?php }
?>
<button type="submit" value="Submit" onclick="getDiv();"/>
</form>
我应该怎么做才能获取div元素中的信息?此外,我正在使用这个例子。 http://nightly.ckeditor.com/7484/_samples/divreplace.html
谢谢。
最佳答案
要保存表单数据,您需要将信息存储在输入/选择/文本区域中。 div 和其他非 form 的元素不会被存储。
您必须将数据存储在隐藏字段中:
<form method="post">
<p>
Double-click any of the following <code><div></code> elements to transform them into
editor instances.</p>
<?php
$makeleSql = 'SELECT * FROM makale';
$makaleRs = $con->func_query($makeleSql);
while ($makaleRow = mysql_fetch_array($makaleRs)) {
?>
<div class="editable" id="<?php echo "content".$makaleRow['id'];?>">
<?php
$contentSql = 'SELECT * FROM content WHERE makale_id ='.$makaleRow['id'];
$contentRs = $con->func_query($contentSql);
while ($contentRow = mysql_fetch_array($contentRs)) {
echo $contentRow['icerik'].$makaleRow['id'];
// store original text
echo '<input type="hidden" name="'.$makaleRow['id'].'" value="'.htmlspecialchars($contentRow['icerik'].$makaleRow['id']).'">;
}
?>
</div>
<?php }
?>
<button type="submit" value="Submit" onclick="getDiv(this);"/>
</form>
<script>
var getDiv = function(btn) {
for(var el in btn.form.elements) {
var d = document.getElementById(btn.form.elements[el].name);
btn.form.elements[el].value = d.innerHTML;
}
return true;
}
</script>
关于php - 如何在表单中提交div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10578960/