-5

I want to get DIV contents in PHP to submit a form.

<div id="hello"></div>

In my search, I was advised to use <input type="hidden" but I do not know how to do.

James Z
  • 12,209
  • 10
  • 24
  • 44
Jaber
  • 21
  • 1
  • 1
  • 7

2 Answers2

1

If you are obtaining the HTML as a string, or even if its a remote web page, you will need a HTML parser. There are lots of these for PHP and the question has already been asked and answered. How do you parse and process HTML/XML in PHP?

If you are looking to do this on click or some other page event when a user does something, you need to use javascript instead of PHP. PHP is a server side language and cant be used to access elements in the users web browser, you need to use javascript for this.

Dan Hastings
  • 3,241
  • 7
  • 34
  • 71
0

If you don't want to use an input field to show a value (perhaps because you don't want the user to modify it or for styling reasons). You can display it in a div, and pass the value with the form submission by duplicating the value in a hidden input positioned inside your form. The div may be inside or outside your form.

<div id="user">Jaber</div>
<form>
    ... any other form fields
    <input type="hidden" name="user" value="Jaber">
    ... submit button
</form>
mickmackusa
  • 43,625
  • 12
  • 83
  • 136