Welcome Guest, Not a member yet? Register   Sign In
Form and bad submit redirect
#1

[eluser]nahalem[/eluser]
Hello,

I have serious problem with form. I create view within form, I wrote code using codeigniter creating form politic. Problem is when I try to send by email all the stuff collected from form the submit button redirects me to the same page of the form. It should redirect the function wrote in the controller. It's doesn't happen. In the controller I included form, url, form_validation helpers and etc. Can somebody provide me on the good way what it's wrong? Code below: Function sendEmail doesn't run... I have many other form on that project, this form all works fine...

When I create another form inside that view, submit button has redirect to the view, not to the function and another form submit button has redirect to the function...

Base url is configured, application works fine, I have problem with this only.

Controller function
Code:
/* main function sending email */
public function sendEmail()
{

  $this->form_validation->set_rules('company_name', 'company_name', 'required');
  $this->form_validation->set_rules('company_adress', 'company_adress', 'required');
  $this->form_validation->set_rules('company_phone', 'company_phone', 'required');
  $this->form_validation->set_rules('company_email', 'company_email', 'required');
  $this->form_validation->set_rules('company_nip', 'company_nip', 'required|valid_email()');
  
  $this->form_validation->set_rules('company_name2', 'company_name2', 'required');
  $this->form_validation->set_rules('company_adress2', 'company_adress2', 'required');
  $this->form_validation->set_rules('company_phone', 'company_phone', 'required');
  

  $this->form_validation->set_rules('username', 'username', 'required');
  $this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
  $this->form_validation->set_rules('subject', 'subject', 'required');
  $this->form_validation->set_rules('message', 'message', 'required');
  
  if ($this->form_validation->run() == FALSE)
  {

   $this->indexMain(3);

  }
  else
  {
  
   $this->email->to('[email protected]');
   $this->email->subject($this->input->post('subject'));
   $this->email->message($this->input->post('message'));
  
   if(!$this->email->send())
   {
    //return $this->email->print_debugger();
   }
   else
   {
    
   }
  
  }
}

view form
Code:
<?php echo form_open('mycontroller_name/sendEmail'); ?>
<div id="errors">
&lt;?php echo validation_errors(); ?&gt;
</div>
<br /><br /><br />
<fieldset class="info">
<legend class="leg">Dane do wysyłki</legend>
<table class="bank_account_info">
<tr>
<td class="bank_account_info_title">
  Nazwa firmy
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_name',set_value('company_name'),$company_name); ?&gt;
</td>
</tr>
<tr>
<td class="bank_account_info_title">
  Adres
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_adress',set_value('company_adress'),$company_adress); ?&gt;
</td>
</tr>
<tr>
<td class="bank_account_info_title">
  Telefon
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_phone',set_value('company_phone'),$company_phone); ?&gt;
</td>
</tr>
<tr>
<td class="bank_account_info_title">
  Email
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_email',set_value('company_email'),$company_email); ?&gt;
</td>
</tr>
</table>

<br /><br /><br />
<legend class="leg">Dane do faktury</legend>

<table class="bank_account_info">
<tr>
<td class="bank_account_info_title">
  Nazwa firmy, imię nazwisko
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_name2',set_value('company_name2'),$company_name2); ?&gt;
</td>
</tr>
<tr>
<td class="bank_account_info_title">
  Adres
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_adress2',set_value('company_adress2'),$company_adress2); ?&gt;
</td>
</tr>
<tr>
<td class="bank_account_info_title">
  NIP
</td>
<td class="bank_account_info">
  &lt;?php echo form_input('company_nip',set_value('company_nip'),$company_nip); ?&gt;
</td>
</tr>
</table>


<br /><br /><br />
<legend class="leg">Formularz - złóż zamówienie</legend>
<table class="question_form" id="question_form_text">
<tr class="question_form">
<td class="question_form-01">
  Imię i nazwisko:
</td>
<td class="question_form-02">
  &lt;?php echo form_input('username',set_value('username'),$username); ?&gt;
</td>
</tr>
<tr class="question_form">
<td class="question_form-01">
  Prosimy podać email:
</td>
<td class="question_form-02">
  &lt;?php echo form_input('email',set_value('email'),$email); ?&gt;
</td>
</tr>
<tr class="question_form">
<td class="question_form-01">
  Temat wiadomości:
</td>
<td class="question_form-02">
  &lt;?php echo form_input('subject',set_value('subject'),$subject); ?&gt;
</td>
</tr>
<tr class="question_form">
<td class="question_form-01">
  Treść wiadomość:
</td>
<td class="question_form-02">
  &lt;?php echo form_textarea('message',set_value('message'),$message); ?&gt;
</td>
</tr>
<tr class="question_form">
<td class="question_form-01">
  &lt;?php echo form_submit('submit','Wyślij','class="question_form_submit"'); ?&gt;

</td>
<td class="question_form-02">
  
</td>
</tr>

</table>
</fieldset>

</div>
&lt;?php echo form_close(); ?&gt;
#2

[eluser]aquary[/eluser]
Code:
$this->form_validation->set_rules('company_nip', 'company_nip', 'required|valid_email()');

the valid_email() part made me popout a question mark. I think the form_validation return false by that ?
#3

[eluser]nahalem[/eluser]
While I'm mouse overing submit button browser display url to the form view of the project, should display url to the controller and function... When button is pressed sendEmail function doesn't run. Thx for solve validation problem but it's not resolve my real problem.
#4

[eluser]aquary[/eluser]
There was too many unknown factor here. My answer to yours before was because I doesn't have the full code, so I couldn't know what was indexMain() doing. I have to guess it was for loading the form itself. The worst thing is you said "the form goes to the view after submit", which was doesn't make sense since views need controller/method It cannot be shown directly :\

ARE you sure it was not run? Please define your meaning of NOT RUNNING. WHAT was the URL you saw on the browser URL after submitting the form? Did it change? Did it just stay there? Etc.
#5

[eluser]nahalem[/eluser]
I'm sure function is not running, Ill checked using echo and break. IndexMain() is a function inside controller to keep all pages.
#6

[eluser]nahalem[/eluser]
Guys I really need help, can't resolve problem:

function in the controller running view with form:

Code:
public function contactPage()
{

  $this->load->model('categories_model');
  $data['cat'] = $this->categories_model->retrieveActiveCategories();
  $data['content_cat'] = 'static/menu_categories';
  
  $this->load->model('adverts_model');
  $data['adverts_type'] = $this->adverts_model->retrieveAdvertsTypesList();
  
  $data['content'] = 'static/orders_form';
  $this->load->view('polimax',$data);
  
}

Controller constructor:

Code:
public function __construct()
    {
        parent::__construct();
        
  /* loading helpers */
        $this->load->helper('url');
  $this->load->helper('html');
  $this->load->helper('form');
  $this->load->helper('asset');
  $this->load->library('ajax');
        $this->load->library('pagination');//JW
  $this->load->library('form_validation');
  $this->load->database();
  
  
                /* variables initializations */
                $this->data = null;
  $this->contacts = null;
  /* set constrains values */
  $this->data = array
  (
   'title'  => ucfirst('title')
  );
  /* load header view */
  $this->load->view('static/header',$this->data);  
    }

view with form is already in this post. If I create second form second then submit button has right url to the controller function... No idea whats going on. Ill try to create new project, but it's the same think happend....

pls for help.

When I mouse over the submit button i have redirection url like:

.../polimax/contactPage

should be
.../polimax/sendEmail





Theme © iAndrew 2016 - Forum software by © MyBB