Is multiple insertions possible in FUELCMS?

edited May 2016 in Modules
Hello Sir,

I am a beginner in FuelCms. have a module in which I need to enter multiple data of the form on click of Save button at once.
As we are aware that FuelCms gets data in array form to store in database .So, my question is "Can I enter multiple data with unique entries on click of single button using one form only and on_before_save method will help me to do so ?".

Comments

  • edited 1:13AM
    Yes you can and I would use something like the on_before_save or on_after_save function to save multiple data potentially to another table. The "template" field type allows for repeatable fields that produces an array in which you can iterate through in those hooks:
    http://docs.getfuelcms.com/general/forms#template

    Additionally, you can use serialized fields to save a JSON representation of the data stored:
    http://docs.getfuelcms.com/general/models#serialized
  • edited 1:13AM
    Sir,

    Thank you.

    Single form data is only getting stored in database using Template field type even after filling 2 or more forms.And i made my fields serialized using

    public $serialized_fields = array('fields_name1','fields_name2');

    in the model page which isn't working and even on_before_save() hooks shows that only single form data in array is getting passed on.

    Sir,What should I do now to solve this?

    Thanks in advance.
  • edited 1:13AM
    The $values array may not contain everything that was posted (depending on if it's an actual field on the model). To access all the posted data, there is a property on the model you can access in your model hooks called 'normalized_save_data':
    function on_after_save($values) { $data = $this->normalized_save_data; print_r($data); exit(); }
Sign In or Register to comment.