Reputation: 944
I am fairly new to PHP.
The code is pretty simple:
home.php:
<form action="getsentitem.php" method="get">
<div >
<input name="query" id="query" class="searchQuery" size="20" value="" type="text" autocomplete="off">
<input id="searchButton" value="Search" type="submit">
</div>
</form>
getsentitem.php:
<?php
if (isset($_GET['query']))
$query = $_GET['query'];
?>
Question:
The above code will simply give me whatever I enter in the text box which is there in home.php
. Now, is there any way through which I can get the values of the other attributes of the text box? Like, is it possible to get the id of the textbox or its size through this method.
Upvotes: 0
Views: 2716
Reputation: 1647
The short answer is: NO
You can only get the value of the input from the $_GET
superarray.
edit.
However if you did something like this:
<form action="getsentitem.php" method="get">
<div >
<input name="query" id="query" class="searchQuery" size="20" value="" type="text" autocomplete="off">
<input name="queryMeta" value="id:query_class:searchQuery_size:20" type="hidden">
<input id="searchButton" value="Search" type="submit">
</div>
</form>
Then you can read it in the PHP like this:
<?php
if (isset($_GET['queryMeta']))
$queryMeta = explode('_',$_GET['queryMeta']); //splits the string to array('id:query','class:searchQuery','size:20')
?>
Upvotes: 1
Reputation: 2625
No, it is not. Only name=>value pairs are sent to the server via your chosen method (GET/POST).
You can include custom data in hidden inputs within the form if you want to:
<form action="getsentitem.php" method="get">
<div >
<input type="hidden" name="more_info" value="I will be available after submit."/>
<input name="query" id="query" class="searchQuery" size="20" value="" type="text" autocomplete="off">
<input id="searchButton" value="Search" type="submit">
</div>
</form>
echo $_GET['more_info']; // 'I will be available after submit.'
This is handy when you generate additional data via AJAX calls and javascript calculations. You don't necessarily know all the IDs of a highly dynamic webpage.
CSRF tokens are also usually sent this way.
Upvotes: 3
Reputation: 522016
No. Only the entered value is submitted with the name you gave it, nothing else; you can see exactly what gets submitted in the URL, that's it. Since you created the HTML in the first place, you should know what the other values were.
Upvotes: 2