Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_POST for text in DIV elements

Tags:

php

Because of my web style, i don't want to use input & textarea and get information by using $_POST[] and i need to get information that is in DIV element.

For example , I want to get information in this :

<div class="mine" name"myname">
this is information that i want to get and put into database by PHP ! 
</div>

and :

$_POST[myname];

But i can't do it with $_POST , How can i do it ??

And if this method can't do this , do you know any other method to get information from DIV like this ?

like image 716
user3271403 Avatar asked Sep 03 '25 02:09

user3271403


1 Answers

you can call a onsubmit function and make a hidden field at the time of form submission like this

HTML need to give a id to your form id="my_form"

<form action="submit.php" method="post" id="my_form">
<div class="mine" name"myname">
this is information that i want to get and put into database by PHP ! 
</div>
<input type="submit" value="submit" name="submit" />
</form>

Jquery call on submit the form

$(document).ready(function(){
   $("#my_form").on("submit", function () {
        var hvalue = $('.mine').text();
        $(this).append("<input type='hidden' name='myname' value=' " + hvalue + " '/>");
    });
});

PHP : submit.php

echo $_POST['myname'];
like image 70
Satish Sharma Avatar answered Sep 04 '25 19:09

Satish Sharma