Advertisement
Guest User

index.php and functions.php

a guest
Dec 18th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. //index.php
  2. <?php
  3.  
  4. require ('functions.php');
  5. // detect whether or not the form has  been posted
  6. //if( isset($_SERVER['REQUEST_METHOD'] == 'POST')  )
  7. if ( $_SERVER['REQUEST_METHOD'] == 'POST')
  8. {
  9.     $name =  trim($_POST['name']);
  10.     $email =  trim($_POST['email']);
  11.  
  12.     // did they fill everything out ?
  13.     if( empty ($name) || empty($email) )
  14.     {
  15.         $status = 'Please provide a name and valid email address';
  16.     }
  17.     // if not empty add user
  18.     else {
  19.         add_registered_user($name, $email);
  20.         $status = 'thank you for registering';
  21.     }
  22.  
  23. }
  24.  
  25.  
  26. include ('index.tmpl.php');
  27.  
  28. //----------------- separate file----------------------------
  29. //functions.php
  30.  
  31. <?php
  32.  
  33. function add_registered_user($name, $email)
  34. {
  35.     //creates the file mailing_list.php if it doesnt exist
  36.     //then put name and email to that file and append any other submissions
  37.     file_put_contents('mailing_list.php', "$name: $email\n", FILE_APPEND);
  38. }
  39.  
  40. // --------------------preserve input values after failed post---------------------------------
  41.  
  42. function  old($key)
  43. { // return old value if on POST to the value attribute
  44.      if( !empty($_REQUEST['$key']))
  45.       {
  46.             return htmlspecialchars($_REQUEST['$key']);
  47.       }
  48.         return '';
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement