Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.php
- <?php
- require ('functions.php');
- // detect whether or not the form has been posted
- //if( isset($_SERVER['REQUEST_METHOD'] == 'POST') )
- if ( $_SERVER['REQUEST_METHOD'] == 'POST')
- {
- $name = trim($_POST['name']);
- $email = trim($_POST['email']);
- // did they fill everything out ?
- if( empty ($name) || empty($email) )
- {
- $status = 'Please provide a name and valid email address';
- }
- // if not empty add user
- else {
- add_registered_user($name, $email);
- $status = 'thank you for registering';
- }
- }
- include ('index.tmpl.php');
- //----------------- separate file----------------------------
- //functions.php
- <?php
- function add_registered_user($name, $email)
- {
- //creates the file mailing_list.php if it doesnt exist
- //then put name and email to that file and append any other submissions
- file_put_contents('mailing_list.php', "$name: $email\n", FILE_APPEND);
- }
- // --------------------preserve input values after failed post---------------------------------
- function old($key)
- { // return old value if on POST to the value attribute
- if( !empty($_REQUEST['$key']))
- {
- return htmlspecialchars($_REQUEST['$key']);
- }
- return '';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement