• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form not submitting data

#1
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
Reply

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

Code:
<input type="text" name="fname">
https://www.w3schools.com/tags/tag_input.asp
"Make it idiot proof and someone will make a better idiot."
Reply

#3
@majortom84,

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

Any reason why?
Reply

#4
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)
Reply

#5
(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.
Reply

#6
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

Reply

#7
(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.
Reply

#8
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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