Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 11,112
» Latest member: fineleric
» Forum threads: 67,631
» Forum posts: 422,807

Full Statistics

Latest Threads
Return Path Is Not Set Wh...
Forum: Libraries & Helpers
11 minutes ago
» Replies: 1   » Views: 17
How to watch iTunes movie...
Forum: Lounge
19 minutes ago
» Replies: 13   » Views: 1,589
Lost session
Forum: CodeIgniter 4 Support
1 hour ago
» Replies: 23   » Views: 441
CodeIgniter 3.x.x Branch ...
Forum: CodeIgniter 3.x
2 hours ago
» Replies: 4   » Views: 214
cart library google are n...
Forum: Libraries & Helpers
2 hours ago
» Replies: 0   » Views: 10
blank admin page
Forum: General Help
3 hours ago
» Replies: 2   » Views: 63
CodeIgniter 3.1.7 unbuffe...
Forum: Issues
3 hours ago
» Replies: 3   » Views: 155
Missing Argument Error
Forum: General Help
7 hours ago
» Replies: 1   » Views: 66
language switcher and SEO...
Forum: Best Practices
8 hours ago
» Replies: 2   » Views: 216
If flexi-auth dead?
Forum: Addins
Yesterday, 08:36 PM
» Replies: 0   » Views: 63

 
  Validation headaches
Posted by: El Forum - 08-13-2007, 04:47 PM - Forum: Archived Development & Programming - Replies (7)

[eluser]codex[/eluser]
Hello,

I bet I'm not the first to have this kind of trouble as a noob, but I'm puzzled about how to do validation properly using the validation class. I've searched the docs and forum, but it still isn't exactly clear to me. Hope you guys can help!

Basically I want a user to change his password. Therefore he has to enter the old pass, the new and a new retype. Pretty basic stuff (in plain old php I can do it with no probs). The input of the old password is checked against the DB. Now, if the password doesn't exist, aan error should be thrown. But I can't seem to get the validation working.

This is what I have so far:

Controller: settings.php

Code:
<?php
class Settings extends Controller {

    function Settings()
    {
        parent::Controller();
        setlocale (LC_ALL, "nl_NL");
        $this->load->model('mailbox_model');
        $this->load->model('settings_model');
        $_SESSION['uid'] = 1000;
    }
      
    function password()
    {    
        $this->load->library('validation');
                
            $rules['old_password']            = "required";
            $rules['new_password']            = "required";
            $rules['new_password_retype']     = "required|matches[new_password]";
            $this->validation->set_rules($rules);
            
        $old = $this->input->post('old_password');
        
        if ($this->settings_model->check_pass($old)) {
            // ERROR HERE I GUESS
        }
                
        $this->validation->set_error_delimiters('<p class="alert">', '</p>');    
        
        if ($this->validation->run() == FALSE)
        {
            $data['title']             = "Wachtwoord";
            $template['content']    = $this->load->view('settings/password_view', $data, true);
            $this->load->view('main_template', $template);
        }
        else {
            $this->load->view('formsuccess');
        }
    }
    
}
?&gt;


Model: settings_model.php
Code:
&lt;?php
class Settings_model extends Model {

    function Settings_model()
    {
        parent::Model();
    }

    function check_pass($old_pass)
    {
        $query = $this->db->query("    SELECT user_password
                            FROM users
                            WHERE user_password ='". md5($old_pass) ."'
                            AND user_id = '". $_SESSION['uid'] ."' ");
        
        if($query->num_rows() > 0) {
            return true;
        }
    }
}
?&gt;


View: password_view.php
Code:
&lt;?=$this->validation->error_string; ?&gt;
&lt;form method="post" name="edit_password" class="pt-20"&gt;
<label for="old_password" class="bold">Je oude wachtwoord</label>
<p class="pb-5">&lt;?php echo input_password("old_password", 30, "input_text", $this->validation->old_password)?&gt;</p>
<label for="new_password" class="bold">Nieuwe wachtwoord</label>
<p class="pb-5">&lt;?php echo input_password("new_password", 30, "input_text", $this->validation->new_password)?&gt;</p>
<label for="new_password_retype" class="bold">Nieuwe wachtwoord nogmaals</label>
<p class="pb-5">&lt;?php echo input_password("new_password_retype", 30, "input_text", $this->validation->new_password_retype)?&gt;</p>
<p>&lt;?php echo input_submit("edit_password", "input_submit", "Wachtwoord opslaan")?&gt;</p>
&lt;/form&gt;

Any help is greatly appreciated!!


