Saturday, 22 November 2008
   
Home arrow Tutorial  
 
Home
Supporto
Contattaci
Categorie Script
RSS Media Grabber Video & Foto Divertenti Storie di Vita (Flash) Video: Ricerca & Download Script Download Video Nazioni in Vendita Script per Sondaggi Host per File wap Script Creazione SlideShow Script PhotoCube Script "Make Confessions" Script Spartiti Chitarra Crea Smile Personalizzati URL Brevi & Sottodomini Script Gioco Hot Or Not Metti il Tuo Testo Sulle Img Host & Watermark Img Salva i Tuoi Preferiti Online Componenti Joomla Script a Basso Costo
Partners
StileGames
Php Tutorial
 
 
   
 
Passing Variables with Forms Print E-mail

This tutorial will (hopefully, if I can manage to be coherent) show you, my fellow php-er, how to pass a variable through 2 pages. 

 It doesn't sound very difficult, but it is a mite tricky. The way I used it was to verify information from a form submission. In this case, the user enters their info in a form and clicks

"submit,"

but instead of having the information submitted immediately, it is first displayed to the user again for them to check it. This way, he/she/it has the option of saying, "Oh, suck! I put in the wrong information!" In other case, I have a list of links, and when the user clicks on one, the script shows the person what he/she/it clicked on and asks if that's really what they wanted... we all know how mouse pointers can wander. So, on with the tutorial...

First, I have a basic HTML form, which I'm going to assume you know how to do. When the user clicks the submit button from there, the action is . With that, he/she/it is taken to the page that will check their info.

First, we make sure the temp .txt file can be opened, in "write" mode:

if(!($myFile = fopen("tempfile.txt", "w+"))) { print("Whoa there! Something broke. Try again."); exit; }

Then, we write what they entered to that tempfile.

txt: fputs($myFile, "Name: "); fputs($myFile, "$name\n\n"); fputs($myFile, "Email address: "); fputs($myFile, "$email\n\n"); fputs($myFile, "$information\n"); fclose($myFile);

Now we will reopen that file for reading only, then print the information in that file on the displayed page. When php writes to a file, it puts in slashes with any apostrophes, so we have to strip those out of the .txt file so the user doesn't get an ugly, slashed-up version of what he/she/it entered originally:

$myFile = fopen("squirrel.txt", "r"); while(!feof($myFile)) { $myLine = fgets($myFile, 3000); print(stripslashes("$myLine")); print("\n"); } fclose($myFile);

Now, since all the information is already written to a text file, none of those variables need to be passed through. However, my goal is to have that information emailed to me, and I want the email to be CC'ed to the user. Therefore, I need to pass the $email variable through to the next page. Here's how I did that: The final page's script is as follows... this script emails me the information from the text file and CC's that email to the user who entered it:

$mailTo = " , $sendTo";rn$mailSubject = "a subject"; $mailHeader = "From: $sendTo"; $myFile = fopen("tempfile.txt", "r"); $message = fread($myFile, 3000); $message=str_replace("\\","",$message); mail($mailTo, $mailSubject, $message, $mailHeader);

That's it. I hope it made sense. Perhaps someday I'll write an even simpler variable-passing tutorial based on my other script, which doesn't use the form. Just let me know if any of you think that would be helpful! However, the basic idea is the same: rename the variable in your tag. Verbosity is a curse.  

Creadit: www.phpdeveloper.org 





Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
 
< Prev   Next >
 
Se trovi uno dei nostri operatori online, contattalo prima di comprare per usufruire di uno sconto!
Servizi
Controlla PageRank
Richiedi un Preventivo
Script Gratuiti
Installazione Script
Blog Backlinks
Login Form
Prodotti Scontati
Script Nazioni in Vendita
Script Nazioni in Vendita
$49.99
$29.99
You Save: $20.00
Add to Cart
 
Copyrighted © 2006 phppod.com