What is an input?
Video outline
So far we have seen concepts related to coding that don’t interact directly with the final user of our program. We saw for example how the programmer can create a variable and assign a value to it, however this value cannot be modified by the final user.
Definition
With input, things are different because this is a function that is going to allow the user to enter some information into our program’s database. As a sort of analogy, this would be the equivalent of writing some data inside a cell in a spreadsheet.
Practical example
Imagine that you want to create a form for your website in which the user needs to fill out certain personal information such as Name, address, phone number. Obviously the programmer doesn’t know this information and needs a way to let the user enter this data.
The solution is to create input fields in our code.
{% input custom.user.name %}
On the other end, in this case on the website, the user is going to be able to type the required information for each field. For example the name.
Using inputs
Inputs are useful because now we have gathered certain information that we previously did not know. Now we can use it in our code and include it as part of a sentence as you can see on this example. Since we know the user’s name we can print is as part of the sentence: “Hello, my name is...” and then the username.
Hello, my name is {{ custom.user.name }}
Or another thing that we can also do is to create formulas and perform calculations if the data from the input field is a number. In this case I know that my tax rate is for example 20% but I need the user to tell me how much profit he had during the year in order to work out the total tax to be paid.
The total tax to be paid is: £{{ custom.total.profit*0.20 }}
Conclusion
Input gets information from the user and puts it into a variable of our choosing that we can then use in our code for certain purposes and that it will be stored in our database.
This is a necessary function and an extremely useful one as often only the final user has the information we request.
Updated over 3 years ago