Subscribe email html code
Here is an example of HTML code for a subscription form:
<form action="https://your-email-service.com/subscribe" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<input type="submit" value="Subscribe">
</form>
This code creates a simple form with a label, input field, and submit button. The action
attribute specifies the URL where the form data will be sent, and the method
attribute specifies that the form data will be sent using the POST method.
You'll need to replace https://your-email-service.com/subscribe
with the actual URL of your email service's subscription endpoint.
Here are some additional attributes you can add to the form to customize its behavior:
placeholder
: adds a hint to the input field, e.g.<input type="email" id="email" name="email" required placeholder="Enter your email address">
size
: sets the width of the input field, e.g.<input type="email" id="email" name="email" required size="30">
style
: adds CSS styles to the form, e.g.<form style="width: 300px; margin: 0 auto;">
class
: adds a CSS class to the form, e.g.<form class="subscribe-form">
onsubmit
: specifies a JavaScript function to run when the form is submitted, e.g.<form onsubmit="return validateForm()">
Here is an example of a more advanced subscription form with validation:
<form action="https://your-email-service.com/subscribe" method="post" onsubmit="return validateForm()">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<span id="email-error" style="color: red;"></span>
<input type="submit" value="Subscribe">
</form>
<script>
function validateForm() {
var email = document.getElementById("email").value;
if (!email.match(/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/)) {
document.getElementById("email-error").innerHTML = "Invalid email address";
return false;
}
return true;
}
</script>
This code adds a JavaScript function validateForm()
that checks if the email address entered is valid. If the email address is invalid, it displays an error message next to the input field. The onsubmit
attribute specifies that this function should be run when the form is submitted.