Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Onclick event in any button of an HTML form to run a PHP script 3

Status
Not open for further replies.

GAstrada

Programmer
Sep 20, 2000
97
I know that I'm breaking the forum's rules: Look carefully in a Google's search, find a thread in this forum, and so.. before sending a question,...forguive me..

But I'm urgent to have to know:

How can I call a php script (who must perform a query in a MySql database, and change fields), from any button from an html form?........ any button that isn't a SUBMIT button, as defined in the "action" of the form.
Thats said <input type=BUTTON OnClick .....(something) >
... so, this button calls OTHER php's script, not the defined in the "action" form.

The OnClick is my headache...

I know that php runs from the server's side, and Javascript and html runs from the client's browser side.

It's impossible for html to do this. But with Javascript maybe there is a way to do this..

The sequence must be:

1. The client fills a main.html form and have many buttons to press, only one is submit (at least I think that)

2. If pressed the submit button, the program continue as it was made.

3. If pressed another button, some php's script ended with a (not pretty, but works: header("Location:main.html"); shoud make field changes in the Mysql table, and the program shuld came back to MAIN.HTML.

Tanks all, in advance!!!!
 
Use AJAX methods to call an XMLHTTP request to the script in question, receive the result and update your page accordingly.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Thanks Foamcow,!! but now I discovered that MORE than ONE submit button can exists in one form. (believe me, many people does not know this).

So, all I have to do is (from the server's side), arrange my php's script to evaluate the name (if exists), of the variables submitted from the form, (to know what button was pressed) and take the action accordingly.

Regards !!!!
 
Sorry, I misunderstood your question.
I thought you wanted to do something to the form without submitting it if a button was pressed.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Hi, yes.. This is what you have the value="blah" for..

eg.
Code:
<input type="hidden" name="uid" value="<?=$uid?>" />
<input type="submit" name="do" value="Add" />
<input type="submit" name="do" value="Edit" />
<input type="submit" name="do" value="Delete" />

Code:
switch ($_POST['do']) {
case "Add":
    usrAdd($_POST['uid']);
    break;
case "Edit":
    usrEdit($_POST['uid']);
    break;
case "Delete":
    usrDelete($_POST['uid']);
    break;
}

Olav Alexander Mjelde
Admin & Webmaster
 
Foamcow:
Excuse me my poor English: This was the reason you diden't understand completely my question, I review my question y realized that was poorly written. (another forum's rules broken!!! ... even the title of the thread was somewhat "strange").
But you are right that AJAX + XMLHTTP is the solution to make some php's script to be executed whitout (or before) submitting the form.
<forgive>..my poor English</forgive> *:O)


DaButcher:
Thanks for your VALUABLE CODE. It's the way I was thinking it shoud be, since I now know than more than ONE submit button can be in ONE form. I'm just now testing it.
I hate that the last line of the php's script that will process some submit button will look something like header("Location:main.html"), it remembers me the "goto" from the old 1970-1980 Basic, but, it's the way that it will work..

Regards!!!
 
Thanks !!!! jpadie.

A "short browse" into the link you posted me, showed me that other methods of programming are avalaible, regardless if they are web-pointing.
After 21 years writing programs in "structured languages" like Pascal, dBase, Knowledgeman, Clipper, you surely understand that is hard to me to write something like a "goto".

Regards !!!

 
but d'ya know, I grew up with programming in basic, then pascal then machine code/assembler (on RMLs) and, every now and then I really find myself missing goto's and explicit code labels: it can shortcut some code constructs majorly.

which is great (!) because php6 is to feature the goto command and named labels ;-)

 
Thanks ALL !!!! specially jpadie. The project is now ready to run. It maybe called "taxi driver", becouse "security" (GPRS), and SMS (an easy way to call a taxi) are the cornerstones of the project.
My brother "Rod" (engeener) made the dirty work: he wrote in C the interfaces: with the SMS provider,... the GPRS provider, and so, and even third-party guys that have the "Geography" of our city.... in gps....

.... our city is Montevideo, Uruguay, South America.....

I'm proud to say that next week it will be fully functionally.

Again, thanks to all: every project is made with the help of any people that loves to make something, regardless it will help or not, but ... they love make it: .... to help !!!!

gus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top