from bs4 import BeautifulSoup


def get_forms(content: str):
    """
    This function gets all the forms from a page source html.

    @param content: The page content.
    @type content: str
    @return: List of all the forms.
    @rtype: list
    """
    forms = list()
    for form in BeautifulSoup(content, "html.parser").find_all("form"):
        try:
            # Get the form action (requested URL).
            action = form.attrs.get("action", "").lower()
            # Get the form method (POST, GET, DELETE, etc).
            # If not specified, GET is the default in HTML.
            method = form.attrs.get("method", "get").lower()
            # Get all form inputs.
            inputs = []
            for input_tag in form.find_all("input"):
                input_dict = dict()
                # Get type of input form control.
                input_type = input_tag.attrs.get("type")
                # Get name attribute.
                input_name = input_tag.attrs.get("name")
                # Get the default value of that input tag.
                input_dict["value"] = input_tag.attrs.get("value", "")
                # Add all the attributes to the input dictionary.
                if input_type:
                    input_dict["type"] = input_type
                if input_name:
                    input_dict["name"] = input_name
                
                # Add the input dictionary object to the list of inputs.
                inputs.append(input_dict)
            # Adding the form to the list.
            forms.append({"action": action, "method": method, "inputs": inputs, "form": form})
        except:
            continue
    return forms