Welcome Guest, Not a member yet? Register   Sign In
CodeExtinguisher Validation Problem and Possible Solution
#1

[eluser]BeingDefined[/eluser]
First of all I would like to start off saying that codeigniter is a lifesaver. I don't know how I survived without all of these years. On top of that, codeextinguisher is going to be a big help on managing things on the backend. This thread is about codeextinguisher.

Having said that, codeextinguisher programmer recently release 1.5 version. And this was when I heard about ce. Just reading the docs, I could already see all the time and hassle that is going to be saved. So I got right on it and started messing around with it. Everything worked expect validation of the form fields. When I define a set of rules for fields, its suppose to display error messages if the input didn't follow along with the set rules. The doc has it was a problem in php4 so I installed php5 on my windows machine and no luck. So I tried php4 and php5 on linux, same thing, no luck. So one thing was clear here .. it wasn't an issue with the version of php. So I decided to take things on my own hand and started digging thru the code, tracing back steps. After about 2 hours of debugging, I finally was going somewhere. It turns out that the problem wasn't in the internal code, the problem was with displaying the message. The actual code in the view that displays the message is written in codex_header view. Below is that code:
Code:
<?php
                // Displays the error messages

                if(count($this->codexmessages->getAsArray()) > 0){  ?>
                <div id="messages" class="column span-50"> &lt;?php echo $this->codexmessages->getAsHTML(); ?&gt; </div>
                &lt;?php } ?&gt;

Now the problem is that codex_header is being displayed in the constructor(initializer) of thecodexcontroller. So as you can see, codex_header which contained the messagedisplay code was being call before $this->messages variable was actually assigned.

So to fix this I added the follow code to the top of codex_form_view.php view:
Code:
<div class="container">   &lt;?php
                // Displays the error messages

                if(count($this->codexmessages->getAsArray()) > 0){  ?&gt;
                <div id="messages" class="column span-50"> &lt;?php echo $this->codexmessages->getAsHTML(); ?&gt; </div>
                &lt;?php } ?&gt;
</div>


And Bingo! Validation was now displaying the messages. The "Edit" feature was displaying double pages for some reason. Did some digging and turns out that it was infact printing the page twice. To fix this, go into codexcontroller.php and look for this code:
Code:
function execute_edit(){
        if(count($this->codexadmin->get_rules()) > 0){
            $this->codexvalidation->set_rules($this->codexadmin->get_rules());
            if($this->codexvalidation->run() == FALSE){
                $this->edit($_POST);
            }
        }
        if($this->codexmodel->_edit($this->table,$_POST)){
            $this->codexmessages->add('success',$this->codexadmin->get_message('edit_success'),'',true);
            $this->index();
        }
        else{
            $this->codexmessages->add('success',$this->codexadmin->get_message('edit_failure'),'',true);
            $this->index();
        }
    }

Replace the above code with:

Code:
function execute_edit(){
        if(count($this->codexadmin->get_rules()) > 0){
            $this->codexvalidation->set_rules($this->codexadmin->get_rules());
            if($this->codexvalidation->run() == FALSE){
                $this->edit($_POST);
        return;
            }
        }
        if($this->codexmodel->_edit($this->table,$_POST)){
            $this->codexmessages->add('success',$this->codexadmin->get_message('edit_success'),'',true);
            $this->index();
        }
        else{
            $this->codexmessages->add('success',$this->codexadmin->get_message('edit_failure'),'',true);
            $this->index();
        }
    }

Also change line 147: $this->codexforms->populateWithArrayInfo($data[0]); to $this->codexforms->populateWithArrayInfo($data);

Even though I got it working, there is still a small problem. When I enter incorrect entrys into the field once and enter the correct input the second time, I'm redirected to a "Form Ownership error." When I get the error, I'm still logged in cuz I can go back and everything is as it was. The error seems to be referencing to line 14 & 35 in codexmodel. By posting here, I'm hoping one of you smart folks can come up with a solution to the ownership error.
#2

[eluser]Majd Taby[/eluser]
Hello BeingDefined,
The version in the subversion repository is actually a release candidate, not the final version. In fact, I have made a lot of changes since the svn version. One of the changes, is the fix for validation, including the form ownership error. If you hold on for just a few more days, the official release will be made. As of now, it's is done (some new features were introduced since that release candidate), but I have some fine-tuning and final testing to do.

Happy Extinguishing Tongue




Theme © iAndrew 2016 - Forum software by © MyBB