Contact formulier in CodeIgniter

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • SpaceK33z
  • Registratie: Mei 2009
  • Laatst online: 03-06 19:14

SpaceK33z

Webdeveloper

Topicstarter
Ik ben bezig met het maken van een contactformulier in CodeIgniter, maar dat wil helaas niet lukken.
Ik krijg deze error, die mij niks zegt:
Fatal error: Can't use method return value in write context in ***/ci/application/controllers/contact.php on line 18

In de controller Contact heb ik dit staan:
PHP:
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

class Contact extends Controller {

    function __construct() // Werkt alleen in PHP5!
    {
        parent::Controller();
        $this->load->helper('form');
        $this->load->helper('email');
        $this->load->library('email');
    }
    
    function index()
    {
        $header_data['titel'] = "Neem contact op"; // Defineer de titel
        $this->load->view('header', $header_data); // Roep de header en titel van de pagina op
        
        if(!empty($this->input->post('submit'))) // Hier zit 't probleem
        {
            $name = (string)$this->input->post('name', TRUE);
            $email = (string)$this->input->post('email', TRUE);
            $subject = (string)$this->input->post('subject', TRUE);
            $message = (string)$this->input->post('message', TRUE);

            if(empty($name) OR empty($email) OR empty($subject) OR empty($message))
            {
                show_error("U hebt niet alles ingevuld.");
            }

            if(!valid_email($email))
            {
                show_error("U heeft een ongeldig e-mail adres ingevuld.");
            }

            $config['protocol'] = 'sendmail';
            $this->email->initialize($config);

            $this->email->from($email, $name);
            $this->email->to('e-mailadres@mail.nl');

            $this->email->subject($subject);
            $this->email->message($message);

            $this->email->send();

            $this->load->view('contact_succes');
        }
        else
        {
            $this->load->view('contact_form');
        }

        $this->load->view('footer'); // Roep het einde van de pagina op
    }
}

/* End of file contact.php */
/* Location: ./application/controllers/contact.php */


In de contact_form view staat dit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<div id="content">
                
    <?php echo form_open('contact'); ?>
            Full Name<br />
            <input type="text" name="name" /><br />
            Email<br />
            <input type="text" name="email" /><br />
            Subject<br />
            <input type="text" name="subject" /><br />
            Message<br />
            <textarea rows="10" cols="60" name="message">
            <input type="submit" name="submit" value="Email me" />
            <br /><br />
    <?php echo form_close(); ?>

                
</div><!-- Einde content -->


Weet iemand wat ik fout doe?

Acties:
  • 0 Henk 'm!

  • Sebazzz
  • Registratie: September 2006
  • Laatst online: 16-09 15:42

Sebazzz

3dp

empty() kan je volgens mij alleen op variabelen gebruiken omdat het een language construct is.

[Te koop: 3D printers] [Website] Agile tools: [Return: retrospectives] [Pokertime: planning poker]


Acties:
  • 0 Henk 'm!

  • mithras
  • Registratie: Maart 2003
  • Niet online
Klopt wat Sebazzz zegt. Je kan in de language costruct niet een return waarde opvangen (beetje onhandig eigenlijk, maar goed).

Je zou volgens mij wel iets kunnen doen als dit (uit mijn hoofd):
PHP:
1
2
if (!empty($submit = $this->input->post('submit'))) {
}

Acties:
  • 0 Henk 'm!

  • SpaceK33z
  • Registratie: Mei 2009
  • Laatst online: 03-06 19:14

SpaceK33z

Webdeveloper

Topicstarter
Dankjewel :). Dat laatste ging niet helemaal goed maar ik heb voor de if() de variable $submit gedifineerd, en nou doet 'ie het.

Acties:
  • 0 Henk 'm!

  • Brakkie
  • Registratie: Maart 2001
  • Niet online

Brakkie

blaat

Error copy paste in google, 1e hit :p

Systeem | Strava


  • NMe
  • Registratie: Februari 2004
  • Laatst online: 09-09 13:58

NMe

Quia Ego Sic Dico.

mithras schreef op woensdag 11 november 2009 @ 18:00:
Klopt wat Sebazzz zegt. Je kan in de language costruct niet een return waarde opvangen (beetje onhandig eigenlijk, maar goed).
Zó onlogisch is het niet; empty is gemaakt om te kunnen bepalen of een variabele leeg is, net als isset. Je kan ook moeilijk checken of een variabele niet geset is als die überhaupt niet naar een variabele verwijst. ;)

'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.

Pagina: 1