Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

How can I save a form values like contact us?

edited April 4 in Modules

I have a traditional contact us form for user and I want to save its values to database. I have followed tutorials for creating modules, but I can't understand how can I use these models to save the data or how do I set the values coming from form to these models and then call save upon them?
I can see the module in CMS and I can create entries by filling form, but I want to be able to get the end user's values in entries?

Comments

  • This documentation may help too:
    http://docs.getfuelcms.com/general/models

  • I have seen these examples as I told earlier in my post but this is for CMS forms creating and saving and I have done this part, I can create forms via CMS and save it. What I want to do is allow a frontend user to submit the form. I have also seen the save and create methods in My_Model class and tried to use them but they don't work or I can't get them working. I have used them like
    $this->load->model('Contact_us_model')
    $this->Contact_us_model->save($this->input->post())
    but it doesn't do anything.
    Of course this is after I get the values from frontend.

  • Perhaps there is a validation error on save? The save method should return false if it doesn't save and then you can check for any errors:

    print_r($this->contact_us_model->get_errors());
    
  • I have tried your approach as well as tried outputting the clean method, which is only giving two fields back although I have given it 5 fields and 1 for honeypot hidden field another is send field, in total 7 fields, I thought it was due to naming in my fields and model's required array and changed it to reflect the form ones, but still same result and no output from save method.
    This is how I'm doing right now in my controller after checking for form validation errors. I have checked my post and it passes all rules.
    $this->load->model('Contact_us_model');
    print_r($this->Contact_us_model->save($this->input->post()));

    This is my required array in model after changing them to form name fields
    public $required = array('full-name' => 'Full Name is not provided', 'company-name' => 'Company Name is not provided', 'message' => 'Message is not provided', 'email' => 'Email address is not provided', 'contact-number' => 'Contact Number is not provided');
    But it also does not give any error message.

  • Okay! A big apology as I didn't saw your message completely and missed the get_errors part. It was due to the fact that I was using different field names in my model and form that I was not getting them from post to model, and as soon as I provide it correct field names I was able to get the data in model and also save it.
    The correct way is to use the same field names in both your database and form field's name attribute, so they can sync with each other.
    Thank you once again for your help, and I think that the user guide should provide a short tutorial or examples like this so it does not get too confusing.

Sign In or Register to comment.