TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-01-2008, 01:42 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default fetch data in a form without using post?

let's say that i'll be making functions that should be able to execute in the page while not making use of post method...

like this..

<form>
<input type = "text" name = "text" />
<input type = "button" name = "call" onclick = "<?call();"?>" />
</form>

correct me if i'm wrong but is this possible...
kororo203 is offline  
Reply With Quote
Old 05-01-2008, 01:49 AM   #2 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

the onclick event is for javascript, not php. So you can't do this.
You can execute the call() function using an ajax call...
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 05-01-2008, 01:55 AM   #3 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default

i think that the onclick is an available option for the input type button isn't it?
kororo203 is offline  
Reply With Quote
Old 05-01-2008, 12:01 PM   #4 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

yes but only for javascript:

input type="text" onclick="[javascriptCode]">


input type="text" onclick="alert('test')">

The above will work because it's executed on the client's machine, but the php code is parsed before the page is send to the client (on the server) so it is impossible to know when the user will click it.
However you can make an ajax call:


input type="text" onclick="$.get('page.php')">

And page.php will have a call to you function: <?call();"?>

This will work. (The above code uses jQuery library)
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 05-01-2008, 03:04 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,216
Thanks: 17
Village Idiot is on a distinguished road
Default

Javascript is a client side language and can be executed at any time. PHP is a server side language and is done parsing the code when you see the page. Javascript starts after PHP ends. Since they are ran at different times, you can not call PHP from javascript. What you can do is use ajax to send a request to a PHP page and get the response. I have a limited knowledge of javascript, so someone else will have to help you with that.
Village Idiot is offline  
Reply With Quote
Old 05-14-2008, 01:37 AM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 305
Thanks: 44
sarmenhb is on a distinguished road
Default

perhaps if we did this then its possible


Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">

function jscall() {

var output = "<?php echo $output = "php passwed to javascript"; ?>";
alert(output);


}
</script>
</head>

<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="submit" value="submit" onclick="jscall()" />
</form>
</body>
</html>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:57 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design