Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple form images revisited.

Status
Not open for further replies.

SunnyByfleet

Technical User
Feb 24, 2003
146
GB
Following on from this thread: thread215-1262702

I basically wanted to have one image as a submit button and another as a cancel button.

That didn't work. for reasons explained in the other thread. I will try the solution suggested there, but am also puzzled.

To get around it not working, I resorted to having one image as a standard submit, and the other as a standard link.

It was something like this:


Code:
<form action="process.php" method="post">

....

<input type='image' src='m_submit.gif' />
<a href='main.php?tab=123'>
<img src='m_cancel.gif' border=0>
</a>
</form>

If I run that, and have process dump the contents of $_REQUEST using print_r, I see that there is no POST data as expected. Instead the form has a single GET consisting of tab=123 which comes from the second image.

If I move the second image outside the form it all works fine. However, that then presents separate formatting issues, and I would much rather it reside where it does.

Having seen the other thread I can now use the two image submit technique described, however I am curious to know why my images are behaving as they do, as it sounds odd.

Thanks
 
images are input fields. when you use them AS form elements, I believe they only submit the mouse location or some useless garbage like that.

if you're looking for sexy input and cancel buttons, the best method is to use submit and reset buttons and style them appropriately. this way, you don't need javascript to have a functional form.

----
 
Javascript wasn't an issue for me, as all the processing is done via PHP. I was just curious as to why they image not defined in the INPUT tags was being treated as part of the submit tag.

If that is the case, is the <INPUT type="image" portion actually redundant?
 
Images used as submit buttons will only ever send the mouse coordinates. But if you know what to look for they can still be used to determine what button was pushed.

Take this example its in PHP since it seems that's what you are using:
Code:
<form action="blank.php" method=POST>
<input type=text name="dummy">
<input type=image name="send" src="send.png">
<input type=image name="cancel" src="cancel.png">
</form>


<?PHP
echo "<pre>";
print_r($_POST);
echo "</pre>";


if(isset($_POST['send_x'])){
echo "Send Button was Pushed";
}

if(isset($_POST['cancel_x'])){
echo "Cancel Button was Pushed";
}

Since I know the submit buttons are going to be images I'm prepared to look for what they return.

In PHP the POST variable will have the X and Y coordinates of the button that was pushed. I just looked for X but you could look for Y.

Different languages will return the x and y coordinates differently. for PHP it just creates 2 variables comprised of the name of the input plus an underscore and the letters X or Y depending on the coordinate.

Its still very simple to actually figure out what was pressed and then act accordingly.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If we return to your original question, are you saying that after you press the image input button your form information does not get sent, instead only the information from the link after it gets sent? This is how I understand your problem and want to verify with you that this is what you're experiencing.

If that is true, then you should know that this is not the way the code should be behaving and there could be an issue with either styling the cancel button or some html error. If you could show us an online example of this it would be best.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Yes Vragabond you are absolutely correct. Thank you to all the other contributors for your efforts, but that is not the issue. The issue is what Vragabond has said.

I can't post an online link, as the code currently resides on my Wampserver. However, the relevent HTML is shown below:

Code:
<form action="procdres.php" method="post">

<!--ORDINARY FIELD CODE GOES HERE. -->

<input type='image'  src='[URL unfurl="true"]http://localhost/goons/images/admin/m_submit.gif'[/URL] />

[red]<a href='[URL unfurl="true"]http://localhost/goons/shopdata/gg_admlist.php?tag=kxbmfdvkpa'>[/URL]

<img src='[URL unfurl="true"]http://localhost/goons/images/admin/m_return.gif'[/URL] border=0>

</a>
[/red]
</form>

If I run the above and click on the submit graphic, I get the following in the POST and GET buffers.

Code:
--------------------

POST
Array ( ) 

--------------------

GET
Array ( !tag! => ) 

--------------------

[blue]
## NB I have replaced square brackets with ! ! above otherwise the word tag is not displayed.
[/blue]
As you can see, there is nothing in POST, and a half-argument in GET.


Now, if I move the code in red so that it is after the closing FORM tag, everythin works fine. The POST is populated and there is nothing in GET.

So what is going on?
 
Based on what you've shown us I cannot say for sure what is the problem. Nothing seems to suggest behaviour that you describe, however you have barely shown us any code. We might need to see the entire form code, any javascript you use and any CSS styling of these elements you have.

Are you forwarded to procdres.php or to gg_admlist.php after submitting the form?

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Your Post array is empty because form what you have showed us there are no fields to be sent. I suppose there should be, but you did not copy them with your code.

Also your Submit button has no name. Though that should not affect the submission its good practice to always give your buttons names.

As for your GET array, you can't have it both ways. If you use the Submit image button the GET array will be empty because your form's method is POST not GET so nothing gets sent in the GET.

If you where to press your link, the link goes to a totally different page than your Form, so that page would probably find something in the GET array.

However I agree with Vragabond, e need more code. Your entire form code would help us diagnose the problem.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Right, I've simplified the form as much as possible, and here it is.

As it stands, the below form works. I can click on the submit button and it goes to procdres.php. procdres.php confirms that POST is populated and GET is empty, as expected. If I click the cancel button, I go to gg_admlist.php


Code:
<form action="procdres.php" method="post">
<h2>Edit Stock Item: 2</h2>
<input name="ccode" id = "ccode" value="2" type="hidden" />
<label for="cdesognercode">Designer Code:</label>
<input name="cdesognercode" value="21204" class="text" type="text" />

<input name='baz' type='image'  src='[URL unfurl="true"]http://localhost/goons/images/admin/m_submit.gif'[/URL] />
<a href='[URL unfurl="true"]http://localhost/goons/shopdata/gg_admlist.php?tab=aezjkvtoew'>[/URL]
<img src='[URL unfurl="true"]http://localhost/goons/images/admin/m_return.gif'[/URL] border=0>
</a>

</form>

However, in order for that to work, I had to rename the designercode field. Its original name was cdesignercode, as shown below.

If I change that 1 letter in the name field, then when I click submit, I still go to procdres.php, however the POST is empty and there is data in the GET which matches the tab= on the return button.

Code:
<form action="procdres.php" method="post">
<h2>Edit Stock Item: 2</h2>
<input name="ccode" id = "ccode" value="2" type="hidden" />
<label for="cdes[red]i[/red]gnercode">Designer Code:</label>
<input name="cdes[red]i[/red]gnercode" value="21204" class="text" type="text" />

<input name='baz' type='image'  src='[URL unfurl="true"]http://localhost/goons/images/admin/m_submit.gif'[/URL] />
<a href='[URL unfurl="true"]http://localhost/goons/shopdata/gg_admlist.php?tab=aezjkvtoew'>[/URL]
<img src='[URL unfurl="true"]http://localhost/goons/images/admin/m_return.gif'[/URL] border=0>
</a>

</form>


So what is wrong with "cdesignercode" as a name?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top