  Moving site visitors through a whole bunch of 'yes/no' questions - best way to do this?
Posted by: El Forum - 08-13-2007, 04:45 PM - Forum: Archived Development & Programming - Replies (3)

[eluser]tinawina[/eluser]
Hi - I am developing an application that moves people through a series of yes/no questions:

Question #1:
Answer: yes -> track visitor to Question #1b
Answer: no -> track visitor to Question #2

Question #1b:
Answer: yes? -> track visitor to Question #1c
Answer: no? -> track visitor to Question #3

etc.

In the end, we'll have a lot of questions -- a visitor will answer somewhere's around 25 total, start to finish. We are only using the answers to get to a definitive yes/no -- not saving all of these answers to a dbase or anything.

(All of this yes/no business is an attempt to help people understand copyright and hopefully get them to use a Creative Commons license to freely share their written works.)

Before I dig into building this out, I'm wondering what the best way to structure it is. For instance, it seems to me that I should be able to dynamically generate the question form view from the controller rather than building out lots of individual files in my view folder, one for each yes/no question. Of course, I'm scratching my head re: how to actually do this.

I appreciate any insights, ideas, theories, cautions, tips and/or tricks you can share with me! Thanks!


  Using truly object-oriented models?
Posted by: El Forum - 08-13-2007, 03:52 PM - Forum: Archived General Discussion - Replies (27)

[eluser]Matthew Pennell[/eluser]
I've just started learning Ruby on Rails, and one of the things that stands out for me is the way it seems to use Models in a more truly object-oriented fashion than Code Igniter does.

In RoR, you (for example) would call the new() method of your Article model, and it will return an object representing the new Article, complete with methods and properties:

Code:
@article = Article.new # => the variable @article is now an instance of the Article class
@article.title = "My latest blog entry"
puts @article.title # => prints the title

CI, by comparison, seems more like a bunch of procedural functions that just happen to be namespaced into a particular model - there's no object-relationship between the model and the 'thing' it represents:

Code:
$article = $this->article_model->new(); // we can assign the result to a variable, but it isn't an instance of the Article class
$this->article_model->setTitle("My latest blog entry");
echo $this->article_model->getTitle(); // prints the title, assuming we kept a reference to the row in the database

Is this something I'm misunderstanding about CI, or was it never supposed to be truly OO in respect of models?


  Loading Email Body From A File
Posted by: El Forum - 08-13-2007, 03:46 PM - Forum: Archived Development & Programming - Replies (2)

[eluser]omed habib[/eluser]
Hey guys,

I'm trying to load the body of an email from an external file. I assumed the way to do this is this:

Code:
$this->load->library('email');        
$this->email->from('[email protected]', 'Sender');
$this->email->to('[email protected]');
$this->email->subject('Subject');

$emailbody = $this->load->view('contactus/emailtemplate');            
$this->email->message($emailbody);        

$this->email->send();

This doesn't work and only sends a blank email. Any ideas anyone?


  Just three little questions?
Posted by: El Forum - 08-13-2007, 03:00 PM - Forum: Archived Development & Programming - Replies (5)

[eluser]danfloun[/eluser]
Hi,
How can I use validation on a textarea that doesn't accept a value="" parameter?

Secondly, how can I format the contents of a form field before it is passed to the database. I need uk 11 digit telephone numbers to be formatted like:

Code:
##### ######

The first part being the area code but I don't what brackets round it.
Is it a case of Regex expressions or what?

and third,
Is it possible to use form field validation that requires at least one of two fields to have data entered!

For example,

Field One
Field Two

On validation it checks to see if either field has data. If either or both fields contain data it verifies. If neither field contains data it fails.

Possible?

Thanks

Danny


