Placeholder Image

字幕表 動画を再生する

  • So today I'm going to show you how to send the data to a pH.

  • Be script using an HTML form.

  • So we're gonna do is we're going to create an HTML form where going to point it at the pH be script.

  • And what PHP script is going to do is is going to take all the values from that HTML form.

  • It is going to set those values two variables that we can use in PHP and that is going to send simply print out those values on the screen now is important to understand that as soon as you turn anything into a variable within PHP, you can do almost anything you want with it.

  • So today we're gonna be printing it out to a screen.

  • But it is just a Z Z.

  • To put that information to a file or submitted into a database or do something like that, we're just simply printing out on the screen a day to keep the script simple so that you understand what is going on Now.

  • It is important, understand, whenever you're going, be creating a full fledged web app that you don't use one specific language to create the app.

  • So it's very easy to think that you're gonna be creating Web APS that you will just be using PHP or you'll just be using Ruby or you'll just be using JavaScript.

  • But the reality is, when you create a full fledged Web app, you'll be using PHP and HTML, most likely CSS.

  • There's a good chance will be a my sequel database that uses a sequel in order to interact with it.

  • You may also be using Java script, and so the thing is, is you're going to be using multiple programming languages, and all of these languages are going to be communicating with each other, and it's simply simply essentially passing data off to each other in order to make that full fledged Web.

  • Now, this is why I could be a little confusing for new people when you hear about HTML programming because a lot of people lose their minds when they hear old timers like me to talk about HTML programming.

  • Because HTML is a mark up language, it's not a programming language.

  • Well, the thing is again in the practical world, it gets a little more fuzzy around the edges because you create forms.

  • So the forms that you will use to submit data to PHP that is going to be an HTML ce form.

  • Ah, when you use PHP to write out a report from data that a graft from a database or a file or something like that is going to be writing into HTML.

  • And so this is where you'll hear somebody people talking about programming and CSS or a key amount, which is technically incorrect.

  • Truly, truly, technically, a correct.

  • But in the real world, when you're using four different languages and again you're sending data and information between all those different languages, it's very easy just to simply say, you know, your programming in HTML, even if that's not technically the case.

  • So the demonstration that I'm going to do is going to be a very simple demonstration.

  • Basically, the idea is somebody is going to be signing up for to take, like, a shift at an event.

  • So let's say you're having a volunteer event, so you need to know the person's name.

  • You know, the person's T shirt size, and you need to know what shift that they're willing to take the basic idea there, so we're gonna have a name form.

  • We're going to have a T shirt size of drop down box so you can see how that works.

  • And we're also gonna have to check boxes for a second or first shift again.

  • The idea being somebody comes, they put in their name and putting their T shirt size.

  • And then they say, which shifts they're available for Basically a simple, practical idea.

  • Ah, with that, all we're going to do at this point is we're going to simply print that out the browser screen because we're gonna take all that information, we're gonna turn into the variables, and then all we're going to do is simply do the print function.

  • So do remember, with this everything that we do today, you could take these variables and write it to a file.

  • You could write it to a database, something like that.

  • Just four ease of explaining how this works were simply just writing this out to the Web browser so that let's go over to the computer s so I can show you how this works.

  • Now, I don't normally show you the finished product.

  • In the beginning, I rather show you the code, but there's a little bit of code that goes into this s So I think if I show you the finished product first when we go through and take a look at the code, the code will make a little bit more sense.

  • So, as always, we're going to go to Silica Dojo and the form that we're going to be going to.

  • So it's important.

  • Understand, there's two files in this particular script.

  • There's the form, not PHP.

  • So form dot PHP is the actual HTML form that we're going to be inputting data into.

  • It will then send the data to form script dot PHP.

  • That form script will process the data and actually put this stuff on the screen.

  • Let's go to form dot PHP And here we can see a very, very ugly basically, for right.

  • You know, we have your name.

  • You know, whatever your name is.

  • We have your T shirt size, so they're small, medium large, and then we have whatever shift that you want to take.

  • You want take first or second shift, so if we go here, we could say Let's say your name is Mark.

  • Let's say your medium and let's say you can take the second shift.

  • So when we hit submit then what we're going to see is we're going to say the name is Mark the T shirt sizes medium the shift available is second shift, right?

  • So that's all we're doing again.

  • This could be printed out Thio to a text file to a C S V.

  • File.

  • Something like that.

  • We go here again, we could say Sue just to show its all time Anamika we could say small and we just say first shift and then he hit, Submit And then this is what it looks like.

  • It is important, understand again and being very simple with this Ah oh, this particular script.

  • So there is things like formatting he may have to think about.

  • So, like if I select both first and second shift and hit submit, you'll see this here looks a little bit ugly, but again, this this is the difference between having code that functions versus code that looks good again.

  • Right now we're just gonna try to keep it simple for you.

  • So with that, let's go over and let's take a look at the form itself.

  • So I've called this form dot PHP.

  • Technically, you could make it html or ht up.

  • I just figure if you're gonna be using PHP scripts, just keep everything is PHP makes a little bit easier to understand s Oh, this is just simply called form dot PHP.

  • And this is the entire form for you.

  • So the first thing that we're going to do is we're gonna open up with the form tag.

  • So you open with a form tag and you close to the form tag that says it's a form, then the next thing we're going to do is say, what?

  • What is the action?

  • So Okay, we're taking this down about what are we doing with this data?

  • And what we do is we want to set the action to equal double quotation, and then all we do here is we put what script we're going to be sending us data to, so we're going to be sending us data to the form script dot PHP course close with double quotation marks.

  • They were going to use a method so method at this point, just used post.

  • There are other methods, but making life easier for you.

  • We just simply said it's equal.

  • Double quotation post.

  • And so for this just kind of leave this as it ISS.

  • So this right here the name of the script you're sending it to You can change that for right now.

  • Just leave this as it is, then we just We simply closed that.

  • So that's the opening of the form tag.

  • Then from there, we just actually just right out the foreman html.

  • So the first thing we're gonna say is your name.

  • So again, remember, you can put in html format in here so you could make this 8th 1 You could make the strong and could make this a talic.

  • You could make this blue green Whatever else again.

  • I'm just putting a very simple, simple thing here.

  • So what we're going to say is your name, so no, no additional formatting.

  • We're just simply going to say your name and then we're going to put a text input box.

  • So this is a four input box.

  • That's just a text.

  • So when we go here, this is going to create this particular box that we're looking at.

  • And so we say input.

  • Then we do type equals.

  • And so it's a text box.

  • So it's just simply double quotation marks and then text.

  • So that tells a female that's a text box, and then we're going to give it a name.

  • So the name is how we're going to reference this variable when this gets sent over to the PHP script.

  • And so all we're going to do here is going to name equals name, So this could be anything, so this could be t shirt size.

  • This could be a dress.

  • This could be e mail address.

  • This could be it could be named anything.

  • Basically, the port of thing to understand is this is what we're gonna be referencing.

  • Ah, when we actually try to pull the information, pull the value in order to turn this into a variable.

  • Then we double quotation marks.

  • Do the the forward slash and order clothes, the input and the finish with the thing.

  • So basically, this right here, this gives us a text box, and it creates the name of the text box as name.

  • Okay, we're gonna put a break in.

  • This is simply going to brake line.

  • But the next thing on the new line and then what we're going to do here is we're gonna put an option box or selection box.

  • This is where Ugo and you're able to select multiple different options.

  • Here s O that I were going to do is Thio create this the select box as we open with select.

  • Then we have all again we have to give it a name.

  • So we know what to reference when we're trying to grab the value.

  • And so for this we're going to just do sizes, so sizes close that and then here we have all the option values so you can have, you know, 100 option values or two option values.

  • You have any as many option values as you want.

  • Essentially, in order to create an option value, you just write this code and they go was many times you do option value and then equals.

  • And then the important thing here is with value.

  • So value is what is actually going to be set to the PHP script so small as a looks here, small all lower case.

  • This is what the value that is going to be sent to the pH be script will look like.

  • Then what we do is we close and then small uppercase s and an m a a l l.

  • That is what people will be able to see in the selection box here.

  • That's a very important thing to understand is this is what people will see in the form.

  • This is the actual data that will be sent from the form eso here so you could say small.

  • But then let's say if you have something internal, this may be a U.

  • P C.

  • Code, or this may be some kind of other reference number that you put in there that works with your thing.

  • Ah, Then in order to finish off this option line, we simply close out with option.

  • And so this is how you create ik option.

  • So we do small.

  • We do medium, we do large, and then we close the slick box.

  • Then from that, we do a break, so that could be on the next line.

  • Then what we go down is we're going to do to check boxes so check boxes or either true or false.

  • If they're true the dad, the value will be sent if they're false.

  • The value will not be cept Ah, so this is we do input type.

  • And so this type is a check box they were going to do name so again how we're actually going to reference the value that's being sent.

  • And so what we're going to just do here is we're just simply going to say shift one, right?

  • Ah, Then the value for shift one, we're going to say as first shift.

  • So getting this is this this first shift right here, This is actually going to be set as the value on Then we print out for shift, then we do a break.

  • Then we do input type check box again.

  • For this, we will do shift to the value second shift, and then we're just simply going to do second shift.

  • And so if we take a look here, that's where you see these check boxes.

  • So for shift in the second ship that if we go back, we're just simply going to a break, and then we're going to do the submit button, so input again and put type.

  • And for this we simply make it equal submit.

  • So this is what actually creates that little submit button down there actually allows this thing to function, and then we're going to close that out and then we close the four.

  • So that's how we create this particular for.

  • Then we hit.

  • Submit again.

  • All of his data is said to the form script dot PHP.

  • So let's go take a look at that.

  • So if we open up for script, PHP actually form script out.

  • PHP is easy.

  • Is easier to read, is easier to look at them the the form itself.

  • So with this, all we're going to be doing is we're going to be taking the values that are being sent through post.

  • We're going to be taking those values and will be setting variables to the values that have been given to us.

  • So what we're gonna do is we're going to create a value.

  • A variable for name, a variable for size is a parable for shift one and a variable for shift, too.

  • We're going to make them equal to, and this is where we do dollar side, underscore post all of her case bracket and then wrote a single quotation mark.

  • And then what we're going to be doing is we're going be using the names, right?

  • So if we go back, we look at form, See how we had name is name.

  • Name is sizes.

  • Name is shift One name is shift too.

  • So that's how we'll be accessing the value of those variables.

  • And so what we're going to do is from dollar sign underscore post bracket.

  • We're going to take name and we're going to set the value of the name that's being posted to this script, and we're going to make that the value of dollar sign name the same for size is the same for shift one.

  • The same for shift, too.

  • So that's all you have to do there, then passed that We're just doing the same crappy old print that we've been doing 1000 times already, right?

  • So I'm gonna say print, they're going to double quotation marks and the just name name Colon.

  • So that's something specific.

  • And then the value for the variable name course semi colon.

  • They were going to print a break like we normally dio they were going to print T shirt size and then the value of the variable sizes print to break.

  • And then we're just gonna put this on one line.

  • There's no additional breaks.

  • We're going to print shifts, available colon, and then what we'll do is we'll print the value of Shift one and they will print the value of Shift two.

  • And basically all that data comes from a form gets processed by the script, and that's where you get the output here.

  • So Gadd, Fred for shift.

  • So name is Fred T.

  • Shirt size is large, and he's willing to take the first shift if t shirt size.

  • You know, Sue isn't willing to take anything.

  • And there you go.

  • Ah, an important thing to understand.

  • You'll notice this here.

  • You'll notice this auto fill to be clear again.

  • We talk about using a Web application.

  • There's multiple technologies being involved.

  • This has nothing to do with me.

  • To be clear, this is not PHP.

  • This is Nazi SS.

  • This is not html.

  • This, um, this little auto fill feature.

  • This is actually part of crow by itself.

  • So I don't think I coded anything to make this work so you can put it Tom again.

  • But it's small that could take both shifts.

  • They're ago, and that's really all there is to this particular demonstration, using both the HTML form and then using the pH Be script in order to process it.

  • So that's what there is, using an HTML form to be able to send the data to a PHP script.

  • Um, and again, as with most of the stuff with any kind of coating, it's relatively simple.

  • Where the complicated thing comes into play is the difference between what the viewer or the user sees versus what data you're actually sending back and forth.

  • So again, it's very important.

  • Understand, Let's say, with a drop down box where the user sees small, large, extra large whatever else.

  • But you have to ask yourself, Is that really the data you want to send to the script?

  • Let's say to a database or something else.

  • Do you want to send a small medium extra large?

  • Or again?

  • Do you want to send something like a U P.

  • C.

  • Code 011665550 Right, because when I as a user, I'm saying small, medium large.

  • I'm just thinking about the size for you.

  • If you're actually having to order a product by putting the U P C code or the eyes being or whatever kind of code in there that may make it easier so that when somebody selects that, that can then do something such as auto fire, an order from a vendor that you're using.

  • And so this is where you really have to start thinking about the difference between what the user is seen and then what you need the code to actually accomplish.

  • And, as always, that is a thing that is much, much more complicated again.

  • To this is where you start seeing how user interface design is very important.

  • I showed you a very ugly form with a very ugly report.

  • This is where you start having to ask yourself, What should the sizes of these different fonts be?

  • You know, how should they be separated out?

  • Should to be putting things on the same lines or different lines on, and that's honestly, that's where coding gets complicated.

  • People think that coding is complicated because of the script that I show you.

  • But as you've seen with this BHP Siris, each individual type of script that I'm showing he was actually relatively easy once you do it.

  • 10 times you'll memorize it.

  • No big deal.

  • The language itself is not what's complicated.

  • It's taking that language and then turning it into something that's actually useful and productive and profitable for an organization.

  • That's where that's where things get complicated, eh?

  • So that's really all there is to using an HTML form.

  • This said data to a PHP script.

  • As with all these things, there is much more to learn about it, so you can learn about different types of methods for sending the data.

  • You could look at different the different the types of dad again, whether it's text or select boxes or checks boxes.

  • They're different options.

  • There.

  • You might want to take a look at radio boxes, that type of thing.

  • So there is MME or Toe.

  • Look into with this.

  • But the basic idea is you created HTML form.

  • You set the name of the different fields within that form, and then you simply are able to access the value from the form, using the name using the PHP script.

  • If you understand that, the rest of it is just basically going through with just adding little things here and there so that that's why HTML forms is sending data to PHP scripts is important.

So today I'm going to show you how to send the data to a pH.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

A2 初級

PHP - HTMLフォームでデータをPHPに送信する (PHP - Send Data to PHP with HTML Form)

  • 7 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語