CodeIgniter Forums
Form not submitting data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Form not submitting data (/showthread.php?tid=71619)



Form not submitting data - majortom84 - 09-05-2018

I have this working in another Controller so I am not sure why it is not working in this one.

Controller:
Code:
public function contact(){

        if( empty( $this->input->post() ) ){
            $this->data['title'] .= ' - Contact';
            
            $this->load->view('templates-portfolio/header', $this->data);
            $this->load->view('portfolio/contact');
            $this->load->view('templates-portfolio/footer');
        }
        else{
            var_dump( $this->input->post() ); die();
        }
        
    } // end function contact

View:
Code:
<div class="container-contact">
            <?php echo form_open('portfolio/contact'); ?> <!-- the action is the controller media and the function process -->
    
            <div class="grid-container">
                <div class="grid-x grid-padding-x">
                    
                    <div class="large-12 cell">
                        <label>
                            Hello, Tell me a bit about yourself.
                            <textarea autofocus placeholder="" rows="5"></textarea>
                        </label>
                    </div>
                    
                    <div class="medium-6 large-6 cell">
                        <label>Name
                            <input type="text" placeholder="Name">
                        </label>
                    </div>
    
                    <div class="medium-6 large-6 cell">
                        <label>Email
                            <input type="email" placeholder="Email">
                        </label>
                    </div>
                    
                    <button type="submit" class="hollow button submit">Submit</button>
                    
                </div>
            </div>
    
            <?php echo form_close(); ?>

Testing in postman works, just not seeing anything in CI on backend


RE: Form not submitting data - kierownik - 09-05-2018

should your inputs and textarea's not have name's?

Code:
<input type="text" name="fname">
https://www.w3schools.com/tags/tag_input.asp


RE: Form not submitting data - php_rocs - 09-05-2018

@majortom84,

Interesting, you are using...
if( empty( $this->input->post() ) )
instead of...
if ($this->form_validation->run() == FALSE)

Any reason why?


RE: Form not submitting data - neuron - 09-05-2018

as I remember  empty() function does not accept return values;
so U can't run if(empty($this->input->post())) instead I just use  if($this->input->post() == null)


RE: Form not submitting data - neuron - 09-05-2018

(09-05-2018, 04:23 PM)php_rocs Wrote: @majortom84,

Interesting, you are using...  
if( empty( $this->input->post() ) )
instead of...
if ($this->form_validation->run() == FALSE)

Any reason why?


assume that u need to show alert when validation failed
and you submit your form to the same url where you view the form (which is common way in CI):
PHP Code:
public function foo()

    {
 
           if($this->form_validation->run()){
 
           }else{
//set alert
 
               $this->postal->add('failed to validate!''error');
 
           }

then every time you open link you will see error alert because u did not submit anything. That's why you need first check if something posted or not.


RE: Form not submitting data - Wouter60 - 09-06-2018

Like kierownik said: $_POST (or $this->input->post()) will only have values if the inputs have names.
Best practice is to give the submit button a name also:
PHP Code:
<button type="submit" name="submit" class="hollow button submit">Submit</button

Then, in your controller:
PHP Code:
if ($this->input->post('submit')) {
 
  // handle form input
}
else {
 
  // show form




RE: Form not submitting data - majortom84 - 09-06-2018

(09-05-2018, 04:22 PM)kierownik Wrote: should your inputs and textarea's not have name's?

Code:
<input type="text" name="fname">
https://www.w3schools.com/tags/tag_input.asp

This was it, found it about 10 min after I posted this. Would have added to post but my son needed my attention.


RE: Form not submitting data - InsiteFX - 09-06-2018

Using JavaScript and with forms you should always give the input elements a name,
if you use the class along with name give them both the same name.

Will give you piece of mind.