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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image submit button

Status
Not open for further replies.

4181944

Programmer
Aug 6, 2002
9
NZ
Hi,

I changed the submit button created using <INPUT TYPE=&quot;SUBMIT> to an image submit button <INPUT TYPE=&quot;IMAGE&quot; SRC=&quot;login1.gif&quot;>. here is my code:

<?

if(isset($imgbut)){
echo &quot;You click image button: $inputtext <br>&quot;; //***
}
elseif (isset($butsubmit)){
echo &quot;You click submit button: $inputtext <br>&quot;; //+++
}
else{
echo &quot;No click :$inputtext<br>&quot;; //@@@
}
?>
<html>
<head>
<title></title>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>

Submit Button Image<br>
<form action=&quot;imagebutton.php&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;inputtext&quot;>
<input type=&quot;submit&quot; name= &quot;butsubmit&quot; value=&quot;click me&quot;>
<input type=&quot;image&quot; name=&quot;imgbut&quot; src=&quot;login1.gif&quot; value=&quot;Submitimage&quot; >
</form>
</body>
</html>

When I click the image button( name= imgbut), it did not execute line //*** instead execute line/@@@, Why? How can I execute line/***? There is no problem if I click submit button(name=butsubmit). How can I get $imgbut variable after form action in php?

Many thanks for help

Richard

 
//Do you have both buttons on the form?
Yes. Even I removed the submit button(<input type=&quot;submit&quot; name= &quot;butsubmit&quot; value=&quot;click me&quot;>) from the form, I still can not get $imgbut variable after form action.
 
it maybe register globals problem,

if it is off then $imgbut will be empty, u have to use the $POST method to get the value of the field.

now try checking.
 
Try putting a [tt]print_r($HTTP_POST_VARS);[/tt] at the beginning of the script. //Daniel
 
I start every response by saying that I don't always explain things very well. I'll apologize for that right up front. Having said that, your problem looks to be quite simple to fix.

If I understand your problem you are not able to echo the text in the textbox named inputtext when you hit the image submit button. I'm assuming that the form action is set to submit to itself since you list the code to echo the variable at the top. If that assumption is wrong then you would need to post the code for the page receiving the submit. Anyway...

First off, you're not echoing the variable at all. You have the variable, $inputtext, inside the echo string. By doing this you tell the PHP engine that it is just part of a string and the engine will not evaluate the variable at all. The correct echo statement would be...

echo &quot;You click image button: &quot;.$inputtext.&quot;<br>&quot;;

You have to break the quotes to call the variable. The dots before and after the variable tell PHP to concatenate the value of the variable to the strings that came before and after. Note that you do have to re-open the quotes in order to include the <br> in the string.

That should fix your problem. If not, then strip away the entire if() statement and the echo text and just try....

echo $inputtext;

That will at least tell you if the variable is being submitted and not processed correctly or not submitted at all. I really believe the echo statement is your problem. My only concern is with using two submit elements on one form. I'm not entirely sure that's allowed. Whenever I've wanted to use two separate buttons I've used JavaScript to differentiate between the buttons. That would probably be the cleanest way to go regardless. You could use the JS to differentiate the buttons and add the &quot;You have clicked the Image Button&quot;, &quot;You have clicked the Submit Button&quot; stuff to the variable before it's even submitted. Then you could lose the whole conditional statements in your PHP and just echo $inputtext. Just a thought.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top