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
Use custom button when using post
Moderator: General Moderators
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>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>Custom Button on Form
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.
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.
well, you can simply change name of submit button in condition..
to this...
also, you can simply have hidden input field in your form named as "submit",
enjoy !! 
Code: Select all
<?php
if ($isset($_POST['submit'])) {
?>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
}
?>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
}
?>