How do I add a PHP code that will always open/create a new text file and write user input once user clicks 'Submit' button

Johnny blee Rowland

How do I add a PHP code that will always open/create a new text file and write user input once user clicks 'Submit' button.

This is the html code

<form action="save_redirect.php" id="#form" method="post" name="#form">
  <label>Email:</label><br>
  <input id="email" name="email" placeholder='Enter A Valid Email Address' type='text'>
  <br>
  <input id='btn' name="submit" type='submit' value='Submit'>
  <?php
  include "include/redirect.php";
  ?>
</form>

This is the php code I already wrote for redirecting.

<?php
if(isset($_POST['submit'])) {
  // Fetching variable of the form which travels in URL
  $email = $_POST['email'];
  $myfile = fopen("text.txt", "w");
  fwrite($myfile, $email);
  fclose($myfile);

  if($email !='') {
    header("Location:https://www.formget.com/app/");
  }
  else {
    ?><span><?php echo "Please fill the email field! This is where you'll receive script files on.";?></span> <?php
  }
}
?>
Barmar

Use uniqid() to generate a unique filename. And you can use file_put_contents() to combine fopen()/fwrite()/fclose().

$filename = uniqid() . ".txt";
file_put_contents($filename, $email);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to add a new button in Main Activity after user clicks a button from a Popup?

How to Create graph page modal as soon as user clicks submit button

How to defer form input binding until user clicks the submit button?

How can I write code that indicates the first position in the text input by the user violates the palindrome property?

How do I read user input and write it to a .txt. file?

How do I retrieve user input from a textbox after users hit the submit button?

How do I style text input by a user?

How do i make a button that can count when a user clicks it?

How to display the value a user puts into an "input="date"" box and clicks submit button using Javascript?

How to implement select so that I can access selelected value in my code when user clicks submit button

How do I add a new line w/ text in a PHP file?

How do I prevent button code from running twice if the user clicks more than once in C#?

How can I end the cell's edit and submit the new value when the user clicks on another control?

Python- how do I write user input to an Excel file?

Add text to an input field x when user clicks button x

Can't get PHP script to write user input to text file

How do I keep a user input? (php)

python 3.x : How to write/append text to a existing file as per user input in new line?

How do I display the user input when user clicks submit button. Also clear the message when user clicks the clear button. (Angularjs)

How do I use the user input to write the output using Tkinter?

How to test the current text of a Tkinter text box widget before inserting new text after user clicks on a button?

How to add validation to user input before they submit

How can I confirm if this code blocks can verify an email once user clicks on it?

How can i changing text button by user input

How do i delete a select item from javascript once a user clicks on one of the select items

Add a button value into an input field when user clicks a button and send it to php file

How do I make text bold after the user clicks a button?

How do I populate a field depending on which button a user clicks?

How do I write a code that takes user input to form an array, and from that array the user decides if we should find the smallest or largest value?