我有一个可以正常工作的表单,但是当我提交表单时,这些字段仅在我刷新浏览器后才会更新。如何在不刷新浏览器的情况下自动保留字段值。
这是我的代码:
控制器
<?php
function input($account_id = '', $platform = '')
{
if ($account_id > '') {
$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
if (isset($query))
if ($query->num_rows() > '') {
$row = $query->row_array();
}
//declare variables
$data['name'] = '';
$data['account_id'] = '';
$data['platform'] = '';
$data['status'] = '';
$data['location_city'] = '';
$data['location_country'] = '';
$data['region'] = '';
$data['type'] = '';
//pass field data
$data['fname']['value'] = $row['name'];
$data['faccount_id']['value'] = $row['account_id'];
$data['fplatform']['value'] = $row['platform'];
$data['fstatus']['value'] = $row['status'];
$data['flocation_city']['value'] = $row['location_city'];
$data['flocation_country']['value'] = $row['location_country'];
$data['fregion']['value'] = $row['region'];
$data['ftype']['value'] = $row['type'];
}
if (isset($account_id)) {
if ($this->input->post('submit')) {
if ($this->input->post('account_id')) {
$this->dashboard_model->entry_update();
$data['message'] = '- update complete...';
} else {
$data['message'] = 'There was an error, update not complete.';
}
}
//echo $name;
$data['account'] = $this->dashboard_model->get_account($account_id, $platform);
$this->load->view('manage/input', $data);
}
}
?>
看法
<?php
$hidden = array(
'account_id' => $faccount_id['value'],
'platform' => $fplatform['value']
);
//form for Edit
echo '<form method="post" accept-charset="utf-8">';
echo form_hidden($hidden);
?>
<a href="/platform/<?php echo $fplatform['value'] . '/account/' . $faccount_id['value']; ?>">Return to Account</a>
<?php
//Platform
echo '<br><br><span font-weight:bold"><font color="#C40909">' . $fplatform['value'] . '</font>';
if (isset($message)) {
echo '<font color=#C40909> ' . $message . '</font></span>';
};
//Header Name
echo '<h1 class="header"><span class="title">' . $fname['value'] . '</span></h1><br>';
//Form Name
echo '<b> Name</b>' . form_input('name', set_value('name', $fname['value']));
//Form Platform
echo '<b> Platform</b>' . form_input('platform', $fplatform['value']);
//Form Dropdown Status
$status_options = $this->lang->line('status');
echo form_label('<b> Status</b>', 'status');
echo form_dropdown('status', $status_options, $fstatus, 'style=width:313px');
//Form Location City
echo '<b> Location: City</b>' . form_input('location_city', set_value('location_city', $flocation_city['value']));
//Form Location Country
echo '<b> Location: Country</b>' . form_input('location_country', set_value('location_country', $flocation_country['value']));
//Form Region
$region_options = $this->lang->line('region');
echo form_label('<b> Region</b>', 'region');
echo form_dropdown('region', $region_options, $fregion, 'style=width:313px');
$data = array('name' => 'submit', 'value' => 'Update Account', 'style' => 'width:313px');
echo form_submit($data);
echo form_close();
?>