CodeIgniter Forums
[HELP] Form submit and - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [HELP] Form submit and (/showthread.php?tid=55085)



[HELP] Form submit and - El Forum - 10-09-2012

[eluser]Darker[/eluser]
http://109.235.69.39/ci/register
click "register" and you can see...
Why ?

register.php controller
Code:
<?
class Register extends CI_Controller {
public function index() {
  $this->load->library('form_validation');
  $this->form_validation->set_rules('first_name', 'First name', 'required');
  $this->form_validation->set_rules('last_name', 'Last name', 'required');
  $this->form_validation->set_rules('username', 'Username', 'callback_checkuser');
  $this->form_validation->set_rules('password', 'Password', 'required');
  $this->form_validation->set_rules('password2', 'Password Confirmation', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');
  $this->form_validation->set_rules('country', 'Country', 'required');
  $this->form_validation->set_rules('city', 'City', 'required');
  $this->form_validation->set_rules('date_of_birth', 'Date of birth', 'required');
  $this->form_validation->set_rules('agree', 'You must check "I agree with terms and conditions"', 'required');
  if ($this->form_validation->run() == FALSE) {
   $data['action'] = "";
  } else {
   $data['action'] = "register_success";
  }
  $data['page'] = 'pages/register_view';
  $data['temporary_data'] = $data;
  $this->load->view('main_view', $data);
}
function checkuser($username) {
  $this->load->model('user_model');
  $exists = $this->user_model->ifUserExists($username);
  if ($exists) { return FALSE; } else { return TRUE; }
}
}
?>

register_view.php view
Code:
<?
print_r($temporary_data);
if ($action == "register_success") {
    ?>
    <h2>Success!</h2>
    Congratulations, registration successful. We sent you an email with account confirmation link.
    &lt;?
} else {
    $this->load->helper('form');
    echo form_open(base_url() . 'register');
    ?&gt;
    <strong>Fill in registration form</strong>
    <br /><br />
    First name:<br />
    &lt;? echo form_input('first_name'); ?&gt;
    <br />Last name:<br />
    &lt;? echo form_input('last_name'); ?&gt;
    <br />Username:<br />
    &lt;? echo form_input('username'); ?&gt;
    <br />Password:<br />
    &lt;? echo form_password('password'); ?&gt;
    <br />Confirm password:<br />
    &lt;? echo form_password('password2'); ?&gt;
    <br />E-mail address:<br />
    &lt;? echo form_input('email'); ?&gt;
    <br />Country:<br />
    &lt;?
    $options = array(
    '0' => '-- none --', '1' => 'Lithuania',
    '2' => 'Latvia', '3' => 'Estonia');
    echo form_dropdown('country', $options, 'Lithuania');
    ?&gt;
    <br />City:<br />
    &lt;? echo form_input('city'); ?&gt;
    <br />Date of birth:<br />
    &lt;? echo form_input('date_of_birth'); ?&gt;
    <br /><br />
    &lt;? echo form_checkbox('agree', '1', TRUE); ?&gt;
    I agree with terms and conditions
    <br /><br />
    &lt;?
    echo form_submit('submit', ' Register ');
    echo form_close();
}
?&gt;

Thanks for you help.


[HELP] Form submit and - El Forum - 10-09-2012

[eluser]TWP Marketing[/eluser]
Load the form helper in the controller:
Code:
&lt;?
print_r($temporary_data);
if ($action == "register_success") {
    ?&gt;
    <h2>Success!</h2>
    Congratulations, registration successful. We sent you an email with account confirmation link.
    &lt;?
} else {
    $this->load->helper('form'); // Move this to the controller
    echo form_open(base_url() . 'register');
    ?&gt;
...



[HELP] Form submit and - El Forum - 10-10-2012

[eluser]Darker[/eluser]
[quote author="TWP Marketing" date="1349817667"]Load the form helper in the controller:
Code:
&lt;?
print_r($temporary_data);
if ($action == "register_success") {
    ?&gt;
    <h2>Success!</h2>
    Congratulations, registration successful. We sent you an email with account confirmation link.
    &lt;?
} else {
    $this->load->helper('form'); // Move this to the controller
    echo form_open(base_url() . 'register');
    ?&gt;
...
[/quote]

Code:
public function index() {
     $this->load->helper('form');
  $this->load->library('form_validation');
  $this->form_validation->set_rules('first_name', 'First name', 'required');

Like this ? Still...


[HELP] Form submit and - El Forum - 10-10-2012

[eluser]Darker[/eluser]
Can anyone help me with it ?

Thanks.


[HELP] Form submit and - El Forum - 10-10-2012

[eluser]TWP Marketing[/eluser]
Check that you have configured base_url() in the application/config/config.php

Use this form for base_url(). See the user guide: user_guide/helpers/url_helper.html

Code:
echo form_open( base_url('register') );



[HELP] Form submit and - El Forum - 10-10-2012

[eluser]CroNiX[/eluser]
form_open() already inserts base_url(), so you'd be doing it 2x. (view the outputted source) You only include the controller/method.

It should just be form_open('register/index') if going to the index method of the register controller.


[HELP] Form submit and - El Forum - 10-10-2012

[eluser]Darker[/eluser]
[quote author="CroNiX" date="1349892958"]form_open() already inserts base_url(), so you'd be doing it 2x. (view the outputted source) You only include the controller/method.

It should just be form_open('register/index') if going to the index method of the register controller.[/quote]

When you fill all inputs its ok, no error. Thats weird.


[HELP] Form submit and - El Forum - 10-10-2012

[eluser]CroNiX[/eluser]
I don't see anywhere where you are displaying the errors, if there are any.

You should always use full open php tags, even if YOUR server is set to use short tags.
Code:
&lt;?php
and always leave off the very last closing php tag on the page to avoid whitespace problems.


[HELP] Form submit and - El Forum - 10-10-2012

[eluser]Darker[/eluser]
[quote author="CroNiX" date="1349895426"]I don't see anywhere where you are displaying the errors, if there are any.

You should always use full open php tags, even if YOUR server is set to use short tags.
[/code]&lt;?php[/code]
and always leave off the very last closing php tag on the page to avoid whitespace problems.[/quote]

I mean when you fill whole form the 500 error won't appear.


[HELP] Form submit and - El Forum - 10-11-2012

[eluser]Darker[/eluser]
The problem was a bad tutorial. 'callback_checkuser' had to be 'checkuser'.

Thanks for your help.