Welcome Guest, Not a member yet? Register   Sign In
submit button not redirecting
#1



I'm trying to make a simple codeigniter signup form, but when I press the submit button nothing happens. Not sure what is going wrong. please help. I've posted both my view file and the contoller which i am re-directing in the form.




Code:
<div id="newsletter_form">
   Sign up to our newsletter

   <?php
   echo form_open('email/send');
   ?>

   <?php

   $name_data= array('name'=>'name',
       'id'=>'name',
       'value'=> set_value('name')


   );

   ?>
   <p> <label for=" name"> Name :</label> <?php echo form_input($name_data); ?> </p>  <!--form_input acts like input tag-->

   <p> <label for=" email"> email address:</label>
       <input type="email" name="email" id="email" value="<?php echo set_value('email') ?>" required/> </p>

   <p> <?php echo form_submit('submit','submit');?></p>

   <?php echo form_close(); ?>
</div>



And the below one is my email.php file

Code:
<?php

class email extends CI_Controller
{
   function _construct()
   {
       parent::__construct();
   }

   function index()
   {
       $this->load->view('newsletter_view');
   }


   function send()
   {
       echo "hello";
       $this->load->library('email');
       $this->email->set_newline("\r\n");

       $this->email->from('[email protected]', 'pallavi');
       $this->email->to('[email protected]');
       $this->email->subject('attachment');
       $this->email->message('hello gpks');

       $path = $this->config->item('server_root');  //server_root is set to document root in config.php
       //echo $path; //to make sure path is set to doc root

       $file = $path . '/CI/attachment/hello.txt';

       $this->email->attach($file);
       if ($this->email->send()) {
           echo "your mail was sent";
       } else {
           show_error($this->email->print_debugger());
       }
Reply
#2

Well, given what you've posted here:

- The controller's class and file name should start with an uppercase letter "Email" and "Email.php"
- The constructor should be:

PHP Code:
public function __construct()
{
    
parent::__construct();


(note that it starts with two underscores (__), not one.

- You shouldn't echo from your controller, especially right at the beginning of your send() method, since this may prevent some or all of the code after the echo from executing properly and will eventually cause errors if you try to load a view.
- I'm assuming you just stopped copying the code at whatever point you thought was relevant, as you don't have closing braces for either the send() method or the class.
Reply
#3

hi,

I did try the constructor, but it doesnt work,if i run email.php the the view gets loaded but the submit isnt redirected.  
The send function also works when i run separately. 
But the form submit doesnt work. (it doesnt redirect to the send function)
Reply
#4

I have tried the constructor part. but it didnt work either.

In my file email.php the view gets loaded but the submit doesnt redirected to send method in contoller. Also the send method works fine separately.
Reply
#5

PHP Code:
class email extends CI_Controller
//should be
class Email extends CI_Controller    // save as: ../application/controllers/Email.php 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

You probably need to use a different name for your controller. When you load the Email library from an Email controller, it's probably not going to work out very well.
Reply
#7

Tried with both Email and a different name. 

But nothing changed Confused Sad
Reply
#8

Could you post your complete code for Controller and view files.
Reply
#9

I have attached both the files.

Attached Files
.php   newsletter_view.php (Size: 936 bytes / Downloads: 95)
.php   Blog.php (Size: 1,011 bytes / Downloads: 92)
Reply
#10

(This post was last modified: 11-12-2015, 01:10 AM by pdthinh.)

(11-11-2015, 09:02 PM)[email protected] Wrote: I have attached both the files.

In your view file modify this line:
PHP Code:
   echo form_open("blog/send"); // blog starts with lower case letter 

In the controller you can use simplified send() method to test if the view can submit to it:
PHP Code:
   function send()
 
   {
 
         var_dump($this->input->post('email'));
 
   
Reply




Theme © iAndrew 2016 - Forum software by © MyBB