Welcome Guest, Not a member yet? Register   Sign In
puzzling error msg in form validation controller
#1

[eluser]oldnews[/eluser]
I'm making use of the standardized controllers/form.php and views/myform.php routines. Having renamed 'username' to 'entrant' to 'contestant' to 'who', the problem nevertheless returns when the completed form apparently passes form validation, always on the same line #37 ($this->email->contestant('$who')): Fatal error: Call to undefined method CI_Email::entrant() in controllers/form.php

Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
                
        $this->form_validation->set_rules('who', 'your name', 'required');
        $this->form_validation->set_rules('mainphone', 'primary phone', 'required');
        $this->form_validation->set_rules('email', 'email address', 'required|valid_email');
        $this->form_validation->set_rules('extraphone', 'additional phone');
        $this->form_validation->set_rules('address', 'mailing address', 'required');
        $this->form_validation->set_rules('altphone', 'alternative phone');
        $this->form_validation->set_rules('city', 'municipality', 'required');
        $this->form_validation->set_rules('zip', 'zip code', 'required');
        $this->form_validation->set_rules('description', 'describe photo', 'required');
        $this->form_validation->set_rules('location', 'photo location', 'required');
        $this->form_validation->set_rules('ageutresidency', 'certification checkbox', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('header2');
            $this->load->view('myform');
            $this->load->view('footer2');
        }
        else
        {

            $this->load->library('email');

            $this->email->subject('Best Summer Vacation Picture contest entry');
            $this->email->to('[email protected]');
            $this->email->from('$email');
            $this->email->contestant('$who');
            $this->email->address('$address');
            $this->email->city('$city');
            $this->email->zip('$zip');
            $this->email->description('$description');
            $this->email->location('$location');
            $this->email->phone1('$mainphone');
            $this->email->phone2('$extraphone');
            $this->email->phone3('$altphone');
            $this->email->certification('$ageutresidency');

            $this->email->attach('uploads/$photofile');

            $this->email->send();

            echo $this->email->print_debugger();

            if ( ! $this->email->send())
            {
                // Generate error
            }
            else
            {
                $this->load->view('header2');
                $this->load->view('formsuccess');
                $this->load->view('footer2');
            }
        }
    }
}
?>

Everytime I've renamed the variable in the controllers/form.php I match the associated name change in the views/form.php

Am I dealing with a sendmail configuration issue and getting a false reference to the code in Line 37? I cannot figure this one out.
#2

[eluser]Dam1an[/eluser]
Emmm... what are you trying to acheive?
You seem to be creating function referneces on the fly to the email library, so they obviously don't exist.

I think what you probably want to do is have all tat information as a string in the body?
#3

[eluser]TheFuzzy0ne[/eluser]
Try using double quotes instead of single quotes. Your variables are not being parsed. In fact, some of those don't even need quotes at all:

Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('who', 'your name', 'required');
        $this->form_validation->set_rules('mainphone', 'primary phone', 'required');
        $this->form_validation->set_rules('email', 'email address', 'required|valid_email');
        $this->form_validation->set_rules('extraphone', 'additional phone');
        $this->form_validation->set_rules('address', 'mailing address', 'required');
        $this->form_validation->set_rules('altphone', 'alternative phone');
        $this->form_validation->set_rules('city', 'municipality', 'required');
        $this->form_validation->set_rules('zip', 'zip code', 'required');
        $this->form_validation->set_rules('description', 'describe photo', 'required');
        $this->form_validation->set_rules('location', 'photo location', 'required');
        $this->form_validation->set_rules('ageutresidency', 'certification checkbox', 'required');

        if ($this->form_validation->run())
        {
            $this->load->library('email');

            $this->email->subject('Best Summer Vacation Picture contest entry');
            $this->email->to('[email protected]');
            $this->email->from($email);
            $this->email->contestant($who);
            $this->email->address($address);
            $this->email->city($city);
            $this->email->zip($zip);
            $this->email->description($description);
            $this->email->location($location);
            $this->email->phone1($mainphone);
            $this->email->phone2($extraphone);
            $this->email->phone3($altphone);
            $this->email->certification($ageutresidency);
            $this->email->attach("uploads/$photofile");
            
            $this->email->send();
            
            echo $this->email->print_debugger();
            
            if ( ! $this->email->send())
            {
                // Generate error
            }
        }
        
        $this->load->view('header2');
        $this->load->view('formsuccess');
        $this->load->view('footer2');
    }
}

