Jump to content

carlg

Members
  • Posts

    104
  • Joined

  • Last visited

    Never

About carlg

  • Birthday 09/24/1974

Profile Information

  • Gender
    Male
  • Location
    PA

carlg's Achievements

Member

Member (2/5)

0

Reputation

  1. Got it now. What I mentioned above was the problem!
  2. I think what I was missing was where the $data is located. Looks like you are setting it up and using it in the view. I was setting it up in the controller and trying to pass it to the view. I'm going to try to put this together later in the afternoon today (or evening). Thanks for all your help so far!!!
  3. "and how does $data['name'] become $fname ?" I changed it to a separate array for each field on my form. Bad idea?
  4. So where I am going wrong with the above. Anyway, please excuse me if I'm not getting it that quick as I'm newer to CI.
  5. So in my view I have this: (keep in mind I'm using the same view for adds and updates) <?php echo form_input($fname, set_value('fname')); ?> <?php echo form_input($email, set_value('email')); ?> When the user clicks the button to update here is the controller code before the view gets called: $data['name'] = array( 'fname' => 'fname', 'value' => $seller->s_fname, 'placeholder' => 'First Name' ); $data['email'] = array( 'name' => 'email', 'size' => 50, 'value' => $seller->s_email, 'placeholder' => 'Email' ); and then $data is passed to the view (I turned your $data into an array of multiple elements) When the user wants to add a new record, he clicks the add button and here is the code from the controller: $data['title'] = 'Add new seller'; $data['message'] = ''; $data['action'] = site_url('seller/addSeller'); $data['fname']=""; $this->load->view('EditSeller', $data);
  6. Actually when I do what I said in the previous post, it comes back with an error when the user submits an erroneous form since the $data variable does not get kept on the re-rendering of the view.
  7. Sorry, I had another question about this topic so I reopened it. In the case where I'm using my view for an add, $data is undefined. So do you think it makes sense to throw in a $data=""; in the add part of my controller before the view gets called? And when it's doing an update, it will do something similar to what Mahngiel posted.
  8. What about when the user submits the form and there are validation errors? Would this hold the values in the fields so the user does not need to enter them again like set_value and validation does?
  9. Does this allow me to use the same form/view for adds and updates?
  10. Maybe I wasn't clear enough on the question. I'm trying to set the values when the form is loaded for the first time. I'm using the same form/view for both adds and updates. I'm using the set_value in the form to display the fields. The user clicks an edit button from a summary page which calls the update function you see above passing in the id of the seller to update.
  11. I'm trying to figure out how to populate my form fields on a simple crud update. Here is some of my view (I use this view for both adds and updates): <input type="text" name="email" value="<?php echo set_value('email', ''); ?>"/> Here is the code in the controller that loads the above view: function update($id){ $data['seller'] = $this->seller_model->get_seller_byID($id)->row(); $this->load->view('EditSeller', $data); } This all works fine for me on adds, but how do I populate the form fields for an edit? I needs to happen somewhere in the update function of my controller; I'm just not sure how. This is most likely a simple question, but I'm just starting CI, thanks for the help.
  12. Thanks for the solution. "On a side-note: why do you wrap your form inputs in a div with a non-contained string? You should use a label instead." No reason, this is just a sample project I'm doing for educational purposes. I was more concerned with learning codeignitor than creating good html at the time.
  13. I'm having a problem getting codeignitor to repopulate the form fields when there is a validation error. If the validation is successful, the fields are populated properly as expected. Here is the code from my controller which is called by the submit button: public function addSeller() { $this->form_validation->set_rules('fname', 'First Name', 'required'); $data['action'] = site_url('seller/addSeller'); if ($this->form_validation->run() == FALSE) { $data['message'] = 'fail'; } else { //SAVE DATA HERE $data['message'] = 'success'; } $this->load->view('EditSeller', $data); } And here is my view: <html> <head> </head> <body> <?php echo $message; ?> <?php echo validation_errors(); ?> <div class="content"> <form method="post" action="<?php echo $action; ?>"> <div class="data"> <div>ID: <label><?php echo set_value('id', ''); ?></label> </div> <div>First Name: <input type="text" name="fname" value="<?php echo set_value('fname', ''); ?>"/> </div> <div>Last Name: <input type="text" name="lname" value="<?php echo set_value('lname', ''); ?>"/> </div> <div>Email: <input type="text" name="email" value="<?php echo set_value('email', ''); ?>"/> </div> <div>Password: <input type="text" name="pword" value="<?php echo set_value('pword', ''); ?>"/> </div> <input type="submit" value="Save"/> </div> </form> <br /> </div> </body> </html>
  14. Think I'm going with paging for the above reason and the overhead associated with learning and installing jqgrid.
×
×
  • 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.