Welcome Guest, Not a member yet? Register   Sign In
Trouble Getting Form to Validate
#1

[eluser]SpecVengeance[/eluser]
I am trying to get my form to validate, and for the life of me I can't seem to get it to work, I am using "CodeIgniter User Guide Version 1.7.2" and I just can't get it working.

Code is listed, below.

Contact Controller
Code:
<?php

class Contact extends Controller
{
    function Contact()
    {
        parent::Controller();
        
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

    }
    function index()
    {
        $data['title_for_layout'] = "Website Redesigns | Florida Web Design Company | Last 7 Studios";
        $data['keywords_for_layout'] = "Florida Web Design Company Last 7 Studios";
        $data['description_for_layout'] = "Florida Web Design Company Last 7 Studios";
        $this->load->library('layout', 'layout_main');
        
        
            
        $this->form_validation->set_rules('name', 'Name', 'required');
        
        if ($this->form_validation->run() == FALSE)
        {
            $this->layout->view('/contact/contact_view', $data);
        }
        else
        {
            $this->load->view('formsucess');
        }
    }


}
?>

Contact View
Code:
<div id="left">

<h1 class="content_title">Contact the Web Design Professionals</h1><br />
<h3 class="content">Web Design, Graphic Design, Print Media, Search Engine Optimization, Logo Design</h3>
<h2>Just Fill out the Form Below and we will respond to you in a flash!</h2>
<p>Thank you for visiting us online. If you have any questions or comments regarding what we do and how we can help you - please call, e-mail, stop by, or fill out the form below.</p><br />

&lt;?php echo validation_errors(); ?&gt;

&lt;?php echo form_open('contact-last-7-studios'); ?&gt;
        <fieldset>
        <legend><span class="req">*</span> <font face="Verdana, Geneva, sans-serif">= Required Fields</font></legend>
      
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="138"><label for="name">Name:<span class="req">*</span></label></td>
<td>&lt;input name="name" id="name" type="text" size="20" value="" /&gt;&lt;/td>
</tr>
<tr>
<td><label for="name">Company:</label></td>
<td>&lt;input name="company" id="company" type="text" size="20" value="" /&gt;&lt;/td>
</tr>
<tr>
<td><label for="name">Address:</label></td>
<td>&lt;input name="address" id="address" type="text" value=""  /&gt;&lt;/td>
</tr>
<tr>
<td><label for="name">City:</label></td>
<td>&lt;input name="city" id="city" type="text" value="" /&gt;&lt;/td>
</tr>
<tr>
<td><label for="state">State </label></td>
</tr>
<tr>
<td><label for="zip">Zip:</label></td>
<td>&lt;input name="zip" id="zip" type="text" value="" /&gt;&lt;/td>
</tr>
<tr>
<td><label for="phone">Phone:</label></td>
<td>&lt;input name="phone" id="phone" type="text" value="" /&gt;&lt;/td>
</tr>
<tr>
<td><label for="fax">Fax:</label></td>
<td>&lt;input name="fax" id="fax" type="text" value="" /&gt;&lt;/td>
</tr>
<tr>
#2

[eluser]mohsin917[/eluser]
how you submit the form?
#3

[eluser]mohsin917[/eluser]
Try this one, this is the easy way..

also read the form validation user guid

contact.php controller
Code:
&lt;?php

class Contact extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
                
        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('contact_view');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?&gt;

contact_view.php view file
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php echo validation_errors(); ?&gt;

&lt;?php echo form_open('contact'); ?&gt;

<h5>Username</h5>
&lt;input type="text" name="username" value="" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
#4

[eluser]SpecVengeance[/eluser]
that is the validation system that I am using, and it is not working correctly, and yes I left the submit button off in that code area. It was a mistake on my part, but it is actually there in the live script.
#5

[eluser]mohsin917[/eluser]
Dude your form is also working. I checked it too. Just change this

form_open('contact-last-7-studios');

with this

form_open('contact');


Because the validation library is loaded in contact controller and in it you set the rules not in contact-last-7-studios.

in form_open you have to enter the action of the form.
#6

[eluser]SpecVengeance[/eluser]
Maybe I am doing something wrong then, because I changed that and I can't seem to get that to validate. It acts like there is nothing happening and it just reloads the page.
#7

[eluser]n0xie[/eluser]
Does anybody else think it's ironic that someone making a website with this title
Quote: $data['title_for_layout'] = "Website Redesigns | Florida Web Design Company | Last 7 Studios";
can't get a basic form validation to work?




Theme © iAndrew 2016 - Forum software by © MyBB