CodeIgniter Forums
Small issue with form_hidden - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Small issue with form_hidden (/showthread.php?tid=68312)



Small issue with form_hidden - doomie22 - 06-22-2017

Hi,

I am having a small issue with form_hidden.  If I have the following:

PHP Code:
<?php echo form_input(array('id' => '1''name' => 'message_id''class' => 'form-control''value' => $tickettitle->message_id)); ?>
<?php 
echo form_input(array('id' => '2''name' => 'title''class' => 'form-control''value' => $tickettitle->title)); ?>

When the following is processed it works.

PHP Code:
public function process(){
 
       $data = array(
 
           
            
'message_id' => $this->input->post('message_id'),
 
           'user1' => $this->config->item('account_name'),
 
           'user2' => 'pushmb',
 
           'title' => $this->input->post('title'),
 
           'message' => $this->input->post('message'),
 
           'timestamp' => date("Y-m-d h:i:sa"),
 
           'user1read' => '1',
 
           'user2read' => '0',
 
           'original' => '0'
 
           );

 
       if (is_array($data) && count($data)>0){
 
           $this->add_content_support($data'internal_messages');
 
           $this->session->set_flashdata('success_message'$data['title'].' Successfully Added');
 
           redirect('admin/support');  
        
} else {
 
           $this->session->set_flashdata('error_message'$data['title'].' Failed to be Added');
 
           redirect('admin/support');
 
       }
 
   


But I need them hidden, so I change it to the following:

PHP Code:
<?php echo form_hidden(array('id' => '1''name' => 'message_id''class' => 'form-control''value' => $tickettitle->message_id)); ?>
<?php 
echo form_hidden(array('id' => '2''name' => 'title''class' => 'form-control''value' => $tickettitle->title)); ?>

They some up as NULL and error the function.  I have used hidden elsewhere and they are working fine so I have no idea why these are causing issues.  

Doomie


RE: Small issue with form_hidden - Paradinight - 06-22-2017

(06-22-2017, 05:10 PM)doomie22 Wrote: Hi,

I am having a small issue with form_hidden.  If I have the following:

PHP Code:
<?php echo form_input(array('id' => '1''name' => 'message_id''class' => 'form-control''value' => $tickettitle->message_id)); ?>
<?php 
echo form_input(array('id' => '2''name' => 'title''class' => 'form-control''value' => $tickettitle->title)); ?>

When the following is processed it works.

PHP Code:
public function process(){
 
       $data = array(
 
           
            
'message_id' => $this->input->post('message_id'),
 
           'user1' => $this->config->item('account_name'),
 
           'user2' => 'pushmb',
 
           'title' => $this->input->post('title'),
 
           'message' => $this->input->post('message'),
 
           'timestamp' => date("Y-m-d h:i:sa"),
 
           'user1read' => '1',
 
           'user2read' => '0',
 
           'original' => '0'
 
           );

 
       if (is_array($data) && count($data)>0){
 
           $this->add_content_support($data'internal_messages');
 
           $this->session->set_flashdata('success_message'$data['title'].' Successfully Added');
 
           redirect('admin/support');  
        
} else {
 
           $this->session->set_flashdata('error_message'$data['title'].' Failed to be Added');
 
           redirect('admin/support');
 
       }
 
   


But I need them hidden, so I change it to the following:

PHP Code:
<?php echo form_hidden(array('id' => '1''name' => 'message_id''class' => 'form-control''value' => $tickettitle->message_id)); ?>
<?php 
echo form_hidden(array('id' => '2''name' => 'title''class' => 'form-control''value' => $tickettitle->title)); ?>

They some up as NULL and error the function.  I have used hidden elsewhere and they are working fine so I have no idea why these are causing issues.  

Doomie
You use it wrong
https://www.codeigniter.com/user_guide/helpers/form_helper.html#form_hidden


RE: Small issue with form_hidden - Martin7483 - 06-23-2017

If you want the same argument structure for a hidden input as with form_input you can make form_input hidden by adding 'type'=>'hidden' to the data array


RE: Small issue with form_hidden - Paradinight - 06-23-2017

@doomie22 Why down vote?

The link show how to use the form_hidden and show an exampla with form_input

PHP Code:
$data = array(
        
'name'  => 'John Doe',
        
'email' => '[email protected]',
        
'url'   => 'http://example.com'
);

echo 
form_hidden('my_array'$data);

/*
        Would produce:

        <input type="hidden" name="my_array[name]" value="John Doe" />
        <input type="hidden" name="my_array[email]" value="[email protected]" />
        <input type="hidden" name="my_array[url]" value="http://example.com" />
*/ 

PHP Code:
$data = array(
        
'type'  => 'hidden',
        
'name'  => 'email',
        
'id'    => 'hiddenemail',
        
'value' => '[email protected]',
        
'class' => 'hiddenemail'
);

echo 
form_input($data);