How to use a button not in forum?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
bghayad
Forum Newbie
Posts: 9
Joined: Thu Oct 29, 2009 1:13 pm

How to use a button not in forum?

Post by bghayad »

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
User avatar
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?

Post by akuji36 »

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
bghayad
Forum Newbie
Posts: 9
Joined: Thu Oct 29, 2009 1:13 pm

Re: How to use a button not in forum?

Post by bghayad »

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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to use a button not in forum?

Post by McInfo »

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

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>
controller.php

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';
    }
}
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.

Code: Select all

case 'Delete' :
    include 'delete.php';
    break;
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 1:04 pm, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How to use a button not in forum?

Post by josh »

Or, you could do

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();
 
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.
jaywebguy
Forum Newbie
Posts: 5
Joined: Wed Nov 04, 2009 11:06 am

Re: How to use a button not in forum?

Post by jaywebguy »

You can also do something like this. And pass your variables through the url address

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'">
 
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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How to use a button not in forum?

Post by superdezign »

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
bghayad
Forum Newbie
Posts: 9
Joined: Thu Oct 29, 2009 1:13 pm

Re: How to use a button not in forum?

Post by bghayad »

What do u mean by anchor elements?

Regards
Bilal
bghayad
Forum Newbie
Posts: 9
Joined: Thu Oct 29, 2009 1:13 pm

Re: How to use a button not in forum?

Post by bghayad »

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

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'">
 
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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: How to use a button not in forum?

Post by josh »

Java != java script,

and if you used google there are a million examples.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How to use a button not in forum?

Post by superdezign »

bghayad wrote:What do u mean by anchor elements?
<a> is an anchor element. It is how we create hyperlinks out here on the world wide web. ;)
Post Reply