The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Making a Form, Using PHP to store form data
nbrown2000
post May 28 2017, 01:00 PM
Post #1





Group: Members
Posts: 1
Joined: 28-May 17
Member No.: 26,419



I am completely new to HTML and PHP, and just coding in general and need some help with making a form that saves the inputted data in a simple .txt file in the same directory on my web server and emails me whenever the form is submitted.

I have the HTML form all setup and looking how I want on the web page, now I need to have the data saved in a formatted .txt file and have an email sent to me whenever the form is submitted, which I have no clue how to do so please bear with me. I need step by step help because like I said, I've never used PHP before and have no idea how to start. Sorry about that...

Anyways, here is the code snippet from the form, this is as far as I've gotten. I know as a basic I need to make the action of the form be a .php file but I don't know how to format the .php file or what to put in it.
CODE

<form method="post" action="script.php">                
   Your Username
   <input name="name1" type="text" maxlength="25" required/>
   Player Who Referred You
   <input name="name2" type="text" maxlength="25" required/>
   Choose a Reward
   <select name="reward">
      <option value="r1">value1</option>
      <option value="r2">value2</option>
      <option value="r3">value3</option>
      <option value="r4">value4</option>
   </select>            
   <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit Referral" />
</form>

How I'd like the .txt file to be formatted is to have "[name1] was referred by [name2] and chose [reward]" Is there any way to accomplish this, as well as making it so that the form can only be submitted once per user?

Again, I am completely new to this and need step by step instructions on how to accomplish this.

Thank you for your time.

This post has been edited by nbrown2000: May 28 2017, 01:01 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 28 2017, 03:49 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,628
Joined: 10-August 06
Member No.: 7



QUOTE(nbrown2000 @ May 28 2017, 08:00 PM) *

I've never used PHP before and have no idea how to start.

See http://php.net/manual/en/tutorial.php for the basics.

QUOTE
I know as a basic I need to make the action of the form be a .php file but I don't know how to format the .php file or what to put in it.

You don't anything special, just the PHP tags around the PHP code. The file itself may not need a .php extension, depending on how you've configured your server.

QUOTE
How I'd like the .txt file to be formatted is to have "[name1] was referred by [name2] and chose [reward]" Is there any way to accomplish this

You can use PHP's mail() function to send you the mail, and file_put_contents() to write to the text file (see the PHP manual for details). A little care needs to be taken with the email part, so your script can't be hacked to send out spam.

QUOTE
as well as making it so that the form can only be submitted once per user?

You might check that a user- and referrer name pair doesn't already exist in the text file, but it's hard to advice without knowing how and why the users arrive to your form, and how the rewards are delivered.

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 03:28 AM