Page 1 of 1

Use custom button when using post

Posted: Wed Nov 26, 2003 9:27 am
by hibbeac1
I was wandering whether in PHP you can use your own custom button instead of the usual submit button to post to the page the person is on now and then process things once it has been pressed.

If so how do you do it.

Thanks

Posted: Wed Nov 26, 2003 9:31 am
by Weirdan
It has nothing to do with PHP. It's HTML (DHTML) issue.

Code: Select all

<form action="something.php" name="frm" id="frm" method="post">
  <input type=button onClick="frm.submit()">
</form>

Posted: Wed Nov 26, 2003 11:42 am
by igoy

Code: Select all

<form action="something.php" name="frm" id="frm" method="POST">
  <input type="image" src="dir/image.jpg" width=100 height=100 onClick="frm.submit()">
</form>
You see.. you can use custom made image as submit button.

Posted: Wed Nov 26, 2003 12:15 pm
by Weirdan
2Igoy
input type=image implies submit, so you don't need onClick handler in a tag.

Posted: Thu Nov 27, 2003 6:22 am
by igoy
yeh... I remembered it later.... thanks anyways for reminding Weirdan.. :)

Custom Button on Form

Posted: Mon Dec 01, 2003 4:22 am
by hibbeac1
I did get this to work on a page where i had a form. In the PHP section of the code i had if(isset($_POST['submit'])) { \\run processes

But when using the custom button i just had if($_POST) as i could not find a way of naming the custom button. I was wandering if there is a way i could do this as i have pages with more than one forms in which would need to check for the posting of different buttons.

Thanks For Your Help.

Posted: Mon Dec 01, 2003 4:36 am
by igoy
well, you can simply change name of submit button in condition..

Code: Select all

<?php

if ($isset($_POST['submit'])) {

?>
to this...

Code: Select all

<form action="something.php" name="frm" id="frm" method="POST"> 
  <input type="image" name="cmdSubmit" src="dir/image.jpg" width=100 height=100 onClick="frm.submit()"> 
</form>

note : you can even set name if your submit button image to whatever you want, like here I've named it "cmdSubmit"

in PHP page i'll recognize it like this

<?php

if (isset($_POST['cmdSubmit'])) {
    // whatever action you want to take
}

?>
also, you can simply have hidden input field in your form named as "submit",

Code: Select all

<form action="something.php" name="frm" id="frm" method="POST"> 
  <input type="image" src="dir/image.jpg" width=100 height=100 onClick="frm.submit()"> 
  <input type="hidden" name="submit">
</form>

and you won't need change in your PHP page.
<?php

if (isset($_POST['submit'])) {
    // whatever action you want to take
}

?>
enjoy !! :)