0

Somehow I have no clue where I could insert data verification into that script to make sure the lines are not left empty when filled out

here is my php process-form-data.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$fp = fopen("Daten.txt", "a");
$savestring = $name . "\r\n" . $email . "\r\n" . $company . "\r\n" . "\r\n";
fwrite($fp, $savestring);
fclose($fp);
echo "Thank you ... please stand by ...<meta http-equiv='Refresh' content='1; URL=.\play\index.html'>";
?>

thank you for the help

  • 1
    Do you have any coding experience? We don't write code for you, and would love to see you try to solve this problem and then help you when you get stuck. Your question is too elementary to even give a tip about though. – Matthew Herbst Mar 24 '16 at 03:40

2 Answers2

0
  1. For back end validation, you can check if the $_POST variables are empty using empty()

  2. For front end validation, you can add the required attribute to your <input> field.

I recommend doing both, but if you are concerned about security I recommend you to check out this post.

Community
  • 1
  • 1
Emil Rosenius
  • 961
  • 1
  • 9
  • 24
  • Thank you all for your replies. I don't mind paying someone to help me do this. But even that I would not know where to find one. Maybe there are scripts I can buy that do this. But hard to find one that does what you want. – BigApple Mar 24 '16 at 17:03
0

A quick workaround to check if the POST data is set:

<?php

$name = isset($_POST['name']) ? $_POST['name']: '';
$email = isset($_POST['email']) ? $_POST['email']:'';
$company = isset($_POST['company'])? $_POST['company']: '';

 //In PHP 7 you can do this:

$name = $_POST['name']?? '';
$email = $_POST['email']?? '';
$company = $_POST['company']?? '';

You can then do the validation:

if(empty($name)){
    echo 'Name is blank';
    exit;    
}elseif(empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
  echo 'Email is invalid';
  exit;
}elseif(empty($company)){
 echo 'Company is blank'; 
 exit;   
}else{
   $name =  filter_var ($_POST['name'], FILTER_SANITIZE_STRING);
   $email =  filter_var ($_POST['email'], FILTER_SANITIZE_EMAIL);
   $company = filter_var ($_POST['company'], FILTER_SANITIZE_STRING);
   $fp = fopen("Daten.txt", "a");
   $savestring = $name . "\r\n" . $email . "\r\n" . $company . "\r\n" . "\r\n";
   fwrite($fp, $savestring);
   fclose($fp);
   echo "Thank you ... please stand by ...
 <meta http-equiv='Refresh' content='1; URL=.\play\index.html'>";
 }
?>

Lastly I strongly recommend to check the type of filters here

Mawia HL
  • 3,605
  • 1
  • 25
  • 46