Welcome Guest, Not a member yet? Register   Sign In
FormIgniter.org launched - Easy form generator - source code now available
#21

[eluser]Ollie Rattue[/eluser]
[quote author="ururk" date="1255243849"]Found just one small bug (I think?)...


In your controller:

Code:
if ($this->myform_model->SaveForm($form_data)

In your model:

Code:
function save_form($form_data)

So it should be:

Code:
if ($this->myform_model->save_form($form_data)

[/quote]

Many thanks for pointing this out. It has now been corrected.
#22

[eluser]Ollie Rattue[/eluser]
[quote author="drewbee" date="1242259688"]

One additional item that I noticed is that one of the rules can be auto set, as well as the part in the view.

When creating the field you have the option for max length. The rules for the field should automatically set max_length[10] and on the view, the maxlength of the attribute ie <input type="text" maxlength="10">
[/quote]

[quote author="Ollie Rattue" date="1242267621"]drewbee, thanks for the insightful feedback. I really like the maxlength feature. As you say it is something thats suits FormIgniter. You enter the data quickly once and it reproduces it in numerous places; removing the repition is what it is all about. I will add this in when I get a moment, aswell as auto setting the 'DB field Length/Values' in the database Schema Smile[/quote]

Finally found some time to implement this feature. Thanks again for the great idea.
#23

[eluser]Omar Vazquez[/eluser]
Great work. This really rocks. Thanks for sharing.
#24

[eluser]ururk[/eluser]
There is a way to extend this to also serve as a one-stop database table editor, using a single view for the form. I've made tweaks to the standard 'form' generated like so:

In my model:
Code:
function SaveForm($form_data)
function UpdateForm($form_data, $id)
function DeleteForm($id)
function GetForm($id)
function GetForms()

In my View:
Code:
echo form_open('myform/add', $attributes); ?>

Example form element ($var instead of set_value):

Code:
<p>
        <label for="role_name">Role Name <span class="required">*</span></label>
        &lt;?php echo form_error('role_name'); ?&gt;
        <br />&lt;input id="role_name" type="text" name="role_name" value="&lt;?php echo $role_name; ?&gt;"  /&gt;
</p>

&lt;input type="hidden" name="id" value="&lt;php echo $id; ?&gt;" />
&lt;input type="hidden" name="operation" value="&lt;?php echo $operation ?&gt;" /&gt;

In my controller:

Code:
function index() - generalized for loop using a table generated via GetForms
    function add() - handles UPDATES and INSERTS
        $this->_validate(); // moved to separate function just to tidy the code up a bit
        $validate_fields = $this->form_validation->run();

        $form_data = array(
            'myform_name' => set_value('myform_name'),
            'myform_level' => set_value('myform_level')
        );

        if ($validate_fields == FALSE) // validation hasn't been passed
        {
            $form_data['role_id'] = set_value('role_id');
            $form_data['operation'] = set_value('operation');
            $data['content'] = $this->load->view('admin/roles_view', $form_data, true);
        }
        else // passed validation proceed to post success logic
        {
            if (set_value('operation') == 'edit') {
                // run update model to write data to db
                if ($this->myform_model->UpdateForm($form_data, set_value('role_id')) == TRUE) {
                    redirect('myform');
                } else {
                    $data['content'] = 'An error occurred updating the data.';
                }
            } else {
                // run insert model to write data to db
                if ($this-> myform_model->SaveForm($form_data) == TRUE) {
                    redirect('myform');
                } else {
                    $data['content'] = 'An error occurred adding the data.';
                }
            }
        }
    function edit($row_id) {
        if ($this->myform_model->GetForm($row_id) == TRUE) {
            $data = $this->myform_model->GetForm($row_id);
            $data['operation'] = 'edit';
            $data['content'] = $this->load->view('admin/roles_view', $data, true);
        } else {
            $data['content'] = 'Could not find the requested record.';
        }
        $this->load->view('myform', $data);
    }
    function delete($row_id) - deletes a single record

I could post my full code, but it is pretty basic stuff - the code above is chopped up to make it a bit more compact, and I got a little lazy in changing the names I used Big Grin. The trouble occurs when you go to use the form helpers that set values - some require POST values, such that I had to rewrite the cb, rb, and select setters. There may be unintended consequences to this, but they seem to work.
#25

[eluser]Ollie Rattue[/eluser]
[quote author="ururk" date="1256640190"]I could post my full code, but it is pretty basic stuff - the code above is chopped up to make it a bit more compact, and I got a little lazy in changing the names I used Big Grin. The trouble occurs when you go to use the form helpers that set values - some require POST values, such that I had to rewrite the cb, rb, and select setters. There may be unintended consequences to this, but they seem to work.[/quote]

Yes a code upload would be great!

CRUD is one of the two things I have been thinking about recently, the other being jQuery validation.
#26

[eluser]ururk[/eluser]
Will do... as soon as I get this project completed... or maybe sooner.

Based on how I set it up, there probably is a better way. In fact, there is an ActiveRecord class in the wiki that could simplify CRUD... but it owuld be a start.
#27

[eluser]skattabrain[/eluser]
Wow dude... nice ... such a time saver! I think your decision to keep it as a "form starter kit" is a good call.

I'm downloading this and installing it in my toolbox!
#28

[eluser]takasia[/eluser]
I just found it - it's really GREAT app!
Thank you so much! :-)

I'm thinking about using it in my project, I don't know if I will be able to do it, but I want to try this - if you don't mind of cource:

Make a form with your app ->
the files will go automatically to a random-named directories in
/controller/forms/_new_form_random_dir/
/views/forms/_new_form_random_dir/
/models/forms/_new_form_random_dir/
and the SQL would be automatically kicked making a random-named DB for the form.

The "random name" would be unique for every form and stored in separate DB - so calling for example form named "dummy45549" would call a DB named "dummy45549" and controller, view and model stored in:
/controller/forms/dummy45549/
/views/forms/dummy45549/
/models/forms/dummy45549/

I don't know if it's possible but I will give it a try :-)
If I succeed, I will post the files here (can I?).

