TJTech
TJTech

Reputation: 19

Can't send contents through POST when in div rather than input/textarea

I want to send the contents of a div using php's post method but can't use a textarea or input as the text editor the contents is in no longer takes affect. The solution will either lie in a tag that can have the 'name' attribute applied to it or another method of sending through post.

Already tried textarea and input.

This is what I've tried:

  <div id="texteditor" name="long_description" maxlength="5000">
      <textarea type="text" name="long_description" style="border: 1px solid black; background: transparent; outline: 0; width: 100%; height: 100%;" value="

      <?php
            if(isset($_SESSION['project_details'])){
              echo $_SESSION['project_details']['long_description'];
            }
          ?>

        ">
      </textarea>
    </div>

I've also tried:

<div id="texteditor" name="long_description" maxlength="5000">
      <input type="text" name="long_description" style="border: 1px solid black; background: transparent; outline: 0; width: 100%; height: 100%;" value="

      <?php
            if(isset($_SESSION['project_details'])){
              echo $_SESSION['project_details']['long_description'];
            }
          ?>

          ">
      </input>
  </div>

This was the first thing I did:

<div contenteditable="true" id="texteditor" name="long_description" maxlength="5000">
    <?php
        if(isset($_SESSION['project_details'])){
            echo $_SESSION['project_details']['long_description'];
        }
    ?>
</div>

Currently I can get the text to send through post however the formatting in the text editor doesn't work. (e.g. I click 'B' to turn the text bold and nothing happens). Or it simply doesn't send and returns an error of 'all fields must be filled in'.

Upvotes: 0

Views: 58

Answers (2)

Jnt0r
Jnt0r

Reputation: 173

I can't see that you use a form around that snippet. As mentioned here https://stackoverflow.com/a/5518526/6639865, the name attribute must be inside a form.

The first attempt would be to make the name attribute and put it in a form (or use ajax to post the data)

Maybe you could provide some more code so we can give you more specific answers. What should the post do? Should it be sent to a script where anything happens and then the text returns with some changes?

Upvotes: 0

electric.Kariim
electric.Kariim

Reputation: 110

Use JS/AJAX. Use JS to Store the text you're looking for in a JS var and use AJAX to submit it.

This way it won't matter what kind of DOM component the text is coming from. You'll be able to handle text from any HTML component in JS.

Upvotes: 1

Related Questions