Out button on the left or inn button on the right

<form action="search.php" method="get"> 

<input type="image" src="http://load.dot.kr/dmg/search.png" 
name="out" alt="outSearch" style="width:20px"> 

<input type="text" name="key" value="" style="align-items:center"> 

<input type="image" src="http://load.dot.kr/dmg/search.png" 
name="inn" alt="innSearch" style="width:20px"> 

I have the code above at http://dot.kr/qna/221220search/
If a user click a search button on the right, it goes to search.php with some values, i.e. key, inn.x, and inn.y.

in search.php, I can get the value of key with the code below.

echo $_GET['key'];

However, I cannot get the value of inn.x with the code below.

echo $_GET['inn.x];

How can I get the value of inn.x?
I like to know the user click which search button between the left search button and the right search button.

I am not sure you will actually get what you want like this. type = image values are processed differently and an actual value is not passed. The x and y co-ordinates sent are the co-ordinates WITHIN the image you click, so you will get the same co-ordinates with both images if you click in exactly the same place. ie this will not help you determine which image was clicked.

If you want to actually read the co-ordinates you would do something like this -

echo $_GET['key'].'<br>';
echo $_GET['inn_x'].'<br>';
echo $_GET['inn_y'].'<br>';
echo $_GET['out_x'].'<br>';
echo $_GET['out_y'].'<br>';

ie. replace the . with an underscore _

but this will throw an error on the image that was NOT clicked - sample output of above code if clicking on ‘out’ image -


Warning : Undefined array key “inn_x” in C:\xampp\htdocs\MyProjects\NewConstantSurfer\search.php on line 3

Warning : Undefined array key “inn_y” in C:\xampp\htdocs\MyProjects\NewConstantSurfer\search.php on line 4


Contents of values part sent in address bar = search.php?out.x=6&out.y=9&key=dgsg
So it is DISPLAYED as out.y and out.x but you READ it as out_x and out_y

you could then use isset() to determine which button was clicked and then decide how to process, like so

if (isset($_GET['inn_x'])) {
	echo 'inn button was clicked<br>';
if (isset($_GET['out_x'])) {
	echo 'out button was clicked<br>';
echo 'key = '.$_GET['key'];

Hope this helps, but as I say, it may not be best way to do it

Thank you. keyy14.
It helped a lot.
Now I can discriminate that the user clicks which button between out button on the left and inn button on the right.

I have still some curiosity about the following.

I don’t know why the expression “inn_x” in the search.php is different the expression “inn.y” in the URL.

To be honest I don’t know why either, I just know that’s what you have to do :grinning:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.