Jump to content

carlg

Members
  • Posts

    104
  • Joined

  • Last visited

    Never

Everything posted by carlg

  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.
  15. I'm creating a web based application where the user will open a page and there could be anywhere from 5 up to thousands of records on the page. They will then click on a link to edit the record. There are about 5-7 fields to show for each record. Pretty simple stuff, not complicated. So what do you think is a better way to implement this? Using basic paging methods (calculating number of rows and doing the math) and spitting out a table or plain html or do you think it is better to use a grid such as jqgrid where the paging is built in already for me?
  16. I'm trying to create some PHP code and I'm trying to cleanly organize everything. Let's assume I have an account object. I'm trying to figure out (from a design perspective) the best way to do this: Here is approach #1. class Account { public $id; function getAccounts () { // I know this code doesn't work, but it demonstrates the point mysql_query ("Select * from Account"); } } Approach #2: or is is better to have the getAccounts in a separate DAO class (called AccountDAO) so in my main program I would declare an Account object and an AccountDAO object? I'm really trying to figure out the preferred way to structure my application.
  17. Yes, very similar to that, thanks. Besides I'm not doing file uploads (I just used file uploads as an example since it is a common place to see this technique used) My application will have student name, grade point average, and major. The user can add as many students as he wishes;
  18. "First off a file upload field is not a text box - it is a file input that will include a browse button." I knew this already, thanks. File upload is the most common place you see this technique used on the web. In my application, there will be groupings of 3 items (2 dropdowns and 1 text box). So I guess I would handle this in a similar fashion? Thanks again.
  19. I'm not sure of the appropriate subject line for this feature, but hopefully I'm close. I'll try to describe what I'm trying to do. The most common place you see this is on web based file uploads so I'll use it as my example. Let's say I want to allow my user to upload files so there is a text box where they enter the file name. The user is allowed to upload as many files as he wants with 1 push of the submit button. Upon the loading of the form, there will be 5 textboxes for file upload, but if the user wants to upload more than 5 files, there is a link that is clicked and I think via ajax or javascript another textbox will be added. The user can do this for as many files he wants to upload. This is what it looks like to the user, but then when the form is submitted how are these variables referenced? So how is this setup in the main form and how are the variables referenced after form submission? If anyone can point me to a good web tutorial on this type of thing I would appreciate it. Thanks Carl
  20. Figured it out myself. Solution is to get rid of the quotes. Thanks
  21. I have the following code: $query = "SELECT * FROM table"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)){ print $row['$variable']; } What is the proper syntax to use on this line? print $row['$variable']; This code is part of a function and the column that I want to print is variable based upon which parameter is passed in. Thanks
  22. I'm not sure which operating system you are using, but if I was on a Linux based system, I would write a very quick script. sort -u <filename.txt> > newfilename.txt You could actually call it from a php script if needed. If you really have the need to do this in php, the only way I could think of is to read the entire file into an array. Then use the array_unique function. Then write the array back out to the file.
  23. One of my websites allows public users to fill out a web based form and the form information gets sent on in an email. This is totally getting spammed. I figure I could create my own little spam filter. All I need is a "Dirty word" list which I can easily make myself and the ability to use grep. Let's say I place all of my dirty words in a file called dw.txt The message part of the mail is stored in a variable called $message If I was writing a shell script I could do something like the following: if [ $(grep -f dw.txt $message) -ne "" ] then #THIS IS SPAM fi The only way I see to do this with php is to read the contents of the file into an array with the file command. Loop through the array of dirty words and use preg_grep for each iteration. Does anyone have a better way to do this than to loop through each line of the file? Thanks for the help! Carl
  24. I need to implement calendar functionality on one of my websites. I need to make a nice interface for the user to select dates. Does anyone know of any open source/freeware scripts or libraries that I could use to implement this? Or do I need to write from scratch? Carl
×
×
  • 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.