简体   繁体   中英

Empty POST result using CodeIgniter form_validation

Can anyone spot why my form always fails the validation? The validation doesn't output any errors, and the POST array is always empty. Suggests to me, its getting submitted to the wrong place but thats not the case.

    <form action="https://www.mydomain.com/account/withdraw" method="post" accept-charset="utf-8">      <fieldset class="six-col">
        <h3>What amount?</h3>
        <span style="font-size:1.3em;position:relative;display:inline;">&pound;</span>
        <input id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/>

    </fieldset>
    <fieldset class="six-col">
        <h3>Charges</h3>
        <span id="charges" style="font-size:1.3em;"></span>
    </fieldset>
    <fieldset class="six-col">
        <h3>You leave with</h3>
        <span id="charges2" style="font-size:1.3em;"></span>
    </fieldset>
    <fieldset class="six-col end-col">
        <input type="submit" id="submit" class="btn" value="Withdraw" style="width:125px;position:absolute;bottom:0" />
    </fieldset>
</form>

Here is the controller

    $this->load->library('form_validation');

    $this->form_validation->set_rules('amount', 'Amount', 'required|xss_clean|trim|numeric|max_length[5]');

    if ($this->form_validation->run() == FALSE)
    {           
        $this->load->helper(array('form', 'url'));
        $data['credit'] = $this->account_m->get_credit();
        $this->load->view('account/withdraw', $data);
    }
    else
    {
        // The withdraw code
    }
    $this->load->view('footer');

Thanks for any help

You don't have name set in the input.. it should be: <input name="amount" id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/>

Make sure you're actually getting something back.

If at all possible to test.. echo the post var before the form_validation like so:

<?php echo $this->input->post('amount'); ?>

If you aren't getting a value back then its the form, try using POST instead of post .

If you are getting a value back then its the rule. One possibility is the numeric rule, try integer. Try is_natural or try decimal if you're using $0.00.

Also, use codeigniter's profiler class for development.. http://codeigniter.com/user_guide/general/profiling.html

<?php $this->output->enable_profiler(TRUE); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM