How does the controller know it went to it without me passing the parameter in `echo open_form()`?

Asked

Viewed 37 times

0

I have a code here that I’m studying as he does. See this view

insira o código aqui<div class="animate form login_form">
  <section class="login_content">

 <?php echo form_open('', 'id="form" name="form"'); ?>

 <h1>Login Administrativo</h1>
<div> <?php echo form_input(array('name' => 'usuario_usuario', 'type' => 'text', 'class' => 'form-control', 'id' => 'usuario_usuario',     'placeholder' => 'Digite um Usuário')); ?> </div>
<div> <?php echo form_input(array('name' => 'usuario_senha', 'type' => 'password', 'class' => 'form-control', 'id' => 'usuario_senha',   'placeholder' => 'Digite uma Senha')); ?> </div> 
<button type="submit" class="btn btn-default submit">Entrar </button>

<div class="clearfix"></div>

<div class="separator">
  <p class="change_link">Você quer criar uma conta?
 <?php echo anchor(base_url('admin#signup'), 'clique aqui!',    array('class' => 'to_register')); ?>
   </p>

  <div class="clearfix"></div><br />

  <div>
  <h4><i class=""></i> Luziânia Setor Leste GO</h4>
  <p>Igreja de Deus no Brasil em Luziânia</p>
  </div>

   </div>

 <?php echo form_close(); ?>

  </section>
  </div>

this view sends to the controller Login more I’m not understanding how it sends this form to the controller

1 answer

1

When you do not put the address for processing the page on the server, the code takes charge and puts the address of the page in the code section below, it is quite clear that:

// If no action is provided then set to the current url
if ( ! $action)
{
    $action = $CI->config->site_url($CI->uri->uri_string());
}
// If an action is not a full URL then turn it into one
elseif (strpos($action, '://') === FALSE)
{
    $action = $CI->config->site_url($action);
}

Complete code:

function form_open($action = '', $attributes = array(), $hidden = array())
{
    $CI =& get_instance();

    // If no action is provided then set to the current url
    if ( ! $action)
    {
        $action = $CI->config->site_url($CI->uri->uri_string());
    }
    // If an action is not a full URL then turn it into one
    elseif (strpos($action, '://') === FALSE)
    {
        $action = $CI->config->site_url($action);
    }

    $attributes = _attributes_to_string($attributes);

    if (stripos($attributes, 'method=') === FALSE)
    {
        $attributes .= ' method="post"';
    }

    if (stripos($attributes, 'accept-charset=') === FALSE)
    {
        $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"';
    }

    $form = '<form action="'.$action.'"'.$attributes.">\n";

    // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
    if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"'))
    {
        $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
    }

    if (is_array($hidden))
    {
        foreach ($hidden as $name => $value)
        {
            $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value).'" style="display:none;" />'."\n";
        }
    }

    return $form;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.