• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small issue with form_hidden

#1
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
Reply

#2
(06-22-2017, 06: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/h...orm_hidden
Reply

#3
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
Reply

#4
@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); 
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.