Thanks once more for a great app and have a nice day :-)
#29

[eluser]Ollie Rattue[/eluser]
Hey takasia,

[quote author="takasia" date="1276070085"]I just found it - it's really GREAT app!
Thank you so much! :-)[/quote]

No problem, glad you find it useful.

[quote author="takasia" date="1276070085"]I'm thinking about using it in my project, I don't know if I will be able to do it, but I want to try this - if you don't mind of cource:

Make a form with your app ->
the files will go automatically to a random-named directories in
/controller/forms/_new_form_random_dir/
/views/forms/_new_form_random_dir/
/models/forms/_new_form_random_dir/
and the SQL would be automatically kicked making a random-named DB for the form.

The "random name" would be unique for every form and stored in separate DB - so calling for example form named "dummy45549" would call a DB named "dummy45549" and controller, view and model stored in:
/controller/forms/dummy45549/
/views/forms/dummy45549/
/models/forms/dummy45549/

I don't know if it's possible but I will give it a try :-)
If I succeed, I will post the files here (can I?).[/quote]

This all sounds very doable. Good luck Smile You may find your proposed automatic setup is a little restrictive though when building a larger application. I tend to have multiple functions containing forms within a controller to keep related functions together. Separating as above may make things a little hard to manage.

Feel free to modify/change/distribute any code based on FormIgniter. It is distributed as open source with a MIT license so you can do anything you like with it. Would love to see your changes posted here.
#30

[eluser]mddd[/eluser]
Ollie, good idea and nice execution! As everybody is on the track of doing feature requests, I have one too Smile

Based on speed of use, I would suggest making the database definition part of the tool optional. Often (at
least in my workflow), the database is already be laid out. By skipping the 'database schema' part, making a
form would be even quicker!




Theme © iAndrew 2016 - Forum software by © MyBB