How to use a button not in forum?
Moderator: General Moderators
How to use a button not in forum?
Hi All;
I need to have the following buttons, each one to do its function:
Delete
Update
Search
Add
- Actually there are icons and text boxes, so once click on any of these buttons, I need to add the data or delete or update or seach, HOW? How to let each of these button assigned with a specific function? Should I use form and put all these buttons on this form, but in that case, how I will distringuish between clicking on Delete or Update or Search or Add button? Or I can have these buttons without need to function, but I need to do special settings and programing, so each of these buttons will do its work? How?
Any advise?
Regards
Bilal
I need to have the following buttons, each one to do its function:
Delete
Update
Search
Add
- Actually there are icons and text boxes, so once click on any of these buttons, I need to add the data or delete or update or seach, HOW? How to let each of these button assigned with a specific function? Should I use form and put all these buttons on this form, but in that case, how I will distringuish between clicking on Delete or Update or Search or Add button? Or I can have these buttons without need to function, but I need to do special settings and programing, so each of these buttons will do its work? How?
Any advise?
Regards
Bilal
- akuji36
- Forum Contributor
- Posts: 190
- Joined: Tue Oct 14, 2008 9:53 am
- Location: Hartford, Connecticut
Re: How to use a button not in forum?
Hello
All of these can be put on a html form as buttons:
each button will contain a link to a php page.
Php page will contain necessary php code to
1. connect to your db --mysql_connect function
2. issue your query mysql_query
3.issue your results statement
4. close your mysql connection
See more on mysql and php working together on db connection here:
http://www.phpvideotutorials.com/free
thanks
Rod
All of these can be put on a html form as buttons:
each button will contain a link to a php page.
Php page will contain necessary php code to
1. connect to your db --mysql_connect function
2. issue your query mysql_query
3.issue your results statement
4. close your mysql connection
See more on mysql and php working together on db connection here:
http://www.phpvideotutorials.com/free
thanks
Rod
Re: How to use a button not in forum?
Thanks a lot, actually you gave me the main track.
But the question is how to let each button contain the link to the php page? In other words, how to associate between the button and the link for the php page?
Regards
Bilal
But the question is how to let each button contain the link to the php page? In other words, how to associate between the button and the link for the php page?
Regards
Bilal
Re: How to use a button not in forum?
A single form can have multiple submit buttons. If you give all of the submit buttons the same name but different values, you can use a switch statement in your PHP script to handle each button differently.
form.html
controller.php
If you want to handle each action in its own file (delete.php, update.php, etc.), you can use include. Request variables like $_POST and $_GET will be accessible to code in the included file.
Edit: This post was recovered from search engine cache.
form.html
Code: Select all
<form action="controller.php" method="post">
<input type="submit" name="action" value="Delete" />
<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Search" />
<input type="submit" name="action" value="Add" />
</form>Code: Select all
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'Delete' :
echo 'You clicked the Delete button.';
break;
case 'Update' :
echo 'You clicked the Update button.';
break;
case 'Search' :
echo 'You clicked the Search button.';
break;
case 'Add' :
echo 'You clicked the Add button.';
break;
default :
echo 'Action Not Found';
}
}Code: Select all
case 'Delete' :
include 'delete.php';
break;
Last edited by McInfo on Thu Jun 17, 2010 1:04 pm, edited 1 time in total.
Re: How to use a button not in forum?
Or, you could do
The advantage of this is later you can expand on this "interface" and for instance add ->getSuccessMessage()
This is called adhering to an interface and is the OOP fancy way to do it. Plus you don't have to list every possible command, you can add them later by just adding a button and a new class.
Code: Select all
interface Command
{
public function execute();
}
// each command implements the command interface which just enforces consistency
class Command_Delete implements Command
{
public function execute() {}
}
// and in the controller:
$class = 'Command_' . basename( $_GET['command'] );
$command = new $class;
$command->execute();
This is called adhering to an interface and is the OOP fancy way to do it. Plus you don't have to list every possible command, you can add them later by just adding a button and a new class.
Re: How to use a button not in forum?
You can also do something like this. And pass your variables through the url address
the onClick event calls the javascript function "window.location", which in turns takes the user to the specified url address, a long with passing along the url params specified.
Code: Select all
<input type="Button" value="Drop" name="Drop" title="Drop" class="butts" onclick="window.location = 'institutions.php?delete=2'">
<input type="Button" value="Edit" name="Edit" title="Edit" class="butts" onclick="window.location = 'institutions.php?edit=2'">
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: How to use a button not in forum?
You could also just make them links... Anchor elements allow you to have icons in your "buttons," and allows you to design your buttons however you want and still be completely compatible cross-browser.
But, what do I know? :3
But, what do I know? :3
Re: How to use a button not in forum?
What do u mean by anchor elements?
Regards
Bilal
Regards
Bilal
Re: How to use a button not in forum?
Could u please help me to write the window.location javascript function? I do not know java if u can write it for me please.
jaywebguy wrote:You can also do something like this. And pass your variables through the url address
the onClick event calls the javascript function "window.location", which in turns takes the user to the specified url address, a long with passing along the url params specified.Code: Select all
<input type="Button" value="Drop" name="Drop" title="Drop" class="butts" onclick="window.location = 'institutions.php?delete=2'"> <input type="Button" value="Edit" name="Edit" title="Edit" class="butts" onclick="window.location = 'institutions.php?edit=2'">
Re: How to use a button not in forum?
Java != java script,
and if you used google there are a million examples.
and if you used google there are a million examples.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: How to use a button not in forum?
<a> is an anchor element. It is how we create hyperlinks out here on the world wide web.bghayad wrote:What do u mean by anchor elements?