Jump to content

Recommended Posts

Hi

i have tried various method to get the value of current date (which is a hidden field), but in my database it just 0000000 i get. the date dont seem to be inserted. i tried declaring date as a variable in my controller file ($date = date('Y-m-d H:i:s', now());) then passed it on to the db but no avail, i also tried declaring it on the view file still no avail. Where am i going wrong? thanks in advance

My code

View

<?php // Change the css classes to suit your needs    

//$attributes = array('class' => '', 'id' => '');
echo form_open('services'); ?>

<p>
        <label for="title">Title <span class="required">*</span></label>
        <?php echo form_error('title'); ?>
        
        <?php // Change the values in this array to populate your dropdown as required ?>
        <?php $options = array(
                                                  ''  => 'Please Select',
                                                  'mr'    => 'Mr',
											  'mrs'    => 'Mrs',
											  'miss'    => 'Miss',
											  'ms'    => 'Ms',
											  'dr'    => 'Dr',
											  'prof'    => 'Prof',
											  'alhaji'    => 'Alhaji'
                                                ); ?>

        <br /><?php echo form_dropdown('title', $options, set_value('title'))?>
</p>                                             
                        
<p>
        <label for="surname">Surname <span class="required">*</span></label>
        <?php echo form_error('surname'); ?>
        <br /><input id="surname" type="text" name="surname" maxlength="25" value="<?php echo set_value('surname'); ?>"  />
</p>

<p>
        <label for="firstname">Firstname <span class="required">*</span></label>
        <?php echo form_error('firstname'); ?>
        <br /><input id="firstname" type="text" name="firstname"  value="<?php echo set_value('firstname'); ?>"  />
</p>

<p>
        <label for="email">Email <span class="required">*</span></label>
        <?php echo form_error('email'); ?>
        <br /><input id="email" type="text" name="email" maxlength="25" value="<?php echo set_value('email'); ?>"  />
</p>

<p>
        <label for="state">State <span class="required">*</span></label>
        <?php echo form_error('state'); ?>
        <br /><input id="state" type="text" name="state" maxlength="25" value="<?php echo set_value('state'); ?>"  />
</p>

<p>
        <label for="tel">Tel <span class="required">*</span></label>
        <?php echo form_error('tel'); ?>
        <br /><input id="tel" type="text" name="tel" maxlength="20" value="<?php echo set_value('tel'); ?>"  />
</p>

<p>
        <label for="topic">Topic <span class="required">*</span></label>
        <?php echo form_error('topic'); ?>
        
        <?php // Change the values in this array to populate your dropdown as required ?>
        <?php $options = array(
                                                  ''  => 'Please Select',
                                                  'paye'    => 'PAYE',
											  'capital'    => 'Capital Reconstruction',
											  'cash'    => 'Cash Flow Forcasting',
											  
                                                ); ?>

        <br /><?php echo form_dropdown('topic', $options, set_value('topic'))?>
</p>                                             
                        
<p>
        <label for="msg">Message <span class="required">*</span></label>
<?php echo form_error('msg'); ?>
<br />

<?php echo form_textarea( array( 'name' => 'msg', 'rows' => '5', 'cols' => '50', 'value' => set_value('msg') ) )?>
</p>
<p>
<?php
$date = date('Y-m-d H:i:s', now()); 
echo form_hidden( 'date', '$date'); 
?>
</p>
<p>
        <?php echo form_submit( 'submit', 'Submit'); ?>
</p>

<?php echo form_close(); ?>

 

controller

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Services extends CI_Controller {
               
public function __construct()
{
		parent::__construct();
	//$this->load->library('form_validation');
	//$this->load->database();
	//$this->load->helper('form');
	//$this->load->helper('url');
	$this->load->model('services_model');

}	

	public function view($page = 'easylife')
{

	if ( ! file_exists('application/views/services/'.$page.'.php'))
{
	// Whoops, we don't have a page for that!
	show_404();
}

$data['title'] = ucfirst($page); // Capitalize the first letter


$this->load->view('templates/header', $data);
$this->load->view('services/'.$page, $data);
$this->load->view('templates/footer', $data);

}

public function index()
{			
	$this->form_validation->set_rules('title', 'title', 'required|trim|xss_clean|max_length[10]');			
	$this->form_validation->set_rules('surname', 'surname', 'required|trim|xss_clean|max_length[25]');			
	$this->form_validation->set_rules('firstname', 'firstname', 'required|trim|xss_clean');			
	$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean|valid_email|max_length[25]');			
	$this->form_validation->set_rules('state', 'state', 'required|trim|xss_clean|max_length[25]');			
	$this->form_validation->set_rules('tel', 'tel', 'required|trim|xss_clean|is_numeric|max_length[20]');			
	$this->form_validation->set_rules('topic', 'topic', 'required|trim|xss_clean|max_length[25]');			
	$this->form_validation->set_rules('msg', 'msg', 'required|trim|xss_clean|max_length[50]');

	$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');

	if ($this->form_validation->run() == FALSE) // validation hasn't been passed
	{
		//$this->load->view('advisory');
		$this->load->view('templates/header');
		$this->load->view('services/advisory');
		$this->load->view('templates/footer');


	}
	else // passed validation proceed to post success logic
	{
	 	// build array for the model

		$form_data = array(
				       	'title' => set_value('title'),
				       	'surname' => set_value('surname'),
				       	'firstname' => set_value('firstname'),
				       	'email' => set_value('email'),
				       	'state' => set_value('state'),
				       	'tel' => set_value('tel'),
				       	'topic' => set_value('topic'),
				       	'msg' => set_value('msg'),
						'date' => set_value('date')
					);

		// run insert model to write data to db

		if ($this->services_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
		{
			redirect('services/success');   // or whatever logic needs to occur
		}
		else
		{
		echo 'An error occurred saving your information. Please try again later';
		// Or whatever error handling is necessary
		}
	}
}
function success()
{
		echo 'this form has been successfully submitted with all validation being passed. All messages or logic here. Please note
		sessions have not been used and would need to be added in to suit your app';
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/259941-hidden-value-insert-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.