发布数据不是由代码点火器表单发送的

时间:2012-10-10 02:22:49

标签: php codeigniter

我的CI2.0.2应用程序出了点问题。

据我所知,它没有从表单中获取任何帖子数据,因此无法运行更新功能,尽管大多数页面工作正常。

表格如下:

<?php echo form_open('job/update/', array('id' => 'update', 'name' => 'update')); ?>

<div class="images">

    <?php echo img('application/images/updateJob.png');?>

</div>

<h1>Update Job</h1>
<br><br><br><br>


<div class="fieldset">

    <?php
        if (isset($error))
        {
            echo '<div id ="error">';
            echo '<h2>Error:</h2>';
            echo '<p>'.$error.'</p>';
            echo '</div>';
        }
    ?>

    <input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo "0"; }    ?>">
    <div class="left">
        <h4>Job Details:</h4>
        <div>
            <label for="job_number">Job No:</label>
            <input type="text" name="job_number" id="job_number" value="<?php echo $job['jobno']; ?>" disabled="disabled">
        </div>

        <div>
            <label for="date">Date:</label>
            <input type="text" name="date" id="date" value="<?php echo $job['datetime']->format('d-M-Y'); ?>">
        </div>

        <div>
            <label for="council">Council:</label>
            <input type="text" name="council" id="council" value="<?php echo htmlspecialchars($job['council']); ?>"> *
        </div>

        <div>
            <label for="dano">DA No:</label>
            <input type="text" name="dano" id="dano" value="<?php echo htmlspecialchars($job['dano']); ?>">
        </div>

        <div>
            <label for="client">Client:</label>
            <input type="text" name="client" id="client" value="<?php echo $job['clientid']; ?>" disabled="disabled">           
        </div>

    </div>


    <div class="right" style="margin-left: 390px;">
        <h4>Location:</h4>
        <label for="street_no">Street No:</label>
        <input type="text" name="street_no" id="street_no" value="<?php echo $address['streetno']; ?>"> *
        <br>

        <label for="street_name">Street Name:</label>
        <input type="text" name="street_name" id="street_name" value="<?php echo $address['streetname']; ?>"> *
        <br>

        <label for="street_type">Street Type:</label>
        <select name="street_type" id="street_type">
        <?php
            foreach ($street_types as $type)
            {
                echo '<option';
                if ($type == $address['streettype']) echo ' selected="selected"';
                echo '>'.$type.'</option>';
            }
        ?>
        </select> *
        <br>

        <label for="suburb">Suburb:</label>
        <input type="text" name="suburb" id="suburb" value="<?php echo $address['suburb']; ?>"> *
        <br>

        <label for="postcode">Postcode:</label>
        <input type="text" name="postcode" id="postcode" value="<?php echo $address['postcode']; ?>"> *
        <br>

        <label for="state">State:</label>
        <input type="text" name="state" id="state" value="<?php echo $address['state']; ?>"> *
        <br>

        <label for="country">Country:</label>
        <input type="text" name="country" id="country" value="<?php echo $address['country']; ?>">
        <br>

        <label for="dp">DP:</label>
        <input type="text" name="dp" id="dp" value="<?php echo $address['dp']; ?>">
        <br>

        <label for="lot_no">Lot No:</label>
        <input type="text" name="lot_no" id="lot_no" value="<?php echo $address['lotno']; ?>">
        <br>

        <label for="po_box">PO Box:</label>
        <input type="text" name="po_box" id="po_box" value="<?php echo $address['pobox']; ?>">

    </div>


    <div>
        <input type="submit" id="submit" name="submit" value="Submit" class="button">
        <p>* = Required fields</p>
    </div>

</div>

<?php echo form_close();?>

控制器的更新部分如下:

/**
 * Update an existing job.
 * @param   int $job_number     The number of the job to update.
 */
public function update($job_number=0)
{
    $this->load->model('Job_model');
    $job     = array();
    $address = array();

    // Get post data.
    $job['joblocation'] = '';
    $job['jobno']       = $this->input->post('job_number');
    $job['datetime']    = new DateTime($this->input->post('date'));
    $job['dano']        = $this->input->post('dano');
    $job['council']     = $this->input->post('council');
    echo $job['jobno'];
    echo $job['dano'];
    echo $job['council'];
    $address['streetno']    = $this->input->post('street_no');
    $address['streetname']  = $this->input->post('street_name');
    $address['suburb']      = $this->input->post('suburb');
    $address['country']     = $this->input->post('country');
    $address['postcode']    = $this->input->post('postcode');
    $address['state']       = $this->input->post('state');
    $address['dp']          = $this->input->post('dp');
    $address['lotno']       = $this->input->post('lot_no');
    $address['pobox']       = $this->input->post('po_box');
    $address['streettype']  = $this->input->post('street_type');
    echo "here2";
    if (isset($_POST['submit']))
    {
        $this->Job_model->update($job);
        echo "here";
        redirect('job/');
    }

    // Otherwise, get the data from the database.       
    else
    {
        $job = $this->Job_model->search($job_number);
        $job = $job[0];
        $job['datetime'] = new DateTime($job['datetime']);
        $address = $this->Job_model->get_address($job['joblocation']);
        $address = $address[0];
    }


    // Get the street types.
    $street_types = array();
    $this->load->model('staff_model');
    $streets = $this->staff_model->get_street_types();

    foreach ($streets as $street) 
    {
        $street_types[$street['streettype']] = $street['streettype'];
    }


    // Load the client list.
    $clients = array();
    $this->load->model('client_model');
    $people = $this->client_model->get_client_person_list();
    $companies = $this->client_model->get_client_company_list();


    // Allocate view data.
    $viewdata = array();
    $viewdata['job'] = $job;
    $viewdata['street_types'] = $street_types;
    $viewdata['address'] = $address;
    $viewdata['people'] = $people;
    $viewdata['companies'] = $companies;

    $this->layout->view('job/update', $viewdata);
}

为什么会发生这种情况的任何想法?

提前致谢,

詹姆斯

1 个答案:

答案 0 :(得分:0)

尝试更改您在此行中使用的引号:

<input type="hidden" name="c" id='c' value="<?php if(!empty($view[0])) { echo $view[0]; } else { echo '0'; }    ?>" />

你使用双引号围绕0的方式你破坏了那个php,因为第一个将关闭开头值。