Having a problem mixing HTML and PHP

This is a discussion on Having a problem mixing HTML and PHP within the PHP Language forums, part of the PHP Programming Forums category; I am trying to use a form with a button that calls a verification script but can't seem to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-23-2006
tony@tony.com
 
Posts: n/a
Default Having a problem mixing HTML and PHP


I am trying to use a form with a button that calls a verification script
but can't seem to get the script to run at all - can anyone tell me if
this SHOULD work in a forms onCLick or have I got the syntax wrong?

The function is previously included with include_once('library.php');
This seems to work ok. I dont get any php errors if I turn on reporting.
The function checks out ok on its own. I've also tried a simple echo with
no luck. the page is called myform.php (not .html)

The form button has:

<input type=button name="btOne" value="Click-Me" id = "mButton" onClick =
"<?PHP verify(); ?>" >

I did think you could do this - am I wrong?
(Incidently I'm also having trouble getting onBlur to work in a similar
form with PHP.)

thanks.
Reply With Quote
  #2 (permalink)  
Old 05-23-2006
Rik
 
Posts: n/a
Default Re: Having a problem mixing HTML and PHP

tony@tony.com wrote:
> <input type=button name="btOne" value="Click-Me" id = "mButton"
> onClick = "<?PHP verify(); ?>" >
>
> I did think you could do this - am I wrong?


Yes, you are

> (Incidently I'm also having trouble getting onBlur to work in a
> similar form with PHP.)


PHP != javascript.

It runs on the server not onthe clients machine, so simply speaking as soon
as the content is sent it's job is done. It can't tell what you are doing in
a html page. If you want PHP to handle (new) values, you will have to send
them to the server. In most cases this means requesting a new page.

Grtz,
--
Rik Wasmus


Reply With Quote
  #3 (permalink)  
Old 05-23-2006
Kim André Akerĝ
 
Posts: n/a
Default Re: Having a problem mixing HTML and PHP

tony@tony.com wrote:

>
> I am trying to use a form with a button that calls a verification
> script but can't seem to get the script to run at all - can anyone
> tell me if this SHOULD work in a forms onCLick or have I got the
> syntax wrong?
>
> The function is previously included with include_once('library.php');
> This seems to work ok. I dont get any php errors if I turn on
> reporting. The function checks out ok on its own. I've also tried a
> simple echo with no luck. the page is called myform.php (not .html)
>
> The form button has:
>
> <input type=button name="btOne" value="Click-Me" id = "mButton"
> onClick = "<?PHP verify(); ?>" >
>
> I did think you could do this - am I wrong?
> (Incidently I'm also having trouble getting onBlur to work in a
> similar form with PHP.)


PHP is processed on the server, and does this *before* the user ever
sees the HTML page, meaning that the verify() you have is called before
the page is displayed to the user.

Rather use a submit button and let the script referenced to in the
"action" attribute of the <form> tag handle the verification of the
fields.

A process like the one you're shooting for can be done using AJAX, but
in this case, that could be more trouble that it's actually worth.

--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:02 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0