i have a webpage form which have different no of textbox.
i have to send this data to a sql database
but i dont want to use the $_post or $_get command
infact i don't want to send my data to other php page
so i basically want a php equivalent of javascript getelementbyid() function so that i can get the values of extboxes when the user clicks a button.

any one pls help...thanx in advance

Recommended Answers

All 3 Replies

The only way for PHP to get form data is to use GET or POST. In PHP you can use PHP DOM* to get an element by id, but it will retrieve the page and analyze it, this page will not contain the data inserted in the form, because is not a value already present but is related only to the client session. In other words your textarea will be empty.

If you have different textarea tags then use different names:

<textarea name="t1"></textarea>
<textarea name="t2"></textarea>
<textarea name="t3"></textarea>
<textarea name="t4"></textarea>

* http://www.php.net/manual/en/domdocument.getelementbyid.php

If you are good at JS and want to send only what is needed not the whole form there is a solution. You can write a little JS function to get only what you want and send it via AJAX when button is clicked.
But again you need to look at $_POST or $_GET or even $_COOKIE at backend. PHP treats your data as ARRAY of elements. Unlike JS, PHP requires that you issue a request to the server so PHP is triggered and can do something with your data, and return a response for you.

Member Avatar for diafol

I think you've misunderstood the functionality of client and server-side code. If you don't SEND, you don't get on the server without Ajax (as mentioned by fenixz).
Ajax will send data to php via POST or GET anyway.

Ajax is the way to go if you don't want a whole page refresh/reload (call it what you want) when you want to send form data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.