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 file fwrite($fp, $output); fclose($fp); ?>