LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-21-2009, 11:23 PM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 51
PHP: How to can a PHP function without refreshing the page?


Hello,

I have a task01 function. I would like that the click on the button, does not refrest hte page. I does not work...

Here is the code:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  

 
  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 
<body>

 
 
 <?php
function task01() {
   $logfile2    = 'file.txt';
   $fp = @fopen($logfile2,'a+') or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
   
 flock($fp, LOCK_EX);
   // fputs($fp, $_POST[name]);
  //  fputs($fp, $_POST[nachricht]);
    fwrite($fp, "\r\n" );
    fwrite($fp, "_______________________\r\n" );
    fwrite($fp, "$datum\r\n");
    fwrite($fp, "Number of lines: $numLines\r\n");
    fwrite($fp, "Message envoye a $tag, $zeit der $datum.\r\n");
    fwrite($fp, "$_POST[name] \r\n");
    fwrite($fp, "$_POST[nachricht] \r\n");
    flock($fp, LOCK_UN);
    fclose($fp);
 }

?>
 
 <? // ### click button01 ?>
<form action="../ausgabe.php" method="post" name="textmail">
<table border=0 cellspacing=2 cellpadding=0 width=100%>
<tr><td nowrap align=right>Your name:</td><td>&nbsp;</td>
<td width=100%><input type="text" name="name" size=50 maxlength=120 value="<?php echo $from_name; ?>"></td></tr>
<tr><td nowrap align=right>Your E-Mail adress:</td><td></td>
<td width=100%><input type="text" name="email" size=50 maxlength=120 value="<?php echo $from_mail; ?>"></td></tr>
<tr><td nowrap align=right>Subject:</td><td></td>
<td width=100%><input type="text" name="betreff" size=50 maxlength=120 value="<?php echo $mail_subject; ?>"></td></tr>
<tr><td nowrap align=right valign=top>Content:<br><i>(max. 1.000 chars)</i></td><td></td>
<td width=100%><textarea cols="40" rows="10" name="nachricht"><?php echo $mail_text; ?></textarea></td></tr>
<tr><td></td><td></td><td>
<input type="hidden" value="1" name="s">
<input type="submit" value="Send your message." name="submit">
</td></tr>
</table>
</form>
 
 
 <? // ### click button02 ?>
<form action="task01" method="post" name="textmail">
    <input type="submit" value="Click here." name="task01">
</form>




</body>
</html>
 
Old 04-21-2009, 11:28 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,111

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
only problem is by the time you click on the link all the php is done executing,that being said it would be easier said then done
 
Old 04-22-2009, 06:19 AM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Quote:
Originally Posted by frenchn00b View Post
I have a task01 function. I would like that the click on the button, does not refrest hte page. I does not work...
PHP can't function without refreshing the page, as it runs on the server, not the client machine. However, with Ajax, Javascript is used to send a request to a script on the server, then process the response. It is usually used to update part of a page without having to refresh the whole page, but could probably achieve what you're wanting here.
 
Old 04-22-2009, 06:42 AM   #4
aspire1
Member
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 61

Rep: Reputation: 22
Perhaps they mean they don't want the form fields reset. If so sticky form using php?
 
Old 04-22-2009, 08:03 AM   #5
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by aspire1 View Post
Perhaps they mean they don't want the form fields reset. If so sticky form using php?
I just wanted at the click of the button, one single part fo the page is changed. Damn after PHP, seems that I got to learn java now
 
Old 04-23-2009, 05:11 AM   #6
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Quote:
Originally Posted by frenchn00b View Post
I just wanted at the click of the button, one single part fo the page is changed. Damn after PHP, seems that I got to learn java now
Not necessarily, or at least not too much. There are toolkits such as Sajax that allows you to script in PHP, with the Ajax/JavaScript code created automatically.
 
Old 04-23-2009, 05:57 PM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
It is not quite necessary to learn Java. PHP + Ajax can create
'non refreshing' pages updates

I 'ajaxified' pages developed in PHP without many changes. There are some documents around on the internet which suggest to refresh each and every DOM element in your page leaning heavily on Javascript. Not so. Be sure to read all pages about Ajax on the web site below.

http://www.w3schools.com/PHP/php_ajax_database.asp

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
php page displaying text that is supposed to be part of php code DragonM15 Programming 9 07-31-2008 05:58 PM
php page can't display but download as php file? taiwf Linux - Software 2 03-07-2006 06:57 PM
PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work gtrawoger Linux - Software 3 12-21-2005 07:51 AM
php function to open an html page prabhatsoni Linux - Software 2 06-14-2005 12:32 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 01:08 PM


All times are GMT -5. The time now is 02:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration