How can I give css styles to this form

0

How can I give css styles to this form? Is there a better way to create forms in codeigniter 3?

<h1>Formulario con Codeigniter 3</h1>

<?php 

echo validation_errors("<p style='background: red; color: #fff'>", "</p>") ?>

<?php echo form_open(base_url("home/save")) ?>

    <p><?php echo form_label("Username", "username") ?></p>
    <p><?php echo form_input($username) ?></p>

    <p><?php echo form_label("Email", "email") ?></p>
    <p><?php echo form_input($email) ?></p>

    <p><?php echo form_label("Password", "password") ?></p>
    <p><?php echo form_input($password) ?></p>

    <p><?php echo form_label("Sexo", "sexo") ?></p>
    <p><?php echo form_dropdown("sexo", $sexo) ?></p>

    <p><?php echo form_submit("submit", "Enviar") ?></p>

<?php echo form_close() ?>
    
asked by Rangel 19.09.2018 в 21:04
source

1 answer

2

Suppose you change style to these two elements:

<p><?php echo form_label("Username", "username") ?></p>
<p><?php echo form_input($username) ?></p>

You create an array with properties that you will configure to your HTML elements:

<?php 
    $attributes = array(
      'class' => 'label-stilo',
      'style' => 'color: #000;');
    $attributes2 = array(
      'class' => 'campo-stilo',
      'style' => 'color: #4c0;');
?>
    <p><?php echo form_label("Username", "username", $attributes) ?></p>
    <p><?php echo form_input($username ,"", $attributes2 ) ?></p>

Above you can change it for the css class that you use plus you can define several arrays for attributes, you can configure other html properties to assign events (For example):

$atributos= array( "onclick"=> "metodoJsCualquiera()");
    
answered by 19.09.2018 в 21:14