Form to post variables for newsletter signup

512 views Asked by At

I'm new to html and forms and want to understand how form fields get submitted and posted to a newsletter signup url.

This is the code I have so far. When someone fills out the form and submits it, will the form action post the name and email to the url and subscribe the user to the newsletter? or do I need some kind of processing file as well?

<FORM action="http://example.com?fname=<firstname>&email=<email>&redirecturl=abcthankyou" method="post"> <p> <LABEL for="firstname">First name </LABEL> <INPUT type="text" id="firstname"><p /> <LABEL for="email">Email </LABEL><br /> <INPUT type="text" id="email"><p /> <INPUT type="submit" value="Subscribe"> <INPUT type="reset"> </p> </FORM>

Thanks in advance for any help.

2

There are 2 answers

4
DrRoach On

There are a few problems with your form. You want it to look like this with your extra bits:

<form action="http://example.com" method="post">
    <input type="text" name="firstname">
    <input type="text" name="email">
</form>

The form will then call your action page and any inputs with name set will be passed as $_POST variables as set in your method. You may want to look at - http://www.w3schools.com/html/html_forms.asp

3
T90 On

Whenever the user submits(clicks on the form input of type submit), whatever is entered in the form is packed and sent to the url mentioned in the 'action' attribute of your form. The method in which the data is sent is what we mention in the 'method' attribute. It is usually 'GET' or 'POST'.

Now, the data that is sent is in the form of key-value pairs. To make it simpler, say the user enters username and password in a login form. Then the data sent are

username => value_of_username_field
password => value_of_password_field

'username' is the key for value_of_username_field.

So if you want to use these values, and do actions like mailing them, you'll need server side scripting languages, preferably PHP.