Submit div value to form submit

I am trying to submit a form with several different inputs that all work fine. However, one of the inputs is a text box (sort of). I had to change it to content edited by a div, mainly because I created my own bold, italic, and underlined buttons that won't work with regular text fields. The problem is that the form on submit does not send text to php, and I was wondering what I can do to get the div value in php.

Here is the "textarea":

<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>

A form is just a normal form with the = post method.

Here is the php:

$newShoutTextarea = $_POST['dash_new_shout_textarea'];

thanks for the help

+4
source share
5 answers

, :

<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>
+2

jQuery, jQuery, , , jQuery.

HTML

<form onsubmit="prepareDiv()">
    <div id="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>
    <input type="hidden" id="dash_new_shout_textarea_hidden" name="dash_new_shout_textarea" />
</form>

Javascript

function prepareDiv() {
    document.getElementById("dash_new_shout_textarea_hidden").value = document.getElementById("dash_new_shout_textarea").innerHTML;
}

PHP .

+1

, DIV . - javascript, , POST

0

jquery

<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="></div>

<form id="target" method="post" action="destination.php">
  <input id="textarea_hidden" name="textarea_hidden" type="hidden" value="">
  <input type="submit" value="Submit">
</form>

script

$("#target").click(function() {
  $("#textarea_hidden").val($("#dash_new_shout_textarea").val());
});
0

, jQuery .

:

* div . *

This must be done when submitting the form:

$(function () {
    $("#send").on("click", function () {
        $("#hiddenfield").val($("#dash_new_shout_textarea").text());

        alert($("#hiddenfield").val());

        $("form#formID").submit();
    });
});
0
source

All Articles