How to link a PHP file to a html button - php

I want to load a php file when the user clicks on the button, but it isn't working and php file is not loaded. Is there any way to link the php file to the button via anchor tag?
<a href="visual.php" >
<button name="visual" id="newbtn" >Add Visual device</button></a>
<a href="audio.php" ><button name="audio" id="newbtn" >Add Audio device</button></a>
I need to create a main html page which includes only two buttons and when "Add Visual device" button is clicked a php page is loaded with a form to add details about the device to visual device table in sql database. When the "Add Audio device" button is clicked it need to load the php page with form to send the data to the audio table in the db. But nothing loads when the buttons are clicked... I want to load the two pages when the respective buttons are clicked

here is the code to hit php file through anchor tag.
<html>
<body>
visit php file
</body>
</html>
here is the code to hit php file through button.
<form action="audio.php" method="get">
<input type="text" name="id">
<input type="submit" value="Open Form">
</form>

you can do it by adding onclick event as follows
<button onclick="window.location.href = 'audio.php';">Add Audio device</button>
<button onclick="window.location.href = 'visual.php';">Add Visual device</button>
//It can be useful when you are not using a <form> tag.

Related

trying to open an on click element in a new window

I have a button from an embedded piece on a page that links to a form that I want to open things in new window but currently, the page opens inside the embedded piece
Of course, I tried target=_blank but that didn't seem to work. I tried onClick="location.href='embed_newstore.php'" but that didn't work either.
<input type="button" name="op" onclick="document.location.href='embed_newstore.php'" id="edit-submit" value="<?php echo $lang['REQUEST_ADD_STORE']; ?>" class="btn btn-primary" style="color:white !important;" target="_blank"/>
expected: embed_newstore.php opens in new window/tab
actual: embed_newstore.php opens in the embed application container
Try with
onclick="window.open('embed_newstore.php');"
Try This
onclick="window.open('http://localhost/embed_newstore.php');"
it is only works if button not inside the form tags

I have an html button I'm trying to redirect to a PHP file in XAMPP

I have a button in my html form that I want it to take user to food.php when they click on it, I did this but it's not redirecting, Please help
<a href="food.php">
<button name="submit" type="button" id="food">Food - Equipment</button>
</a>
Try this:
<button>Food - Equipment</button>
Why use a button element inside a link tag? Why not just:
Food - Equipment
Try that and see if it fixes it.
A button is requested, not a link. Sometimes linked php files don't work as expected in some browsers. Use a form submit button and you'll get what you're looking for.
<form action="food.php" method="GET"> <!-- use get or post if you want
to send anything -->
<input type="submit" value="GO">
</form>

HTML and PHP: Don't opening a new window in the browser

I have a file HTML with a lot of buttons, when I click a button, the action in the HTML is a reference to a php file.
What can I do for don't open a new the page, I mean run the PHP file without opening it.
This is the form in my HTML
<form action="Controlador.php" method="POST">
<p>He querido irme a dormir a las 8:00 en viernes</p>
<input type="submit" class="button" name="1" value="Vota" />
<br>
</form>
see this How do I make a PHP form that submits to self?
do not define separate action page, use same form page for action

Detecting the source link or button use to navigate to a new webpage

There is a button and a link on a webpage, and both go to the same next page. When a user lands on the next page, I want to know whether they had clicked on the button or the link on the previous page.
How can I get that information in the php for the landing page?
UPDATE:
Add some extra parameter to the link and the button.
For the link:
link text
For the button:
<form ...>
<input type="hidden" name="source" value="button">
...
<input type="button" ...>
</form>
When processing the page inputs, check the $_REQUEST['source']

PHP Form in JQuery ColourBox

I'm trying to implement popup search window in a PHP project. I included JQuery and ColorBox & have managed to open the Search popup inline (using ColorBox plugin).
This is my code to open popup window
$(document).ready(function(){
$(".inline").colorbox({inline:true, transition:'none',speed:'10', close:'close', opacity:'0.6'});
});
Popup div has a separate <form> element to POST data.
<?php
if (isset($_POST['btnSearch']))
{
//Code to search data
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
//Some Page Content
<div class="input"><input type="submit" name="btnSearch" Value="Search"
class="button"></div>
</form>
The problem is when I click the 'Search' button it POST the form but closes the popup. How can I retain popup window opened even after the button click?
AJAX is what you're looking for. jQuery has built in AJAX support which you can read about HERE
It's real easy to use so you shouldn't have any problems implementing it

Categories