mikecaba Posted October 27, 2015 Share Posted October 27, 2015 Hey guys I need help in adding security such as form validation to my PHP form which writes a new row on a csv as users submit their email. I'm a complete novice on PHP and require a bit of help. I need to... Making sure the Email field is not empty and is an actual valid address. Making sure when the submit button is pressed that the field is not empty and is a valid email address. I do want to add user feedback such as when the form is submitted and is valid the user gets a message saying 'Your email address has been added.' However I would like this to be within the same page so it could be underneath the button. How do I get around doing this? I would appreciate all your help! <form action='proces.php' method='post'><p><label>Email</label><br><input type='text' name='email' value=''></p> <p><input type='submit' name='submit' value='Submit'></p> </form><?php//read data from form$lName = filter_input(INPUT_POST, "name");$fName = filter_input(INPUT_POST, "email");$email = filter_input(INPUT_POST, "email");$phone = filter_input(INPUT_POST, "phone");$output = $fName . "\t";$output .= $lName . "\t";$output .= $email . "\t";$output .= $phone . "\n";if(empty($fname) || empty($ln) || empty($phone)){//show the form$message = 'Fill in areas in red!';$aClass = 'errorClass';}//open file for output$fp = fopen("contacts.csv", "a");//write to the filefwrite($fp, $output);fclose($fp);?> Quote Link to comment https://forums.phpfreaks.com/topic/298853-php-security-for-html-form-dynamically-adding-rows-to-csv/ Share on other sites More sharing options...
cyberRobot Posted October 27, 2015 Share Posted October 27, 2015 PHP has a built-in function to validate email addresses. More information can be found here: http://php.net/manual/en/filter.examples.validation.php Quote Link to comment https://forums.phpfreaks.com/topic/298853-php-security-for-html-form-dynamically-adding-rows-to-csv/#findComment-1524439 Share on other sites More sharing options...
benanamen Posted October 27, 2015 Share Posted October 27, 2015 (edited) I would like this to be within the same page so it could be underneath the button. Your Php logic would need to be under the form wrapped in an if if($_POST){ //Do Stuff here } Edited October 27, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298853-php-security-for-html-form-dynamically-adding-rows-to-csv/#findComment-1524470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.