I have a problem in creating a Button with text and image on it.
<td>
<button type="submit" name="report" value="Report"
<?php
if($tab == 'Excel')
echo "id=\"tab_inactive\"";
else
echo "id=\"tab_active\"" ; ?>>
<img src="images/report.gif" alt="Report"/>Report
</button>
<button type="submit" name="excel" value="Excel"
<?php
if($tab == 'Excel' )
echo "id=\"tab_active\"";
else
echo "id=\"tab_inactive\"" ; ?>>
<img src="images/Excel.gif" alt="Excel" width="16" height="16" /> Excel
</button>
</td>
Here $tab is
$tab = strlen(trim($_POST[excel]))>0 ? $_POST[excel] : $_POST[report];
I tried this way, but this is behaving so strangely.
On click the button:- The submit function is working properly in firefox, but not in IE.
Instead of submitting the value(in this example values are 'Report' and 'Excel'), indeed it is submitting the label of the button.
That is if i am checking the value of array PRINT_R($_POST). The value of it is
Array ( [report] =>(Icon that i used) Report
[excel] => (Icon that i used) Excel
[frm_analysis] => [to_analysis] => )
Here i have more than 1 button, then all the labels are submitted eventhough one of them is pressed. i dont how to capture which button is pressed.
I even tried changing button type=button and onclick="document.formname.submit()" Even this is resulting in the same.
Can you please help me to solve this.
<button>s are broken in IE. I think they corrected it in IE7 or 8. Is the page in standards mode? That may help in IE7 or 8.
If you need to support the broken version, you could try and work around it with JS, if you don't mind being dependent on it. Example:
<script type="text/javascript">
function buttonclicked(button) {
button.form.elements["buttonclicked"].value = this.value;
}
</script>
<input type="hidden" name="buttonclicked" value="">
<button type="submit" name="report" onclick="buttonclicked(this)">
<img src="images/report.gif" alt="Report"/>Report
</button>
<button type="submit" name="excel" onclick="buttonclicked(this)">
<img src="images/Excel.gif" alt="Excel" width="16" height="16" /> Excel
</button>
I don't think there is any other way other than avoiding <button> and using <input type=submit> if you need to distinguish between which on was clicked.
This, unfortunately, is IE's default behaviour when dealing with <button> elements. There is, to my knowledge, no real solution to this problem, although there are ofcourse numerous workarounds.
My suggestion would be as follows:
Create a radio button control called report_type (or whatever you choose), with two radio buttons: One for Excel and one for Report. Also, include a regular submit button.
With Javascript (if it's enabled), you can hide the radio buttons and submit button (display: none), and create (through JS) two buttons, labeled Report and Excel. On clicking one of these buttons, the proper radio button is checked, and the form is submitted.
This will allow you to create the form in it's current form, while providing a working fallback for users without javascript support.
And instead of the button's value, you can now look at the Radio's value to decide which form of reporting you want to use.
<button title="Search" onClick="javascript:executeFunction();">Search<br /><img src="images/search_icon.gif"/><br />More Text</button>
since your image is included within the <button> (<input>?) tag, it is likely being included in the value.
Why not use an img with either an onclick event or a href with a GET request?
Have not tested it, just one idea:
<td>
<button type="submit" name="active_page" value="Report"
<?php
if( isset( $_POST['active_page'] ) && $_POST['active_page'] == 'Excel' )
echo "id=\"tab_inactive\"";
else
echo "id=\"tab_active\"" ; ?>>
<img src="images/report.gif" alt="Report"/>Report
</button>
<button type="submit" name="active_page" value="Excel"
<?php
if( isset( $_POST['active_page'] ) && $_POST['active_page'] == 'Excel' )
echo "id=\"tab_active\"";
else
echo "id=\"tab_inactive\"" ; ?>>
<img src="images/Excel.gif" alt="Excel" width="16" height="16" /> Excel
</button>
</td>
Dont really understand your problem, is it this:
You want to now wich Button was clicked, to show the tab or and other tab? Right?
Related
So, I have a button in a form.
<form>
<button onclick="alert('<?php echo $value ?>')">Click me!</button>
</form>
$value = "1.png"
When I press it changes the url like this:
Initial:
index.php?id=82
After I click:
index.php?
As you can see, I want the button to only show an alert, not to change the URL
Full code:
<form>
<label>Title</label><br>
<input type="text" value="<?php echo $title ?>"><br><br>
<label>Description</label><br>
<textarea rows="5" maxlength="120"><?php echo $desc ?></textarea><br><br>
<div>
<?php for($k = 0; $k < count($images); $k++) { ?>
<div>
<img src="<?php echo $images[$k] ?>">
<button onclick="alert('<?php echo $images[$k] ?>')">Click me!</button>
</div>
<?php } ?>
</div>
</form>
PS: I'm not sure what's the problem but I think is the form
There are at least two ways of achieving this:
html:
<button type="button" onclick="alert('<?php echo $images[$k] ?>');">Click me</button>
<button onclick="alert('<?php echo $images[$k] ?>');return false;">Click me!</button>
The first option I think would be best if the only thing you want to achieve is to alert a text.
The second option might be better if call a function when you click on the button and want different responses:
<button onclick="return foo('<?php echo $images[$k] ?>');">Click me!</button>
in javascript:
function foo(image) {
//If image is img1 then update the page
//If any other image, don't update the page
if (image == 'img1') {
return true;
}
return false;
}
When you fail to specify the type of a <button> element, the browser will imply that it is a submit type button. Thus, when you press the button, your browser is submitting the form with it.
You should either,
a) Specify a type for the button other then submit, or
b) Return false in the javascript code to run, to prevent the click event from bubbling.
I am having a problem with a website I have to create. When I call the POST with the right key I dont get the value back. I think the error is that my POST does not get filled.
$id = isset($_GET['id']) && is_numeric($_GET['id']) ? (int) $_GET['id'] : 0;
This line is on top of the coding and gives the right id back, I checked that via an echo.
<form method="POST" action="Index.php">
<input type="hidden" name="Entryid" value="<?php echo $id; ?>">
<a type="submit" name="delete" class="btn btn-success" href="Index.php" data-toggle="modal" data-target="#myModal" style="cursor: pointer;">Löschen</a>
</form>
Here I put the value of id into the key "Entryid" and switch to "Index.php" when I click on a button.
Inside of "Index.php" I try to get the value like that.
$id = isset($_POST['Entryid']) && is_numeric($_POST['Entryid']) ? (int) $_PST['Entryid'] : 0;
Here the value of id is probably not set and if I check it via echo the output is the 0.
Where do you think my error is?
I think it's because you're using an <a>-tag as the button, and not an input.
So change this line:
<a type="submit" name="delete" class="btn btn-success" data-toggle="modal" data-target="#myModal" style="cursor: pointer;">Löschen</a>
to this:
<input type="submit" name="delete" class="btn btn-success" style="cursor: pointer;" value="Löschen" />
The error occurs, because you've made an <a> with a href, - which means that you're not submitting a form to the destination, - but instead just linking it (with a regular get-request without any additional parameters). This page explains a bit about it (the section about 'The Method Attribute').
But as Ali said. Try on your index.php-page, to write:
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
And see what you get, to see if your variable is defined.
Don't use an a to submit. That doesn't process the form. It just links to the page. Use:
<input type="submit" ...
and style it as needed.
The type of an a is not for how it processes a form, https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a.
Specifies the media type in the form of a MIME type for the linked URL. It is purely advisory, with no built-in functionality.
I want to show a button in my page only if a certain condition is met.
Also i want to run a query (DELETE QUERY) when i press that button.
<?php if (isset($_POST['finduser_btn']) && $noerr) :
echo "<div class='green'>
<button type='submit' class='btn' name='scoreDel'>Delete scores</button>
</div>
endif ?>
I use $noerr as FLAG to display or not the button if another button is pressed (the other button is not shown in code)
Well, how do i use scoreDel button to run a query like:
DELETE FROM scores
WHERE name = '$username$;
I think i have some issue with " and ' into the PHP echoing html tags but i'm not sure... I hope in some help, i'm getting mad.
Thanks in advance
You need a form in order to submit your action.
echo '<form action="mypage.php" method="POST"><div class="green">
<button type="submit" class="btn" name="scoreDel">Delete scores</button>
</div></form>';
Try the following:
<?php if (isset($_POST['finduser_btn']) && $noerr) : ?>
<div class='green'>
<form method="post">
<input type="text" name="finduser">
<button type='submit' class='btn' name='scoreDel'>Delete scores</button>
</form>
</div>
<?php endif ?>
Use a form to submit the button tag. Also, write html outside of PHP code if possible.
I am currently trying to make a hyperlink that calls the same page that I am on, but a different PHP function. This seems like a simple enough solution however I don't want any information displayed in the URL. A "post" seems to be the best solution but I cannot find any results as to how to make this work.
<?php
function myFirst(){
echo 'The First ran successfully.';
}
function mySecond(){
echo 'The Second ran successfully.';
}
?>
<html><body>
<?php
if (isset($_GET['run'])){
$linkchoice=$_GET['run'];
}else{
$linkchoice='';
}
switch($linkchoice){
case 'first' :
myFirst();
break;
case 'second' :
mySecond();
break;
default :
echo 'no run';
}
?>
<hr>
Link to First
<br/>
Link to Second
<br/>
Refresh No run
</body></html>
If u want to use POST by pressing something in the page, u can either use JS to turn that into a POST request, or simply submit a form.
Assuming u use jQuery
go somewhere
<form id="koko" style="display:none" target="baba/was/here/this/is/the/url" method="post">
<input type="hidden" name="run" value="boo" />
</form>
...
...
function manda_mi(){
$('#koko').submit();
}
If you want to avoid Javascript you could wrap the links in a form, and style the buttons to look like normal links.
Basically:
<button type="submit" value="first" name="action">Link to First</button>
<br/>
<button type="submit" value="second" name="action">Link to Second</button>
<br/>
<button type="submit" value="0" name="run">Refresh no Run</button>
And then just check what button was pressed.
Although the simplest option is probably Javascript.
Say I have info.php page with user info (id, name, age, etc).
On this page, there is an 'edit' button that takes the user to a form on edit.php so they can change their info. The form is populated via $_POST with id, name, age, etc.
edit.php has an 'update' button that posts back to info.php with the updated data. This all works fine.
But when I try to load edit.php within a jQuery Tools Overlay pop-up, the form in edit.php appears but the variables are not passed along. Instead they all appear as 'undefined'.
I am not sure where to place the required href element so as to pass my variables to edit.php when inside the overlay.
Any ideas?
<form action="edit.php" method="post">
<input type="hidden" name="edit" value="yes" />
<input type="hidden" name="id" value="<?php echo $row[1] ?>" />
<input type="hidden" name="name" value="<?php echo $row[2] ?>" />
<!-- this is the required href to trigger overlay -->
<a href="edit.php" rel="#overlay" style="text-decoration:none">
<input type="submit" value="Edit"/>
</a>
</form>
<div class="apple_overlay" id="overlay">
<!-- the external content is loaded inside this tag -->
<div class="contentWrap"></div>
</div>
<!-- make all links with the 'rel' attribute open overlays -->
<script>
$(function() {
// if the function argument is given to overlay,
// it is assumed to be the onBeforeLoad event listener
$("a[rel]").overlay({
mask: 'darkred',
effect: 'apple',
onBeforeLoad: function() {
// grab wrapper element inside content
var wrap = this.getOverlay().find(".contentWrap");
// load the page specified in the trigger
wrap.load(this.getTrigger().attr("href"));
}
});
});
</script>
I'm a little confused by the question but this is possibly what you are looking for...
You need to either pass the ID in the url and look up the data serverside or pass all the data in the url like so
<a href="edit.php?id=<?php echo $row[1] ?>&name="<?php echo $row[2] ?>" rel="#overlay" style="text-decoration:none">
Another way is to store name id and all that stuff in $_SESSION in php. Then info.php would save it and edit php would read it.