Forms Flashcards

1
Q

What does the action attribute in a <form> specify?

A

The URL where the form data will be sent after submission.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of the method attribute in a <form>?

A

Specifies how to send the form data (GET for retrieving data, POST for submitting changes).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the role of the id attribute in an <input> element?

A

Provides a unique identifier for the input, often used with <label> for accessibility.</label>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is the name attribute used in an <input></input> element?

A

Specifies the key that will pair with the input value when form data is submitted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the disabled attribute do in an <input></input> element?

A

Prevents the input from being edited or submitted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the value attribute do in an <input> element?

A

Sets the default value of the input field.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does the required attribute work in an <input></input> element?

A

Forces the user to fill out the input before submitting the form.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What do the min and max attributes do in an <input></input> element?

A

Set the numeric or date range allowed for the input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do the minlength and maxlength attributes do in an <input></input> element?

A

Define the minimum and maximum number of characters allowed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the accept attribute in an <input> element do?

A

Specifies the file types allowed when the input type is file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you style valid or invalid input fields using CSS?

A

Use :valid and :invalid pseudo-classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Write an input element that requires a number between 1 and 10.

A

<input type=”number” min=”1” max=”10” required>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you make a text input required with a maximum of 50 characters?

A

<input type=”text” required maxlength=”50”>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you access form data submitted via POST in a Django view?

A

Use request.POST.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you handle file uploads in a Django view?

A

Use request.FILES to access the uploaded file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you catch ValueError when parsing numbers in Django?

A

Use a try-except block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you catch DoesNotExist errors in Django?

A

Use a try-except block and raise Http404 if the object isn’t found.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are some risks of handling file uploads in web applications?

A
  1. Large files may consume server storage or memory.

2.Malicious files may execute harmful code.

  1. Files might overwrite existing files.
  2. Files might masquerade as safe types (e.g., .jpg but actually executable).
  3. Improper permissions may expose uploaded files to unauthorized access.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

When should you use GET for form submission?

A

Use GET for requests that don’t change server state, such as search forms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

When should you use POST for form submission?

A

Use POST for requests that create, update, or delete data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you describe a simple security policy?

A

