PHP beginners tutorial 47 - radio buttons

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey YouTube how's it going it's Quinton here and this is tutorial number 47 and in this tutorial I'm still talking about how to retrieve data from certain form elements okay and in this video we're actually going to cover radio buttons cuz I haven't done that yet and radio buttons actually work very similarly to um or in a very similar way to check boxes okay so um um this this tutorial is almost like an exact copy or exact repeat of what we did with checkboxes except only one radio button can be selected so it is as I said a bit of a safer option when you're asking for the user for a yes no question okay now if you take a look at my code over here this is all the same code that we had in the previous tutorial all I did was clear out the form and on this page um all I've done is I've cleared out my PHP tags and any code inside of my PHP tags but other than that the rest of this code has been used for the past um two or three maybe even four tutorials okay so let's go ahead and uh throw some radio buttons into our form and I'm just going to ask the user question like a yes no question uh so let's say do you play League of Legends and then we'll give them the option of ticking yes or no so I'm just going to add in a Break Tag over here and then we'll put in the input option of yes input type equals radio cuz we're working with radio buttons and then we'll say value is equal to yes and then well we have to type the word yes before this radio button as well so yes um okay value yes and then name is equal to and we'll just say uh plays okay that's actually going to be a really long name let's just call it League okay and if they say no then we'll go ahead and send through the value of no so input basically everything's going to be the same here contrl ctrl+ V except the value we're going to set equal to no okay now just make sure that you guys leave the name exactly the same for both of them because if the user ever wanted to send through these values they could only send through a value of yes or no because radio buttons can only have one selected at a time and if you guys don't know what I mean let's go ahead and take a look at that so uh go over to this tutorials page which was Local Host tutorials tutorial and it's actually tutorial 47 okay so do you play League of Legends yes or no and as you can see as soon as I click uh yes then no get gets unselected and if I click no then yes gets unselected so only one radio button can be selected at a time so we never have to worry about the user sending through um multiple values for this uh form unless they like physically try to alter their data themselves or something which means they're trying to hack into your website or something okay so let's go ahead now and actually handle those um these values to find out which uh option that the user sent through okay so I'm going to go ahead and just place my PHP tags over here and then we'll Echo um you were asked if you played League of Legends and you said okay so whatever the user said and I'm going to end that off here and let's go ahead and actually um grab the answer to whatever they said okay and the way we're going to do that is obviously uh we could create a new variable or we could actually just um we could just Echo out straight away well I'm going to create a variable and I'm going to call that playscore league and we'll set that equal to uh dollar uncore post square brackets and then we'll just type in here the name of our input element which is league and we can Echo out uh league so actually if I take that line and I place it underneath here then at least I can actually use the variable over here so plays league and then we'll just append on our variable plays league playscore league okay so now that I have got that I can save this and let's go over here and ah I didn't put in a submit button I accidentally cleared that so let's go back here I've just got a put in a submit button so um we'll put in a Break Tag over there and submit so input type equals submit and then we'll give it a value of submit Okay cool so now we should have everything working uh let's go over here click refresh okay so do you play League of Legends yes or no I'm going to click yes submit handling your data okay if you you were asked if you played League of Legends and you said yes so we've sent through the value um which was whatever we typed in over here that's what got printed out um when we actually create a variable of what the user said and I'm making everything disappear Okay cool so uh yes or no and let's actually go back here again and let's just click no just for long click submit and now we've sent through no okay so that's pretty much how you guys can handle radio buttons and that is all I have for you guys in this video so obviously don't forget to subscribe please feel free to leave a comment like or share this video it's really going to help my channel grow and I will see you guys next time
Info
Channel: Quentin Watt Tutorials
Views: 30,093
Rating: undefined out of 5
Keywords: PHP (Programming Language), Radio Button, Tutorial (Industry), HTML, HTML5, CSS, CSS3, Hyper Text Mark up Language, IT, Information Technology, Science, Computer Science, Websites, Web Design, Web Development, Web Programming, Programming, How to, CS, Make a website, Tutorial, scripting, server side script, ProgrammersCreed, Programmers, Creed, Quentin, Watt, Hypertext Preprocessor
Id: AElaNEkw_ok
Channel Id: undefined
Length: 7min 25sec (445 seconds)
Published: Wed Apr 30 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.