Ask a Question related to PHP Development, Design and Development.
-
Warren Vail #1
RE: [PHP] Calling functions from Button actions
I would assume you are referring to PHP functions since that is the nature of this list and since PHP only really executes on a web server, and since the button click occurs on the browser machine, in it's strictest sense the answer to your first question "Is their an easy way to call a function based upon a button action?" is a qualified no.
However, you can simulate a direct connection by using JavaScript to sense the OnClick event on the browser machine and to force a form submit which invokes the form PHP module on the server.
One technique I like to use is to define multiple "submit" buttons with different values and each one automatically triggers the form submit, and then I can sense the button clicked by looking for its value in my PHP code (all buttons invoke the same PHP module specified in the form Action field). Your user will feel like the application is more interactive, however response will be much slower than JavaScript (running on the browser). If your user expects the same response he gets on a standalone application running on his own computer, then your user is too naive, and you should get a new one ;-).
hope this helps,
Warren Vail
-----Original Message-----
From: Robert Cummings [mailto:robert@wocmud.org]
Sent: Friday, September 12, 2003 3:36 PM
To: Dan J. Rychlik
Cc: [email]php-general@lists.php.net[/email]
Subject: Re: [PHP] Calling functions from Button actions
Any form system (I'm guessing, but I only use my own so I could be
mistaken) that allows custom validation should enable trivial function
calling based on a button click.
Cheers,
Rob.
On Fri, 2003-09-12 at 18:29, Dan J. Rychlik wrote:--> Is their an easy way to call a function based upon a button action?
>
> -Dan
..---------------------------------------------.
| Worlds of Carnage - http://www.wocmud.org |
:---------------------------------------------:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the |
| stuff of nightmares grasp for your soul. |
`---------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Warren Vail Guest
-
calling two Actions in a form
Hi, I am creating a php program with an HTML integration. Within my HTML code, I called two buttons... my question is, how can I call two... -
calling actions from a script and vice versa (CS)
Hey I just realized that I can automate a lot of my workflow in illustrator with applescript (I never realized it was scriptable) and I'm running... -
Movieclip actions/functions/methods/...?
I'm having big trouble with my movie clips, as no actions seem to work. I have the movie clips exported to actionscript, and I'm using these names,... -
Calling functions from Button actions
<? function func1() { } function func2() { } function func3() { } -
button actions
Hi all, quick question, I need to do two things for a presentation (published as a windows projector .exe file); 1. create a button that will... -
Marek Kilimajer #2
Re: [PHP] Calling functions from Button actions
Example:
<form action="action.php">
<input type="submit" name="action1" value="Execute function action1()">
<input type="submit" name="action2" value="Execute function action2()">
</form>
action.php:
function action1() {
echo "Hello, I'm action1";
}
function action2() {
echo "Hello, I'm action2";
}
if(isset($_GET['action1'])) {
action1();
}
if(isset($_GET['action2'])) {
action2();
}
Dan J. Rychlik wrote:> Is their an easy way to call a function based upon a button action?
>
> -DanMarek Kilimajer Guest
-
daniel@electroteque.org #3
Re: [PHP] Calling functions from Button actions
wont they both be set ?
i generally use a button type and onclick document.location.href to enforce
an action in the get variable like something.php?action=something> Example:
>
> <form action="action.php">
> <input type="submit" name="action1" value="Execute function action1()">
> <input type="submit" name="action2" value="Execute function action2()">
> </form>
>
> action.php:
> function action1() {
> echo "Hello, I'm action1";
> }
>
>
> function action2() {
> echo "Hello, I'm action2";
> }
>
> if(isset($_GET['action1'])) {
> action1();
> }
> if(isset($_GET['action2'])) {
> action2();
> }
>
>
> Dan J. Rychlik wrote:>>> Is their an easy way to call a function based upon a button action?
>>
>> -Dan
> --
> PHP General Mailing List ([url]http://www.php.net/[/url])
> To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]daniel@electroteque.org Guest
-
John W. Holmes #4
Re: [PHP] Calling functions from Button actions
[email]daniel@electroteque.org[/email] wrote:
No, only the button that is clicked will be set.>>>Dan J. Rychlik wrote:>>>>>Is their an easy way to call a function based upon a button action?
>>Example:
>>
>><form action="action.php">
>><input type="submit" name="action1" value="Execute function
>>action1()">
>><input type="submit" name="action2" value="Execute function
>>action2()">
>></form>
>>
>>action.php:
>>function action1() {
>> echo "Hello, I'm action1";
>>}
>>
>>
>>function action2() {
>> echo "Hello, I'm action2";
>>}
>>
>>if(isset($_GET['action1'])) {
>> action1();
>>}
>>if(isset($_GET['action2'])) {
>> action2();
>>}
> wont they both be set ?
I wouldn't rely on Javascript...> i generally use a button type and onclick document.location.href to enforce
> an action in the get variable like something.php?action=something
---John Holmes...
Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
John W. Holmes Guest
-
John W. Holmes #5
Re: [PHP] Calling functions from Button actions
[email]daniel@electroteque.org[/email] wrote:
If you're talking about presenting a list of records and using a button> apologies i generally use this system for deleting records, i give a
> confirm box if they press ok it goes to another action, i suppose i should
> change this system to submit the form instead and check for the post var ?
> i guess at least it could store the http_referer then :\
to delete a record, then you should use a method such as this...
<input type="submit" name="delete[xx]" value="Delete">
Where "xx" is the record_id (or equivalent). Then, when the form is
submitted, you just look for $_REQUEST['delete'], make sure it's an
array, grab the key using key(), and delete that record.
Simple, eh? :)
If you want an easy method for presenting a list of records and radio
buttons for each record with different statuses (like open, closed,
pending, delete, etc), and handling the status changes, check out my
column in the latest issue of php|architect. :)
--
---John Holmes...
Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
John W. Holmes Guest
-
daniel@electroteque.org #6
Re: [PHP] Calling functions from Button actions
my form action usually looks like this
some.php?action=update&ID=1
my update will look like update table set *** where _rowid=$_GET['ID']
so therefore its globally used. i'd use the id from the get var
but i guess in the delete function i could place this within the update
action so
case 'update':
delete(tablename);
update(tablename);
break;
i dont tend to like this becuase it'll be in the same action which is why i
tried the location.href way to send it to a different action, as both the
update and delete buttons are within the same form, i'm sure u could have a
delete button in a list although this leads to problems as users generally
would like the delete button in the update/view screen so they know exactly
what they are deleting so therefore which is why the buttons are in the
same form, any ideas ?
> [email]daniel@electroteque.org[/email] wrote:
>>>> apologies i generally use this system for deleting records, i give a
>> confirm box if they press ok it goes to another action, i suppose i
>> should change this system to submit the form instead and check for the
>> post var ? i guess at least it could store the http_referer then :\
> If you're talking about presenting a list of records and using a button
> to delete a record, then you should use a method such as this...
>
> <input type="submit" name="delete[xx]" value="Delete">
>
> Where "xx" is the record_id (or equivalent). Then, when the form is
> submitted, you just look for $_REQUEST['delete'], make sure it's an
> array, grab the key using key(), and delete that record.
>
> Simple, eh? :)
>
> If you want an easy method for presenting a list of records and radio
> buttons for each record with different statuses (like open, closed,
> pending, delete, etc), and handling the status changes, check out my
> column in the latest issue of php|architect. :)
>
> --
> ---John Holmes...
>
> Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
>
> php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
>
> --
> PHP General Mailing List ([url]http://www.php.net/[/url])
> To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]daniel@electroteque.org Guest
-
Stephen Tiano #7
Need Help Troubleshooting Code That Works Till It Comes to Form at End
I spent last night trying, overnight brooding (in my sleep), and this
morning, finally, finding and fixing the errant line in the code below
to get it to display in my browser the entries I made in a test name
named "users".
So I got is to display every column of every entry. But when I tried a
specialized select statement in the query box provided by the form at
the very end of this code, when I pressed the "Submit" button, nothing
changed; I was still left staring at the table of all the info in "users".
What am I missing in the form?
Thanks much.
Steve Tiano
------------------------------------------------------------------------------------------
<?php
if(!isset($query) || empty($query))
{$query = "select * from users";}
//stripslashes is necessary because the slect statement is
//coming from a form. In most systems, the magic_quotes
//setting (see Appendix A) will prepend single quotes
//with backslashes, which could be problematic.
$query=stripslashes($query);
mysql_connect("localhost", "name", "password") or die ("Could not
connect to database");
mysql_select_db("mysqlphp_db_apps_exerDB") or die ("Could not select
database");
$result = mysql_query($query) or die(mysql_error() );
$number_cols = mysql_num_fields($result);
echo "<b>query: $query</b>";
//lay out table header
echo "<table border = 1>\n";
echo "<tr align=center>\n";
for ($i=0; $i<$number_cols; $i++)
{
echo "<th>" . mysql_field_name($result, $i). "</th>\n";
}
echo "</tr>\n";//end table header
//lay out table body
while ($row = mysql_fetch_row($result))
{
echo "<tr align=left>\n";
for ($i=0; $i<$number_cols; $i++)
{
echo "<td>";
if (!isset($row[$i])) //test for null value
{echo "NULL";}
else
{echo $row[$i];}
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>";
?>
<form action="<? echo $PHP_SELF?>" method="GET">
<input type="text" name="query" size="50"><br>
<input type="submit">
</form>
Stephen Tiano Guest
-
John W. Holmes #8
Re: [PHP] Need Help Troubleshooting Code That Works Till It Comesto Form at End
Stephen Tiano wrote:
[snip]> So I got is to display every column of every entry. But when I tried a
> specialized select statement in the query box provided by the form at
> the very end of this code, when I pressed the "Submit" button, nothing
> changed; I was still left staring at the table of all the info in "users".[snip]> if(!isset($query) || empty($query))
> {$query = "select * from users";}Is register_globals ON or OFF? From you're code, you're assuming it's ON> <form action="<? echo $PHP_SELF?>" method="GET">
> <input type="text" name="query" size="50"><br>
> <input type="submit">
> </form>
>
and $query will be created. If it's off, however, there will be no
$query, only $_GET['query'] or $_REQUEST['query'].
--
---John Holmes...
Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
php|architect: The Magazine for PHP Professionals – [url]www.phparch.com[/url]
John W. Holmes Guest



Reply With Quote

