Use custom button when using post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hibbeac1
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2003 10:25 am

Use custom button when using post

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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>
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

2Igoy
input type=image implies submit, so you don't need onClick handler in a tag.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post by igoy »

yeh... I remembered it later.... thanks anyways for reminding Weirdan.. :)
hibbeac1
Forum Newbie
Posts: 13
Joined: Thu Oct 30, 2003 10:25 am

Custom Button on Form

Post 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.
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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 !! :)
Post Reply