Class Checkpoint

Making Parkwood Vale · Part 7 of 13

Part 7a

Build the sign in, register and forgot password forms in HTML and Bootstrap.

We make the three account forms the site needs. This part is the HTML and Bootstrap only; Part 7b makes them work with PHP and the database. In this part: 0:18 What the forms are for 1:07 Creating account.php from the existing template 3:58 The sign in form, and the GET and POST methods 6:59 Email and password fields with labels 10:44 The submit button 12:10 Links to forgot password and register 14:46 The forgot password page 16:41 The register page: name, email and password fields 19:20 A terms checkbox 21:55 Centring the form with Bootstrap flex classes Software: Adobe Dreamweaver, UwAmp, HTML, Bootstrap.
Transcript
  1. Welcome back. In our previous sessions then, we have gone through setting up UwAmp,
  2. setting up our database, and creating the basic HTML of our site.
  3. In our last session, we should have gone through some JavaScript to add in some
  4. advanced features as an image slider.
  5. In today's session, we're going to look at logging in to our library system.
  6. We're going to start by creating our HTML form to submit to our PHP
  7. server that will query our MySQL database.
  8. If all the credentials match, we'll then redirect the user to a logged in page,
  9. creating session item along the way to make sure we know they're logged in.
  10. If they aren't logged in, we're going to redirect them back to the login page with
  11. an error message.
  12. Alongside this, we're going to create a sign up function so that if the user doesn't
  13. exist in the database, they can join as a standard user.
  14. Let's begin.
  15. Okay, so I jumped back onto my student machine here and as you can see, I'm on
  16. Parkwood Vale's website on the accounts page.
  17. If I reload it very quickly, you can see that it starts off with the same header
  18. information, same information based around this image slider, and then just below,
  19. we have our form. Now, I should say at this point, if you know how to build a form,
  20. if you're happy to build your form, you don't need to watch this video.
  21. That's all we're going to be doing is creating our forms.
  22. Very simple, but there's going to be a part B video that goes to all the PHP
  23. technicality side of things. What I'm going to do then is I'm going to go back to
  24. mine and as you can see here's my version.
  25. If I click on to account at the moment it crashes there is no account page so I need
  26. to go in and create that. I'm going to load up Dreamweaver.
  27. I've already loaded UwAmp and let's get into it then.
  28. So on the side here I'm just going to minimize these for a second just to make it a
  29. little bit easier. It reloads my last open file which was the
  30. last time. I'm going to close these off and I'm going to create a new file.
  31. It is going to be called account, or it would be called account if it didn't decide
  32. to rename itself,
  33. .php because it will be a PHP file.
  34. Now, when I open up account.php, it already has some pre-tags in place.
  35. I'm just going to delete it and connect to my testing server just to make sure that
  36. everything
  37. To start with, what I want to do essentially is recreate part of my
  38. homepage. So I want it to look like this to start with at the top here looking
  39. exactly the same. So what I'm going to do is I'm going to open up my index page
  40. here. I'm going to highlight this top section, which I think takes my header
  41. information. And I'm going to go all the way down to where it says end gallery.
  42. I'm going to highlight all of this section here, copy it, paste it, save it.
  43. Now, that's not going to function at the moment because I also need to go back in
  44. and take my end div tags and my footer element, copy it,
  45. paste it, and put that there. So, everything should line up now.
  46. And when I refresh and re-check that page, let's
  47. go on to account and just put it to my test server.
  48. refresh that page i get the basic elements in place it has the same feel
  49. as my not browse book sorry home page but it hasn't got the form elements
  50. that we see here on the Parkwood Vale site here so i'm going to get rid of i
  51. can leave that one there for a second actually just so we can see what we're
  52. comparing against and i'm going to go in to start creating my form so let's start
  53. with my normal add or say login form
  54. element and I'm going to end my login form
  55. and let's just keep the capitalization where I've got it previously there
  56. we go so this is where my form element is going to sit right now if I was to just
  57. because I've been missing some elements of style.
  58. First thing I need to do is put it into its own div.
  59. It's going to be a class and my class for it is going to be equal to
  60. padding for just to make sure that I got enough padding space around it so that it
  61. looks as I expect it to.
  62. From there then I'm going to add in a form tag and
  63. what my form tag does is it takes several different options.
  64. First one being the action. The action is going to be where are we going to send and
  65. process our form to. So I'm going to put in full stop to make sure that it starts
  66. from our current page forward slash and then I'm going to put in sign in
  67. as my page that I'm going to
  68. send it to.
  69. From there then, what I'm going to do is say the method, how it's going to process
  70. its information, what it's going to do is go into post that information.
  71. So I have the options to do a delete method, a get method, a post
  72. method, or a put method. Delete is generally reserved for deletion of different
  73. elements within PHP.
  74. Get methods are what goes in the very top URL.
  75. So if you had a URL in place, account, and then you had a question mark, and
  76. then you said id equals cpd
  77. .jjones, this information here would be in the get string
  78. that is visible to everybody.
  79. The put method is similar to the post method we're going to use.
  80. The put is generally used for updating.
  81. I'm going to say post it
  82. and in there then that will be my basic elements.
  83. I will put in an ID for it so that I know which form it's working with.
  84. I can call it signIn and I'm going to end that form and end that form tag.
  85. Now my sign-in page doesn't actually exist, but what would happen is if I
  86. was to put something in here and post that to that page, I'd be able to receive it
  87. on PHP and make any alterations or use that data in any way.
  88. And I'll show you what I mean by that as soon as we've added some information in.
  89. now bootstrap which is the css library we're using in the background has already got
  90. some pre-built in css stylings for handling our forms
  91. i'm going to put in a div class to start with and it is going to be of type
  92. form and it's outline
  93. and I'm going to put a margin border of four in place.
  94. Now this here is a pre-set of styling within Bootstrap CSS.
  95. I'm going to give it a input field.
  96. The input field is going to be of type and again we have several of these.
  97. We're going for email this time around.
  98. It will contain some very basic JavaScript to check that an
  99. correctly. I have to name it, which is what allows me to catch it the other end in
  100. PHP. So I'm going to name it sensibly email.
  101. I'm then going to add in an ID for it.
  102. So if I needed to attach it in any way in JavaScript, I can.
  103. And I'm going to say email input.
  104. And then I'm going to give it a class.
  105. So it has a bit of CSS applied to it.
  106. and the class is going to be, if I can just get that right, form
  107. -control.
  108. Now, with that in place, then I can finish that off.
  109. And as an input type, it doesn't need an end tag.
  110. It just has a forward slash to end it.
  111. I'm going to provide a label to it.
  112. And my label is going to be a class of form label.
  113. again pre-set up in bootstrap to be able to stylize it it's going to be
  114. for my email input so that's where it's
  115. linking between these two sections here the id is the for id in this element here
  116. and i'm just going to say that my label is email address
  117. and let's just check that in as a capital element there.
  118. Now, if I save this page and put this page and refresh this
  119. for a second, we'll see that that appears and it's got email address underneath it
  120. in the same way that we have within Parkwood Vale here.
  121. It's got the margin at the top there, it's got that section in place.
  122. It's all ready to go. I'm going to go back.
  123. I'm going to repeat the process.
  124. I'm going to be lazy when I repeat this process.
  125. I'm just going to simply highlight, copy, paste, and then update some elements.
  126. Actually, I copy and pasted way too much though.
  127. We don't need to highlight all of that.
  128. And all that there, all I really need to do is this part right here
  129. and paste that there. So both inputs are within our form
  130. section, so they can both be accessed by our form.
  131. they are set up we have an email type here so this type here is actually going to be
  132. a password which will automatically hide it from users when you type in it if i just
  133. jump back here i can show you email doesn't hide the information i'll show you
  134. password as soon as we finish this action here so name is going to be password id is
  135. going to be password input
  136. and the for is going to be password input
  137. and the label is just simply going to be password.
  138. Save that and if I put that and refresh, you now get email and password.
  139. And as I said, type anything you can see it.
  140. I can type anything I can't see it, but the little I symbol appears that allows me
  141. to see what I've typed. So I've got so far these elements in place here.
  142. My next step is simply my button to end it, my button to submit what I have done.
  143. So in my form here then I'm going to put in another input and at this point we're
  144. going to do a simple input where its type is going to be submit.
  145. Now within there then I can still add some classes to this so the class for my
  146. submit is going to be a button so btn it's going to be a primary button so i'm going
  147. to put it in primary and
  148. it's going to be a btn block to show it in nice block
  149. elements within it i can put in a margin at the bottom of it by four as well
  150. and that if i finish
  151. that off there like that
  152. should, when I put it,
  153. give me my submit button.
  154. And there it is. It just simply says submit.
  155. I know on here it says sign in.
  156. We'll adjust that later on, but here we've got a basic setup.
  157. If I click on submit now, what it will do is try to post whatever's in here to my
  158. sign in page, which comes up and says, I can't find that page because I haven't
  159. created it yet. That's what
  160. I forgotten password, not a member register options down the bottom here.
  161. These will come out of our form.
  162. There is no need for these to be within our form, so I'm going to take them outside
  163. of there. I'm going to put in, again, another div here.
  164. So I'm going to go outside of this div entire.
  165. No, I'm not. I'm going to stay in this div here.
  166. And all I'm going to do is give it its own
  167. class equals row.
  168. Close that off for that in place.
  169. Now with that in place there I'm going to do another div.
  170. I say class equals and to start with I want it to have
  171. text center because I want it in the center of my screen.
  172. I got those two elements in place there then.
  173. href which will take them to the forgotten password page so it's going to be
  174. for got
  175. password and the element for it is going to say forgot
  176. password question mark nice and simple underneath
  177. that then I'm going to put in a new element again it's going to be another a href
  178. and this time around it's going to be sent to register so I'll do for start
  179. register close that off and put in register
  180. so that will put in place my ability to link to different pages
  181. so I put that up refresh it and we can see how it looks now they're on the same
  182. line here and if I go back to Parkwood Vale they're not on the same line and I've
  183. actually got a bit of a message for my register option.
  184. To do that, what I've done is simply put this element in a paragraph tag, and I want
  185. that paragraph to be at the end of this.
  186. And here I've said, not a member, question
  187. mark, and then I have my register.
  188. If I post that and refresh my page, it comes up looking like that, which
  189. pretty much looks like that. Again, a little bit different styling
  190. my container width on this and I have used a different font but the styling
  191. is there the text is there and if I click onto any of these they all crash because I
  192. haven't created those pages yet
  193. so that's created my form if I go back to here a second and go forgot password it's
  194. very simple very similar to what I've got so I'm going to use the old-fashioned save
  195. as trick and to save as this is going to be saving as for my register forgot
  196. password sorry forgot password dot php
  197. make sure that it's on all documents save it there we go and then if i refresh here
  198. let's cancel that a second i'm on local view forgot password dot php it is there
  199. it's not showing on my side here for some reason yes refresh that there we go and
  200. now it has forgot password has appeared.
  201. It wants to put these up. It wants to get those down.
  202. I'm going to say okay to those elements there.
  203. So that's all in place. So this is my forgot password.
  204. My forgot password, my form for it down here, I'm going to say
  205. forgot password form capital P.
  206. Just grab that there. Put it there so I know what I'm doing.
  207. this time around though i don't need the password box so i simply delete that
  208. and i don't want to send it to sign in i want to send it to password reset
  209. so that's there in place the form isn't going to be sign in it's going to be forgot
  210. password
  211. but email input still the same email name is still the same submit buttons still the
  212. same
  213. on Parkwood Vale, I deleted those elements at the bottom there, but I can leave
  214. them there. It won't make much difference.
  215. If I save that and just put that for a second.
  216. Now on here, if I click on forgot password, it takes me to the forgot password
  217. element. I got the register button, which still crashes.
  218. What did we have on register? Let's go back and find out.
  219. We have our first name, last name, email, password, and repeating our password and
  220. terms and conditions
  221. we're gonna do the same process again I'm gonna close this one I'm gonna close index
  222. I don't need that anymore I'm gonna use my account because it's already got a
  223. password element in place for me and all I'm going to do is save as register
  224. now that automatically picked up the PHP because I forgot to put that in place which
  225. is quite lucky so that's got all of these elements in place I do want to have my
  226. form in place with let's see it's not a list register now and
  227. register get rid of those let's change that to register
  228. user can't use register because we've already got that set up here it's not a sign
  229. -in form anymore it's a register form and that's set up there email inputs write
  230. emails their passwords write passwords there we do need our password twice So I'm
  231. going to copy that there. I'm going to paste it there.
  232. Call it password repeat.
  233. And the name is going to be password repeat as well.
  234. And the input is for password repeat input.
  235. The label is for password repeat input.
  236. Password repeat just simply there.
  237. So the user knows they have to repeat their password.
  238. Should be common practice for people these days.
  239. They're well versed in entering passwords.
  240. just done very quickly is copied the email address element and I'm going to change
  241. this up so the type is no longer email it is going to be type of text and again same
  242. here type of text the name is going to be for name and the
  243. link here would be surname and the ID would be for name input surname
  244. input and as you can see all I'm really doing is going through and adjusting these
  245. elements so that they match all the way through.
  246. So that if I need to use them, if I need to reference them in any way, I can do and
  247. I've got them all in place. Email address here is going to change and I'm going to
  248. put in first name. Now you might think why if I change from forename to first name?
  249. I don't like to put first underscore name.
  250. I don't want to camel case it.
  251. Forename is a nice easy way of encapsulating first name.
  252. And do the same here with last name and the same logic.
  253. Rather than have in surname written in the box there it's nice to see last name but
  254. that encapsulates it quite nicely that's my register page and if i go to my register
  255. page and put that what i should be able to do now is go into here and refresh my
  256. register and i've got those elements in place the only element i haven't got is that
  257. tick box that allows me to say whether they've accepted terms and conditions or not.
  258. So it was nice to have as a final little feature.
  259. So I'm going to put that in place.
  260. So I will stay inside my form for this and it will be above my div here.
  261. What I'm going to do is put in a simple div tag and it is again going to be the same
  262. sort of classes as the rest of these.
  263. So actually I'm going to cheat and copy and paste that.
  264. and there they are now the input type here is going to be a type of
  265. checkbox
  266. and i do need to slightly remove that because the type isn't a password repeat
  267. the type is password the input there is checkbox and i'm going to put in place the
  268. value for this
  269. to start with being nothing.
  270. Now to start it I want it to be checked already so I'm going to use the option that
  271. says checked which means that it has been checked.
  272. Sometimes people like to put in checked like that just so that it's there.
  273. It doesn't really benefit of anything so I don't bother.
  274. I simply put it in as checked there.
  275. Now I need to change these names these different bits
  276. going to be instead of repeat password it's going to be terms
  277. and the ID is going to be terms
  278. and as I go through here it's going to be for terms
  279. so they're all in place there now my text isn't going to work in the same
  280. sort of way here for my label what I'm gonna have is in place the
  281. text I have read
  282. and agreed to the terms. There we go.
  283. And when I save that and put that up and refresh it,
  284. we get this big long input box.
  285. Not quite what we want in place.
  286. We need to change up the CSS for this from our form control to make sure it's how we
  287. want it to look. We want it to be a form type of check this time around because
  288. that's what it is and it is going to be a check input.
  289. Now again I'm going to do a margin of two elements here to put that in place.
  290. I'm going to save it, put it and let's refresh it and there we go.
  291. Now the only real difference is it's in the centre of the screen here and it's got
  292. the terms and conditions linked within
  293. Parkwood Vale's actual site. So on my form class here, I'm going to
  294. set this up to have a type of flex to it, a deflex.
  295. And from there, I'm going to justify the content to the center.
  296. And that should allow it, if I put that,
  297. to be centered on my screen.
  298. The main difference being, I haven't got the terms and conditions element here.
  299. That would be an ahref here.
  300. Ahref equals
  301. and then where it is you want to put it.
  302. So, end that a tag and it was simply hrefed to the terms page.
  303. So, terms. Save that.
  304. I didn't put it. Let's put it.
  305. Refresh it. And there we go.
  306. Our signup system from account.
  307. We can sign in. Forgot password.
  308. We can do this element. Register.
  309. We can do this element. And they all submit to their own pages that haven't been
  310. created yet. In the next video, in part two, you're going to go through the
  311. PHP side of things and see how all of that links together, how we query the database
  312. and how we bring that information back.
  313. But that is setting up our three different forms to do our different elements of
  314. registering, logging in and resetting passwords if need be.
  315. Thank you for watching.