Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Answer Script For Yahoo Question:
- http://answers.yahoo.com/question/index?qid=20110924135432AAWKmca
- */
- $fileName = 'file.txt'; // The name of the file, as to where the data will be saved.
- $template = '
- <div style="border: 1px dotted #999;padding: 8px;">
- <p><span style="font-style: italic;">Name</span>: <span style="font-weight: bold">{NAME}</span></p>
- <p><span style="font-style: italic;">Email</span>: <span style="font-weight: bold">{EMAIL}</span></p>
- <p><span style="font-style: italic;">Message</span>:<br /> <span style="font-weight: bold">{MESSAGE}</span></p>
- </div>
- '; // Template of how you want the message to be displayed.
- $showForm = true; // Whether or not to show the form
- if(isset($_POST['submit'])){ // The Form Has been Submitted
- $name = $_POST['vardas'];
- $email = $_POST['mail'];
- $message = $_POST['tekstas'];
- if(strlen($name) === 0 || strlen($email) === 0 || strlen($message) === 0){
- echo 'All fields are required.<br />';
- }else{
- $templateFills = Array(
- '{NAME}' => $name,
- '{EMAIL}' => $email,
- '{MESSAGE}' => $message
- );
- $string = file_get_contents($fileName) or '';
- $string .= str_replace( array_keys($templateFills), array_values($templateFills), $template);
- file_put_contents($fileName, $string);
- echo $string;
- $showForm = false;
- }
- }
- if($showForm){
- echo '
- <form action="" method="post" name="forma">
- <p>
- Vardas<br />
- <input type="text" name="vardas" value="' . $_POST['vardas'] . '" />
- </p>
- <p>
- E-mail<br />
- <input type="text" name="mail" value="' . $_POST['mail'] . '" />
- </p>
- <p>
- Tekstas<br />
- <textarea cols="30" rows="8" name="tekstas">' . $_POST['tekstas'] . '</textarea>
- </p>
- <br/>
- <input value="Spausk" type="submit" name="submit" />
- </form>
- ';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement