Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:58:38+00:00 2026-06-10T23:58:38+00:00

This is a continue question from here The case is : after i add

  • 0

This is a continue question from here

The case is : after i add a hidden field, now i could Update but i CANT save because everytime i try to save, this error message keep showing up : The User ID field is required.

This is the controller, function add is for Save and update for Update :

function add(){
    //set common properties 
    $data['title'] = 'Tambah User baru';
    $data['action'] = site_url('user/add');
    $data['link_back'] = anchor('user/index/', 'Back to User list', array('class'=>'back'));

    //bedakan add/update
    $data['validate'] = 'add';

    $this->_set_rules();
    //run validation
    if($this->form_validation->run() == false){
        $data['message'] = '';

        $data['title'] = 'Add new User';
        //$data['message'] = '';
        $data['user']['ID_user'] = '';
        $data['user']['pass'] = '';
        $data['user']['nama'] = '';
        $data['user']['email'] = '';
        $data['user']['active'] = '';
        $data['link_back'] = anchor('user/index/', 'Lihat daftar User', array('class'=>'back'));

        $this->load->view('user_form_v', $data);
    }

    else{
        //save data
        $user = array('ID_user'=>$this->input->post('ID_user'),
        'pass'=>sha1($this->input->post('pass')),
        'nama'=>$this->input->post('nama'),
        'email'=>$this->input->post('email'),
        'active'=>$this->input->post('active'),
        'regis_date'=>date('Y-m-d H:i:s'));

        $ID_user = $this->user_m->save($user);

        //set form input nama = "id"
        $this->validation->ID_user = $ID_user;

        redirect('user/index/add_success');
    }
}

function update($ID_user){
    //set common properties
    $data['title'] = 'Update user';
    $this->load->library('form_validation');

    //set validation properties
    $this->_set_rules();
    $data['action'] = ('user/update/'.$ID_user);

    //bedakan add/update
    $data['validate'] = 'update';

    //run validation
    if ($this->form_validation->run() == false){
        $data['message'] = '';

        $data['user'] = $this->user_m->get_by_id($ID_user)->row_array();
        //set common properties
        $data['title'] = 'Update User';
        $data['message'] = '';
    }
    else{
        //save data
        $ID_user = $this->input->post('ID_user');
        $user = array(
        'pass'=>$this->input->post('pass'),
        'nama'=>$this->input->post('nama'),
        'email'=>$this->input->post('email'),
        'active'=>$this->input->post('active'),
        'regis_date'=>date('Y-m-d H:i:s'));

        $this->user_m->update($ID_user, $user);
        $data['user'] = $this->user_m->get_by_id($ID_user)->row_array();

        //set user message
        $data['message'] = 'Update User Success!';
    }

    $data['link_back'] = anchor('user/index/', 'Lihat daftar user', array('class'=>'back'));
    //load view
    $this->load->view('user_form_v', $data);
}

And this is my view :

<input type="text" name="ID_user" class="text"
                <?php if($validate!='add'){echo "disabled";} ?>
                value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>
                <input type="hidden" name="ID_user" value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>

note : if the name for input text and input hidden is SAME then the update is working but the save is not working, but if the name is different then the update is not working but the save is working @_@

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:58:39+00:00Added an answer on June 10, 2026 at 11:58 pm

    Just put the hidden input element above the disabled element.

    <input type="hidden" name="ID_user" value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>
    <input type="text" name="ID_user" class="text"
                    <?php if($validate!='add'){echo "disabled";} ?>
                    value="<?php echo (isset($user['ID_user']))?$user['ID_user']:""?>"/>
    

    The issue appears because the value is overwritten by the hidden input element (which is empty in your “save” page). By moving placing the hidden one before the may or may not be disabled one, both of the “save” and “update” page will work correctly. In the update page, it’ll work because if the input is disabled, it will not get sent to the server (i.e. it will not overwrite the hidden one).

    However, in my opinion, using a hidden input is not very secure. Users can easily change the value by editing the HTML using tools like Firebug or Chrome developer tools. You might want to look into session as a solution instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow up from this question, Lock Cells after Data Entry .
Not sure it is clear from this question title what I mean, so here
This continues from a previous question . I tried the suggested fix to check
this is my first question in here, and I would like to ask if
Update: What I really wanted all along were greenlets . Note: This question mutated
In an effort to further refine my question this is the 3rd rewrite. Here
I know this looks similar to other questions here but I don't think my
I am a desktop client developer. I now got to continue this project is
For an algorithm competition training (not homework) we were given this question from a
I searched SO and found this question , but it's not quite what I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.