  authorization function w/multiple failure values
Posted by: El Forum - 08-13-2007, 02:52 PM - Forum: Archived Development & Programming - Replies (2)

[eluser]Bacteria Man[/eluser]
I'm developing an authorization function which will return multiple failure values. In other words not just true/false.

To reduce overhead the query string includes a couple of left joins to return all the required data in one pass. If the foreign keys do not exist, the corresponding fields will equal null. Depending on which field is null will determine where the authorization fails.

In the past (using other platforms) I've devised a list of error codes. For example:

-100, that group does not exist
-200, you are already a member of this group
-300, you are not allowed to join this group

The function will return true if all of the conditions are satisfied.

There's nothing complicated about this, but what's the best way to about it using Code Igniter? Is there anything in the core that would make this more efficient and/or easier to implement?

Thanks in advance.


  New to CI : Am I missing something (postgresql)
Posted by: El Forum - 08-13-2007, 02:40 PM - Forum: Archived General Discussion - No Replies

[eluser]Unknown[/eluser]
OK so I setup my db stuff, setup the scaffolding trigger etc etc. Basically my database uses schemas to break apart data. In this instance i am breaking them up by app name in 1 database.

site_management
... application1
---- table1
---- table2
...application2
----table1
----table2

So I setup a scaffold call in a sample controller and I get SELECT COUNT(*) AS numrows FROM "application1.table1"

When I run the query without the quotes in my postgresql it works. but when it has the " in the query it is thrown off. Am I missing an option here somewhere?

- Andy


  JQuery $.post() and CI inquiry
Posted by: El Forum - 08-13-2007, 02:34 PM - Forum: Archived Development & Programming - Replies (4)

[eluser]stevefink[/eluser]
Hi all,

I have a simple javascript file being loaded externally that has the following code:

-- snip --

$(document).ready(function() {

$('#pendingUsers').load('index.php/meduser/check_pending_users',false, function() {
$('#pendingUsers a').click(function() {
$.post('index.php/meduser/pull_user_information', {id: $(this).attr('rel')}
);
});
});

setInterval(function() {
$('#pendingUsers').load('index.php/meduser/check_pending_users');
}, 300000);

// initially hide the main content div until a pending user is clicked.

});

-- snip --

My issue here is I'm not sure how with CI to associate the $.post() with the div I want to populate the data back from the server with in a view. My view contains a <div id="main"></div> area where the results should be posted back.

My controller looks like this:

function pull_user_information()
{
$id = $this->input->post('id');
$data['query'] = $this->db_users->query('select * from tbl_signups
where ID="$id"'
);

$this->load->view('default/meduser_useraccordny_view', $data);
}

I'm trying to populate the rel of the anchor tag into $id and using that to query the database.

I can then pass that into the meduser_useraccordny_view, however I'm still not entirely sure how to populate the particular div.

Any assistance would be appreciated!


  CRUD : url identification of an item by number or by id?
Posted by: El Forum - 08-13-2007, 01:00 PM - Forum: Archived Development & Programming - Replies (1)

[eluser]NemetraL[/eluser]
Hello,

Just a quick poll to know what you generally use to point an item using the URL in a CRUD-like web application (for example an online gallery) %-P

As you may know, the number is most likely different from the ID: let's say you create 5 pictures from scratch in this gallery, the five ID will exactly match the numbers like:

ID: #
1 : 1
2 : 2
3 : 3
4 : 4
5 : 5

Then if you delete picture number 3, the IDs will no longer match the numbers starting from entry 3 on:

ID: #
1 : 1
2 : 2
4 : 3
5 : 4

And so on..

When you display all the pictures in a web page, you'll index the results by number (not by ID, otherwise it will look chaotic). But when you want to display one particular picture, will you access the entry using the number or the ID in the URL?

1st solution: using http://www.site.com/gallery/item/ID
pro: unique identification (you can share the URL)
con: inconsistency with the indexation on the web page displaying all the pictures

2nd solution: using http://www.site.com/gallery/item/number
pro: consistency with the indexation on the web page displaying all the pictures
con: URL not able to be shared since the number of the picture may change at anytime according to its position

So far I tend to use the 1st solution for public applications (an online photo gallery) and the 2nd one for private admin interfaces since there's no reason so share URLs.

What about you?


  Propel ORM?
Posted by: El Forum - 08-13-2007, 12:01 PM - Forum: Archived Development & Programming - Replies (12)

[eluser]jgberg[/eluser]
Based on Hibernate and a google developer podcast I found the Propel ORM which looks interesting. On the wiki is a unfinished and therefore useless article about Propel and CI. I'm looking for any opinions on Propel and on using Propel and CI together.

Thanks!
Jeffrey Greenberg



  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.