phphtmlcssforms

Having trouble with this <form> (adding space/return upon form entry)


I have been making a form that lets you enter your email and it gets sent to site.com/folder/data.txt. It's password protected now and it is working how I would like it to except for the fact that I'm not sure how to make it add a space or return between entries.

here is an example of the entries I've entered so far: test@mail.comtest@mail.comother@mail.com As you can see, there isn't a space or a return (which I would like) in between the entries.

here is the code:

<?php
              
if(isset($_POST['textdata']))
{
$data=$_POST['textdata'];

$fp = fopen('private/data.txt', 'a');
fwrite($fp, $data);
fclose($fp);
}
?>
<html> 
    <style>
@use postcss-preset-env {
  stage: 0
}

body {
  min-height: 100vh;
  display: grid;
  align-items: center;
}

form {
  display: flex;
  flex-wrap: wrap;
  
  & > input {
    flex: 1 1 10ch;
    margin: .5rem;
    
    &[type="email"] {
      flex: 3 1 30ch;
    }
  }
}

input {
  border: none;
  background: hsl(0 0% 93%);
  border-radius: .25rem;
  padding: .75rem 1rem;
  
  &[type="submit"] {
    background: hotpink;
    color: white;
    box-shadow: 0 .75rem .5rem -.5rem hsl(0 50% 80%);
  }
}
        </style>      
<body>
<form method="POST">
  <input type="email" placeholder="Email Address" name="textdata">
  <input type="submit" value="Subscribe">
</form>
</body>
</html>

If anyone knows how to make it add a return or space between entries please let me know. I'm guessing it's something very simple in the css part. is that even css? php? I have no idea what I'm talking about or doing.

Does anyone have a quick solution for centering that form? I had centered the other one that I didn't end up going with but it was a whole different setup.


Solution

  • You don't know where to update so the answer is, in your php file. By your explanation what I understood is, you have one form and on each entry data will be saved to a file right? if so then update your php file. Variable now having some email so to separate each email we can use comma or space here I would suggest comma so to add or to append comma just use . operator like this $data=$_POST['textdata'].","; so on each entry there will a comma to separate.