// End of file: form.php
// Location: ./system/application/controllers/form.php

It's also good practice to omit the closing PHP tag, and replace it with something like the above.
#4

[eluser]oldnews[/eluser]
I am attempting to assemble 10 required and 2 optional data fields from a contestant entry form and trying to attach a previously uploaded photo to an email that will be submitted to the contest sponsor. As far as I can tell, I am only calling the two recommended libraries from the CI User Guide's boilerplated tandem (controllers/form.php and views/myform.php. These summoned libraries in my code above are form_validation and email in order to complete the process.
#5

[eluser]n0xie[/eluser]
It errors on:
Code:
$this->email->contestant(’$who’))
because 'contestant' is not a method of the library email. You randomly call functions of a library that don't exist. Obviously it's going to error.
#6

[eluser]TheFuzzy0ne[/eluser]
lol, I assumed he'd overridden the library. I was going to mention, but I thought, "Nah, stupid question." That'll teach me Tongue
#7

[eluser]Dam1an[/eluser]
yay, everyone finally caught onto what I said 15 minutes ago Tongue
#8

[eluser]TheFuzzy0ne[/eluser]
I make that 20 minutes. Tongue You must type like my Granddad.
#9

[eluser]oldnews[/eluser]
Thanks to all. I appreciate the abundant feedback and try, to my abilities, to absorb and to learn as a newbie from all. Have been doing HTML and JavaScript for 15 years, but PHP is new to me. And this CI framework in particular. Here's how I have cleaned up the mess, however, I'm now stuck with a line 38 (the very lengthy message segment) error: Parse error: syntax, unexpected T_CONSTANT_ENCAPSED_STRING for the controller/form.php. I've tried both single and double quotes and both yield the same error msg.
Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('form_validation');
                
        $this->form_validation->set_rules('who', 'your name', 'required');
        $this->form_validation->set_rules('mainphone', 'primary phone', 'required');
        $this->form_validation->set_rules('email', 'email address', 'required|valid_email');
        $this->form_validation->set_rules('extraphone', 'additional phone');
        $this->form_validation->set_rules('address', 'mailing address', 'required');
        $this->form_validation->set_rules('altphone', 'alternative phone');
        $this->form_validation->set_rules('city', 'municipality', 'required');
        $this->form_validation->set_rules('zip', 'zip code', 'required');
        $this->form_validation->set_rules('description', 'describe photo', 'required');
        $this->form_validation->set_rules('location', 'photo location', 'required');
        $this->form_validation->set_rules('ageutresidency', 'certification checkbox', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('header2');
            $this->load->view('myform');
            $this->load->view('footer2');
        }
        else
        {

            $this->load->library('email');

            $this->email->subject("Best Summer Vacation Picture contest entry");
            $this->email->email_from($email, $who);
            $this->email->reply_to($email, $who);
            $this->email->to("[email protected]");
            $this->email->message($address', '$city', UT '$zip', photo description: '$description', location: '$location', primary phone: '$mainphone', optional secondary phone: '$extraphone', optional tertiary phone: '$altphone', certification of minimum age of 18 and UT residency: '$ageutresidency);

//            $this->email->attach("/uploads/"$photofile);

            $this->email->send();

            echo $this->email->print_debugger();

            if ( ! $this->email->send())
            {
                // Generate error
            }
            else
            {
                $this->load->view('header2');
                $this->load->view('formsuccess');
                $this->load->view('footer2');
            }
        }
    }
}

// End of file: form.php
// Location: ./system/application/controllers/form.php

Obviously, I have commented out the TBA image attachment (previously downloaded), hoping to simply witness a successfully dispatched text email. Prpject on deadline, appreciate this community's intelligent support.

UploadPixMaverik.com
#10

[eluser]oldnews[/eluser]
core problematic line #38, with enforced line breaks:
Code:
$this->email->message($address', '$city', UT '$zip', photo description: '$description
', location: '$location', primary phone: '$mainphone', optional secondary phone: '$extraphone
', optional tertiary phone: '$altphone', certification of minimum age of 18 and UT residency:
'$ageutresidency);




Theme © iAndrew 2016 - Forum software by © MyBB