I originally had a submit button like this
<form action="<?php $self ?>" method="post" >
<input name="search" type="hidden" >
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "search">
</form>
it made this statment true
if(isset($_POST['Search'])){}
For a time all was well
then i made my submit button a image
<form action="<?php $self ?>" method="post" >
<input name="Search" type="hidden" />
<INPUT value="Search" TYPE="image" SRC="search.jpg" BORDER="0" ALT="Search">
</form>
For more time all was good untill i wanted to make this button into a text link..
I looked on the internet and read many things where i learned that it cant be done in html but java script was needed..
so i tryed to use this code but it no longer made my statment true..
this is the javascript submit button i found
<a href='javaScript:document.FORM_NAME.submit()'>Submit</a>
My two questions to you wizards out there are
1) where do i put the value of the submit?
2) how do i get this to replace my earlyer submit buttons?
Making a button into a text link is simple CSS.
<input type="submit" id="submit" value="submit" class="submitbutton" />
CSS:
input.submitbutton{
margin: 0;
border: none;
background-color: transparent;
padding: 0;
}
/* Make sure the hover has the same element properties as the first, obviously changing the font colour on hover is something acceptable */
input.submitbutton:hover{
margin: 0;
border: none;
background-color: transparent;
padding: 0;
}
For starters you need to give your form a name corresponding to what's in the Javascript link (in this case, FORM_NAME):
<form name="FORM_NAME" action="<?php $self ?>" method="post" >
<input name="search" type="hidden" />
<a href='javaScript:document.FORM_NAME.submit()'>Submit</a>
</form>
Then on the page that checks the form, you need to check for $_POST['search'], which comes from the input. I don't think case matters, but it makes sense to always check using the same string anyway.
I'm not 100% sure what this form is meant to do since it doesn't seem to submit anything, don't you want to use a text input so the user can search for something?
If you want an image as a submit button? Why not use the button element
<button name="search" value="search" type="submit">
Send<img src="/icons/wow.gif" alt="wow" /></button>
see:
http://www.w3.org/TR/html401/interact/forms.html#h-17.5
Just out of curiosity, how will users without javascript enabled submit the form?
How about using CSS to style submit input to look like a text rather than a button?
examples here:
http://cssm.wordpress.com/2006/10/01/how-do-i-make-a-submit-button-look-like-text/
http://forums.digitalpoint.com/showthread.php?t=403667
Related
I am trying to figure out a way to know which button is clicked using PHP. I am new to this "world" so it is kind of difficult for me to figure it out by myself.
So what basically i am doing is a website that will control an Arduino (iot) and i am giving the admin the privileges to give access to his house to who ever he wants and also deletes who ever he wants. i am doing this with the help with a database of course (mysql).
This is how it looks :
IMAGE HERE
When the admin fill the inputs and submit it will add a person to database then display it with a delete button. This is the code i m using for the button :
<form method="post" action="addAdmin.php">
<button type="submit" style="background:none; border:0; box-shadow: none; border-radius: 0px; cursor: pointer; color: red;"><i class="fas fa-trash-alt"></i></button>
</form>
I want to know how i can know which user did the admin choose to delete but i can not figure it out.
Thanks for your help !
What you need to do is supply information other than just having the delete button.
Currently the only thing you are doing is loading the addAdmin script, but you are passing zero information.
The simplest way to do this would be to add a hidden input with a key of the current user that the button is supposed to be for, like so:
<form method="post" action="addAdmin.php">
<input type="hidden" name="user" value="<?= $userID ?>" />
<button type="submit"><i class="fas fa-trash-alt"></i></button>
</form>
Then in the addAdmin script you can check the $_POST array for the user key, and work from there.
You can give the button the name attribute.
<form method="post" action="addAdmin.php">
<button type="submit" name="submit" style="background:none; border:0; box-shadow: none; border-radius: 0px; cursor: pointer; color: red;"><i class="fas fa-trash-alt"></i></button>
</form>
It can be achieved by utilizing name/value attributes of button tag.
This is a HTML chunk:
<form action="/delete.php" method="post">
<button name="delete_id" type="submit" value="1">User 1</button>
</form>
...
<form action="/delete.php" method="post">
<button name="delete_id" type="submit" value="2">User 2</button>
</form>
PHP code:
<?php
$deleteId = $_POST['delete_id'];
// call sql query and pass $deleteId
?>
I have a hyperlink as shown:
<div style="clear:both"> <a color="grey" accesskey=""style="float: right" href="newbattle.php? userid= <?php echo $id0; ?>"> [<font color="grey">Attack</font>]</a><br></div> <br>
Is it possible, using only only php, to carry POST data? I want to put this
<input type="hidden" name="test" value="<?php echo $number;?>
So I can $_POST['test'] on the other page and get the $number. I can switch over to normal form but I really like what I have
No, that's not possible. If you want to submit a POST request, you should go through a <form> and submit it.
You cannot post through a hyperlink, unless you use JavaScript to capture the click event and simulate a click on a submit button.
But a better approach, I think, would be to make an actual submit button. With a bit of CSS you can style that button to look as if it was a hyperlink. That way, if the CSS fails, you've still got a working button, while if a JavaScript issue would occur, you have a disfunctional link with unexpected behaviour.
input[type=submit] {
display: inline;
border: none;
background-color: transparent;
color: blue;
cursor: pointer;
}
input[type=submit]:hover {
text-decoration: underline;
}
<form action="otherpage.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>">
<input type="submit" value = "Look, I'm a link!">
</form>
A link redirects user to another page, it's purpose is not for get/post requests.
If you want to send a post request on a click, you can do it with a submit button inside form. For example,
<form action="another_page.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>
<input type="submit" />
</form>
Style the button like a hyperlink and it will send a post request as expected.
You can do that using a form.
When the user clicks the link, the form is submitted with the "test" variable and the "userid" variable.
Here's the code:
<form method="post" action="newbattle.php" id="myForm">
<div style="clear:both">
<a color="grey" accesskey="" style="float:right;" href="" onclick="javascript:document.myForm.submit(); return false;">[<font color="grey">Attack</font>]</a>
<br/>
</div>
<br/>
<input type="hidden" name="userid" value="<?php echo $id0; ?>" />
<input type="hidden" name="test" value="<?php echo $number; ?>" />
</form>
For my specific problem, here's what I ended up doing.
href="newbattle.php?userid= <?php echo $id0; ?>&num=<?php echo $number; ?>"
I added the $number on to the hyperlink and then retrieved it with $_GET on the next page
If you want to access test value by $_POST you have to use form like this :
<form action="another_page.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>
<input type="submit" />
</form>
get.php :
<?php
$num = $_POST['test'];
echo $num;
?>
I can submit input with type "submit" but once I changed it to "image" it doesn't submit.
Works with submit:
<FORM ACTION="balance.php" METHOD="POST" enctype="multipart/form-data">
<input name="addBal" type="submit"/>
</form>
Doesn't work with image:
<FORM ACTION="balance.php" METHOD="POST" enctype="multipart/form-data">
<input name="addBal" src="pics/add.png" type="image"/>
</form>
Output end (balance.php):
if(isset($_POST['addBal'])) {
echo 'TESTER';
}
I've made a typo: but the problem still remains. Type submit works, and image doesn't
You can try this example:
<button type="submit" name="addBal" style="padding: 0; border: none;"><img src="monkeydluffy.png" /></button>
It can serve the same purpose of submitting. As for additional information, you can check out this discussion regarding your concern.
Input Type image submit form value?
Probably you're looking for type image:
<input name="addBal" type="image" src="pics/add.png" alt="Submit" />
I just want to have multiple buttons on my site which redirect to a certain section. This is what i got but it is redirecting to "error.php" everytime no matter which button I click:
<html>
<form action="error.php" method="POST">
<input type="hidden" name="variable" value="50" />
<input type="image" src="play.png" name="Play" style="top:10%; left: 43%; position: absolute;" value="play" onclick="submitForm=('play.php')" class="submit_button"/>
<input type="image" src="forum.png" name="Forum" style="top:11%; left: 22%; position: absolute;" value="forum" onclick="submitForm=('forum.php')" class="submit_button"/>
</form>
</html>
So basically I want button A to redirect to folder X and button B to folder Y. I have searched for hours but didn't find any awnser, please help!
Sincerely,
Max
I have spent several hours trying to find a solution to my issue, but just can't seem to find the proper solution. Thanks in advance for your assistance!
I have ONE html form with:
<form id="columnarForm" action="formindb_hoh_1.php" enctype="multipart/form-data" method="post" />
I would like to have TWO submit buttons:
<input type="image" name="camper" value="camper" src="../images/apps/camperBtn.png" class="submit_button" />
<input type="image" name="medical" value="medical" src="../images/apps/medicalBtn.png"class="submit_button" />
I would like the first submit button to have the action of formindb_hoh_1.php when clicked and the second submit button to have the action of formindb_hoh_2.php, but am unsure how to make one button have one action and have the other button has a different action.
No JS, use HTML5.
Change the submit buttons to use new HMTL5 button attribute formaction:
<button type="submit" name="camper" formaction="formindb_hoh_1.php">Camper</button>
<button type="submit" name="camper" formaction="formindb_hoh_2.php">Medical</button>
Reference: http://devdocs.io/html/element/button
Refer this :
Multiple submit buttons php different actions
Put this script in your page :
<script>
function submitForm(action)
{
document.getElementById('columnarForm').action = action;
document.getElementById('columnarForm').submit();
}
</script>
Modify your input code :
<input type="image" name="camper" onclick="submitForm('formindb_hoh_1.php')" value="camper" src="../images/apps/camperBtn.png" class="submit_button" />
<input type="image" name="medical" onclick="submitForm('formindb_hoh_2.php')" value="medical" src="../images/apps/medicalBtn.png"class="submit_button" />
Finally, I got my answer after spending more than an hour. I tried a various method like switch case, jquery, and JavaScript. But I only used HTML5 formaction tag and now my form two submit button working at two location.
Code :
<input type="submit" class="btn btn-success" value="Pay Now" name="submit" style="width: 100%; letter-spacing: 1px; color: #fff; border: none;padding: 10px;" formaction="example.php">
<button type="submit" class="btn btn-success" name="submit" style="width: 100%; letter-spacing: 1px; color: #fff; border: none;padding: 10px; margin-top: 15px;" formaction="mail.php"> Button</buttton>
I have the same issue. but the thing is the first button function is in JS while the other is using PHP.
$('#add-bookingid').submit(function(e){
e.preventDefault();
calculateDistance();
});
You see $('#add-bookingid').submit so both buttons have same button type as submit.
Main Purpose
Button# 1
Button# 2