By specifying which users can perform which actions (e.g., “Only admins can delete users”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Define authentication.

A

The process of verifying a user’s identity (e.g., via a username and password).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Define authorization.

A

The process of determining what actions an authenticated user is allowed to perform.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the purpose of a cookie in web security?

A

A cookie stores data in the user’s browser, often used to maintain session identity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do sessions work with cookies for user logins?

A

After login, the server generates a session ID, stores it in a cookie, and uses it to track the user’s state across requests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do you log in a user in Django?

A

Use authenticate to verify credentials and login to start the session.

user = authenticate(request, username=”user”, password=”pass”)
if user:
login(request, user)

26
Q

How do you log out a user in Django?

A

Use the logout function.

logout(request)

27
Q

How can you check if a user is in a specific group?

A

if not user.groups.filter(name=”GroupName”).exists():
raise PermissionDenied

28
Q

What is an injection vulnerability?

A

A security flaw where untrusted input is used to manipulate or execute unintended commands in queries or scripts.

29
Q

What are the risks of using |safe

A

|safe: Bypasses auto-escaping, risking XSS if used on untrusted data.

30
Q

What are the risks of using .raw()

A

.raw(): Executes raw SQL queries, risking SQL injection.

31
Q

What is CSRF?

A

Cross-Site Request Forgery occurs when an attacker tricks a user into performing actions on a site without their consent.

32
Q

What does {% csrf_token %} output?

A

A hidden input field with a unique token that validates the authenticity of form submissions.

33
Q

What are the risks of using @csrf_exempt in Django?

A

It disables CSRF protection, making the application vulnerable to CSRF attacks.

34
Q

What is an open redirect?

A

A vulnerability where an application redirects users to an external URL without validation, enabling phishing attacks.

35
Q

What should you check to avoid open redirects in your code?

A

Validate redirect URLs using Django’s url_has_allowed_host_and_scheme.

36
Q

What is a CVE?

A

A record in the Common Vulnerabilities and Exposures database that documents known security flaws.

37
Q

What is OWASP?

A

The Open Web Application Security Project, an organization that identifies and educates about common web security vulnerabilities.

38
Q

What is the benefit of using |safe in Django templates?

A

It allows rendering HTML or JavaScript from variables without escaping, enabling trusted content to display as intended (e.g., rendering preformatted HTML snippets or rich text).

39
Q

What is the benefit of using .raw() in Django queries?

A

It enables executing custom SQL queries that cannot be achieved with Django’s ORM, providing flexibility for complex or optimized queries.

40
Q

What does the defer attribute in a <script> tag do?

A

Delays execution of the script until the HTML document is fully parsed.

41
Q

What does type=”module” in a <script> tag enable?

A

Allows the use of ES6 modules for importing/exporting and creates a separate namespace for the script.

42
Q

What is progressive enhancement in web development?

A

A design approach where basic functionality is provided for all users, with additional features added for users with more advanced browsers or capabilities.

43
Q

What are some common pitfalls to avoid in JavaScript?

A
  1. Type mixing (e.g., comparing numbers and strings).
  2. Declaring variables without let, const, or var (accidental globals).
  3. Using var instead of let or const.
    4.Using for/in loops on arrays.
    Improper use of this.
44
Q

How does Array.from() differ from arrays?

A

It converts array-like objects (e.g., NodeLists) to true arrays with array methods.

45
Q

How do you wrap, select, or create elements in jQuery?

A

Use the $() function:

Wrap: $(“<div>content</div>”)
Select: $(“#id”) or $(“.class”)
Create: $(“<tag>").</tag>

46
Q

How do you manipulate elements in jQuery using append?

A

append: Adds content as the last child of the selected element.

47
Q

How do you manipulate elements in jQuery using prepend?

A

prepend: Adds content as the first child.

48
Q

How do you manipulate elements in jQuery using before?

A

before: Inserts content before the selected element.

49
Q

How do you manipulate elements in jQuery using after?

A

after: Inserts content after the selected element.

50
Q

How do you modify an element’s class using jQuery?

A

addClass(“className”)
removeClass(“className”)

51
Q

What does the val() function do in jQuery?

A

Gets or sets the value of input elements.

52
Q

How do you traverse elements in jQuery using children?

A

children(): Selects direct child elements.

53
Q

How do you traverse elements in jQuery using parent?

A

parent(): Selects the parent of the current element.

54
Q

How do you traverse elements in jQuery using find?

A

find(): Selects descendants matching a selector.

55
Q

How do you attach an event handler in jQuery?

A

Use the on method

$(“selector”).on(“event”, function(event) {
// Handle event
});

56
Q

What does the preventDefault() method do?

A

Prevents the default action of the event (e.g., form submission).

57
Q

How can you access the element that triggered an event in jQuery?

A

Use event.target.

58
Q

What is the purpose of the $.ajax method in jQuery?

A

To make asynchronous HTTP requests.

59
Q

What do the method and data options in $.ajax specify?

A
  • method: HTTP method (e.g., GET, POST).
  • data: Data to be sent with the request.
60
Q

How do you handle errors in $.ajax?

A

Use the error callback:

$.ajax(url, {
error: function(xhr, status, error) {
console.error(“Error:”, error);
}
});

61
Q

How do you handle a successful $.ajax response?

A

Use the success callback:

$.ajax(url, {
success: function(data) {
console.log(“Data:”, data);
}
});

62
Q

How can you use $.ajax with await for asynchronous requests?

A

let data = await $.ajax({
method: “GET”,
url: “/api/example”
});
console.log(data);

63
Q

How do you enable more parallelism with await?

A

Move the await call later in the code by creating multiple Promise objects and resolving them later. Example:

let promises = [];
urls.forEach(url => {
promises.push($.ajax({ url }));
});
let results = await Promise.all(promises);