Page 1 of 1

How to use a button not in forum?

Posted: Thu Oct 29, 2009 1:35 pm
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

Re: How to use a button not in forum?

Posted: Fri Oct 30, 2009 1:55 pm
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

Re: How to use a button not in forum?

Posted: Sat Oct 31, 2009 10:59 am
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

Re: How to use a button not in forum?

Posted: Sun Nov 01, 2009 2:08 pm
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.

Re: How to use a button not in forum?

Posted: Tue Nov 03, 2009 8:20 am
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.

Re: How to use a button not in forum?

Posted: Wed Nov 04, 2009 11:47 am
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.

Re: How to use a button not in forum?

Posted: Wed Nov 04, 2009 12:52 pm
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

Re: How to use a button not in forum?

Posted: Sat Dec 26, 2009 3:19 pm
by bghayad
What do u mean by anchor elements?

Regards
Bilal

Re: How to use a button not in forum?

Posted: Sat Dec 26, 2009 3:32 pm
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.

Re: How to use a button not in forum?

Posted: Sat Dec 26, 2009 3:48 pm
by josh
Java != java script,

and if you used google there are a million examples.

Re: How to use a button not in forum?

Posted: Wed Feb 24, 2010 10:46 am
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. ;)