PHP Form setAttribute function allows developers to dynamically set attributes for HTML form elements such as input, select, and textarea. This function takes two parameters, first is element and second is attribute with its value.
Example 1: Adding a "class" attribute to an input element using setAttribute function,
setAttribute("class", "form-control");
?>
Here, the setAttribute is used to add "form-control" class to the input element with id "username".
Example 2: Adding a "disabled" attribute to a select element using setAttribute function,
setAttribute("disabled", true);
?>
Here, setAttribute is used to add "disabled" attribute to the select element with id "cars".
These functions belong to the document object model (DOM) package library.
PHP Form::setAttribute - 29 examples found. These are the top rated real world PHP examples of Form::setAttribute extracted from open source projects. You can rate examples to help us improve the quality of examples.