Php Form


Published on

Published in: Business, Economy & Finance
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Php Form

  1. 1. PHP<br />FORMS<br />
  2. 2. html form<br />Forms are a vital tool for the webmaster to receive information from the web surfer, such as: their name, email address, credit card, etc. A form will take input from the viewer and depending on your needs, you may store that data into a file, place an order, gather user statistics, register the person to your web forum, or maybe subscribe them to your weekly newsletter.<br />
  3. 3. form text fields<br />Input fields are going to be the meat of your form&apos;s sandwich. The &lt;input&gt; has a few attributes that you should be aware of.<br /> type - Determines what kind of input field it will be. Possible choices are text, submit, and password.<br /> name - Assigns a name to the given field so that you may reference it later.<br /> size - Sets the horizontal width of the field. The unit of measurement is in blank spaces.<br />maxlength - Dictates the maximum number of characters that can be entered.<br />
  4. 4. Sample 1<br />&lt;form method=&quot;post&quot; action=&quot;;&gt; Name: &lt;input type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;40&quot; name=&quot;name&quot;&gt; &lt;br /&gt; Password: &lt;input type=&quot;password&quot; size=&quot;10&quot; maxlength=&quot;10&quot; name=&quot;password&quot;&gt;&lt;/form&gt;<br />
  5. 5. html form email<br />Now we will add the submit functionality to your form. Generally, the button should be the last item of your form and have its name attribute set to &quot;Send&quot; or &quot;Submit&quot;. Name defines what the label of the button will be. Here is a list of important attributes of the submit:<br />In addition to adding the submit button, we must also add a destination for this information and specify how we want it to travel to that place. Adding the following attributes to your &lt;form&gt; will do just this.<br /> method - We will only be using the post functionality of method, which sends the data without displaying any of the information to the visitor.<br /> action - Specifies the URL to send the data to. We will be sending our information to a fake email address.<br />
  6. 6. Sample 2<br /> &lt;form method=&quot;post&quot; action=&quot;;&gt; Name: &lt;input type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;40&quot; name=&quot;name&quot;&gt; &lt;br /&gt; Password: &lt;input type=&quot;password&quot; size=&quot;10&quot; maxlength=&quot;10&quot; name=&quot;password&quot;&gt;&lt;br /&gt;&lt;input type=&quot;submit&quot; value=&quot;Send&quot;&gt; &lt;/form&gt;<br />
  7. 7. html radio buttons<br />Radio buttons are a popular form of interaction. You may have seen them on quizzes, questionnaires, and other web sites that give the user a multiple choice question. Below are a couple attributes you should know that relate to the radio button.<br /> value - specifies what will be sent if the user chooses this radio button. Only one value will be sent for a given group of radio buttons (see name for more information).<br /> name - defines which set of radio buttons that it is a part of. Below we have 2 groups: shade and size.<br />
  8. 8. Sample 3<br /> &lt;form method=&quot;post&quot; action=&quot;;&gt; What kind of shirt are you wearing? &lt;br /&gt; Shade: &lt;input type=&quot;radio&quot; name=&quot;shade&quot; value=&quot;dark&quot;&gt;Dark &lt;input type=&quot;radio&quot; name=&quot;shade&quot; value=&quot;light&quot;&gt;Light &lt;br /&gt; Size:&lt;input type=&quot;radio&quot; name=&quot;size&quot; value=&quot;small&quot;&gt;Small &lt;input type=&quot;radio&quot; name=&quot;size&quot; value=&quot;medium&quot;&gt;Medium &lt;input type=&quot;radio&quot; name=&quot;size&quot; value=&quot;large&quot;&gt;Large &lt;br /&gt; &lt;input type=&quot;submit&quot; value=&quot;Email Myself&quot;&gt; &lt;/form&gt;<br />
  9. 9. html check boxes<br />Check boxes allow for multiple items to be selected for a certain group of choices. The check box&apos;s name and value attributes behave the same as a radio button.<br />
  10. 10. Sample 4<br /> &lt;form method=&quot;post&quot; action=&quot;;&gt; <br /> Select your favorite cartoon characters. <br />&lt;input type=&quot;checkbox&quot; name=&quot;toon” value=&quot;Goofy&quot;&gt;Goofy <br />&lt;input type=&quot;checkbox&quot; name=&quot;toon&quot; value=&quot;Donald&quot;&gt;Donald <br />&lt;input type=&quot;checkbox&quot; name=&quot;toon&quot; value=&quot;Bugs&quot;&gt;Bugs Bunny <br />&lt;input type=&quot;checkbox&quot; name=&quot;toon&quot; value=&quot;Scoob&quot;&gt;Scooby Doo<br />&lt;input type=&quot;submit&quot; value=&quot;Email Myself&quot;&gt; <br />&lt;/form&gt;<br />
  11. 11. html drop down lists<br />Drop down menues are created with the &lt;select&gt; and &lt;option&gt; tags. &lt;select&gt; is the list itself and each &lt;option&gt; is an available choice for the user.<br />
  12. 12. Sample 5<br /> &lt;form method=&quot;post&quot; action=&quot;;&gt; <br />College Degree? <br />&lt;select name=&quot;degree&quot;&gt; &lt;option&gt;Choose One&lt;/option&gt; <br /> &lt;option&gt;Some High School&lt;/option&gt; <br /> &lt;option&gt;High School Degree&lt;/option&gt; <br /> &lt;option&gt;Some College&lt;/option&gt; <br /> &lt;option&gt;Bachelor&apos;s Degree&lt;/option&gt; &lt;option&gt;Doctorate&lt;/option&gt; <br />&lt;input type=&quot;submit&quot; value=&quot;Email Yourself&quot;&gt; &lt;/select&gt; &lt;/form&gt;<br />
  13. 13. html selection forms<br />Yet another type of form, a highlighted selection list. This form will post what the user highlights. Basically just another type of way to get input from the user.<br />The size attribute selects how many options will be shown at once before needing to scroll, and the selected option tells the browser which choice to select by default.<br />
  14. 14. Sample 6<br /> &lt;form method=&quot;post&quot; action=&quot;;&gt; <br />Musical Taste &lt;select multiple name=&quot;music&quot; size=&quot;4&quot;&gt; <br />&lt;option value=&quot;emo&quot; selected&gt;Emo&lt;/option&gt; <br />&lt;option value=&quot;metal/rock&quot; &gt;Metal/Rock&lt;/option&gt; <br />&lt;option value=&quot;hiphop&quot; &gt;Hip Hop&lt;/option&gt; <br />&lt;option value=&quot;ska&quot; &gt;Ska&lt;/option&gt; <br />&lt;option value=&quot;jazz&quot; &gt;Jazz&lt;/option&gt; <br />&lt;option value=&quot;country&quot; &gt;Country&lt;/option&gt; <br />&lt;option value=&quot;classical&quot; &gt;Classical&lt;/option&gt; <br />&lt;option value=&quot;alternative&quot; &gt;Alternative&lt;/option&gt; <br />&lt;option value=&quot;oldies&quot; &gt;Oldies&lt;/option&gt; &lt;option value=&quot;techno&quot; &gt;Techno&lt;/option&gt; <br />&lt;/select&gt; &lt;input type=&quot;submit&quot; value=&quot;Email Yourself&quot;&gt; &lt;/form&gt;<br />
  15. 15. html upload forms<br />An upload form consists of three basic parts. The first being a hidden field. This hidden field does nothing more than limit the allowed file size of our uploaded file. The second part is the input field itself. In this field, the user has the option to type in the full local URL of the file or he/she may click the browse button to thumb through directory after directory. HTML codes this automatically when we place the type=&quot;file&quot; attribute within the input tag.<br />
  16. 16. Sample 7<br /> &lt;input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;100&quot; /&gt; &lt;input name=&quot;file&quot; type=&quot;file&quot; /&gt;<br />
  17. 17. html text areas<br />Text areas serve as an input field for viewers to place their own comments onto. Forums and the like use text areas to post what you type onto their site using scripts. For this form, the text area is used as a way to write comments to somebody.<br />Rows and columns need to be specified as attributes to the &lt;textarea&gt; tag. Rows are roughly 12pixels high, the same as in word programs and the value of the columns reflects how many characters wide the text area will be. i.e. The example below shows a text area 5 rows tall and 20 characters wide. Another attribute to be aware of is the wrap. Wrap has 3 values.<br />wrap=<br />&quot;off&quot;<br />&quot;virtual&quot;<br />&quot;physical&quot;<br />Virtual means that the viewer will see the words wrapping as they type their comments, but when the page is submitted to you, the web host, the document sent will not have wrapping words.Physical means that the text will appear both to you, the web host, and the viewer including any page breaks and additional spaces that may be inputed. The words come as they are.Off of course, turns off word wrapping within the text area. One ongoing line.<br />
  18. 18. Sample 8 <br />&lt;form method=&quot;post&quot; action=&quot;;&gt; &lt;textarea rows=&quot;5&quot; cols=&quot;20&quot; wrap=&quot;physical&quot; name=&quot;comments&quot;&gt;<br />Enter Comments Here &lt;/textarea&gt; <br />&lt;input type=&quot;submit&quot; value=&quot;Email Yourself&quot;&gt; &lt;/form&gt;<br />
  19. 19. using php with html forms<br />t is time to apply the knowledge you have obtained thus far and put it to real use. A very common application of PHP is to have an HTML form gather information from a website&apos;s visitor and then use PHP to do process that information. In this lesson we will simulate a small business&apos;s website that is implementing a very simple order form.<br />
  20. 20. Sample 9<br />&lt;html&gt;&lt;body&gt; &lt;h4&gt;Tizag Art Supply Order Form&lt;/h4&gt; &lt;form&gt; &lt;select&gt; &lt;option&gt;Paint&lt;/option&gt; &lt;option&gt;Brushes&lt;/option&gt; &lt;option&gt;Erasers&lt;/option&gt; &lt;/select&gt; Quantity: &lt;input type=&quot;text&quot; /&gt; &lt;input type=&quot;submit&quot; /&gt; &lt;/form&gt; &lt;/body&gt;&lt;/html&gt;<br />
  21. 21. Sample 10-Modified 9<br />&lt;html&gt;&lt;body&gt; &lt;h4&gt;Tizag Art Supply Order Form&lt;/h4&gt; &lt;form action=&quot;process.php&quot; method=&quot;post&quot;&gt; &lt;select name=&quot;item&quot;&gt; &lt;option&gt;Paint&lt;/option&gt; &lt;option&gt;Brushes&lt;/option&gt; &lt;option&gt;Erasers&lt;/option&gt; &lt;/select&gt; Quantity: &lt;input name=&quot;quantity&quot; type=&quot;text&quot; /&gt; &lt;input type=&quot;submit&quot; /&gt; &lt;/form&gt; &lt;/body&gt;&lt;/html&gt;<br />
  22. 22. Php post<br />We want to get the &quot;item&quot; and &quot;quantity&quot; inputs that we have specified in our HTML form. Using an associative array (this term is explained in the array lesson), we can get this information from the $_POST associative array.<br />The proper way to get this information would be to create two new variables, $item and $quantity and set them equal to the values that have been &quot;posted&quot;.<br />
  23. 23. Sample 11<br />&lt;html&gt;&lt;body&gt; <br />&lt;?php $quantity = $_POST[&apos;quantity&apos;]; $item = $_POST[&apos;item&apos;]; <br />echo &quot;You ordered &quot;. $quantity . &quot; &quot; . $item . &quot;.&lt;br /&gt;&quot;; <br />echo &quot;Thank you for ordering from Art Art Supplies!&quot;; ?&gt; &lt;/body&gt;&lt;/html&gt;<br />
  24. 24. Php get function<br />The get method is different in that it passes the variables along to the &quot;process.php&quot; web page by appending them onto the end of the URL. The URL, after clicking submit, would have this added on to the end of it:<br />&quot;?item=##&quantity=##&quot;<br />The question mark &quot;?&quot; tells the browser that the following items are variables. Now that we changed the method of sending information on &quot;order.html&quot;, we must change the &quot;process.php&quot; code to use the &quot;$_GET&quot; associative array.<br />
  25. 25. Sample 12<br />&lt;html&gt;&lt;body&gt; &lt;h4&gt;Art ArtSupply Order Form&lt;/h4&gt; &lt;form action=&quot;process.php&quot; method=“get&quot;&gt; &lt;select name=&quot;item&quot;&gt; &lt;option&gt;Paint&lt;/option&gt; &lt;option&gt;Brushes&lt;/option&gt; &lt;option&gt;Erasers&lt;/option&gt; &lt;/select&gt; Quantity: &lt;input name=&quot;quantity&quot; type=&quot;text&quot; /&gt; &lt;input type=&quot;submit&quot; /&gt; &lt;/form&gt; &lt;/body&gt;&lt;/html&gt;<br />