Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

HTML 5 newsletter

Fluxcabury
 Share

Hi so I have a form for a newsletter were the user enters some text to sine up to the newsletter but does anyone know how to add the input from the user to a text file if anyone knows that would be amazing thanks.(The website is programmed in HTML 5 and css)

    <section id="newsletter">
        <div class="container">
            <h1>Subscribe to our Newsletter</h1>
            <form>
                <input type="email" placeholder="Enter Email...">
                <button type="submit" class="button_1">Submit</button>
            </form>
        </div>
    </section>

 

Link to comment
Share on other sites

Link to post
Share on other sites

You need to use Javascript (Jquery could also be used) to pass along user input. 

Depending on what you want to do, this might be of use:

<html>
  <body>
Field1: <input type="text" id="name" value="Please enter name here"><br>

<button onclick="myFunction()">Submit</button>

<p>A function is triggered when the button is clicked. The function can do something with the name</p>

<script>
function myFunction() {
  //This saves a name in a variable. You can pass this along to a database using PHP or something. just depends on what you do.
  //Just keep in mind Javascript is something that is run on the user side, so it doesn't save anything to your database here.
  //You might want to implement some anti spam feature too, as this is easy to see code people can inject a ton of stuff in
  nameOfUser = document.getElementById("name").value;
}
</script>

</body>
</html>

 

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Minibois said:

You need to use Javascript (Jquery could also be used) to pass along user input. 

Depending on what you want to do, this might be of use:


<html>
  <body>
Field1: <input type="text" id="name" value="Please enter name here"><br>

<button onclick="myFunction()">Submit</button>

<p>A function is triggered when the button is clicked. The function can do something with the name</p>

<script>
function myFunction() {
  //This saves a name in a variable. You can pass this along to a database using PHP or something. just depends on what you do.
  //Just keep in mind Javascript is something that is run on the user side, so it doesn't save anything to your database here.
  //You might want to implement some anti spam feature too, as this is easy to see code people can inject a ton of stuff in
  nameOfUser = document.getElementById("name").value;
}
</script>

</body>
</html>

 

Thanks do you know a way were I can save it on my database instead?

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Fluxcabury said:

Thanks do you know a way were I can save it on my database instead?

Actually, no. I know my way around HTML, CSS, Javascript, but not much more than that :P

But I just looked it up, how to save stuff to a MySQL database and it seems like Javascript is not the recommended way to save stuff to one. using PHP is better practice.

This looks like a solid tutorial on it:

https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP

 

They have the full code on their site, but it's likely better to just read through this to understand it. They also go over how to create a database.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Minibois said:

Actually, no. I know my way around HTML, CSS, Javascript, but not much more than that :P

But I just looked it up, how to save stuff to a MySQL database and it seems like Javascript is not the recommended way to save stuff to one. using PHP is better practice.

This looks like a solid tutorial on it:

https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP

 

They have the full code on their site, but it's likely better to just read through this to understand it. They also go over how to create a database.

Ok thank for the help

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×