Data uit PHP formulier kopieren naar een ander formulier

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Sebas V

Sebas V

09/08/2012 09:31:04
Quote Anchor link
Goedemorgen,

Ik ben opzoek naar de mogelijkheid om data die ingevoerd wordt in het contactformulier te kopiëren naar een PHP formulier op een andere pagina.

Zover werkt het onderstaande formulier dat de gegevens opgeslagen worden in een database en via de mail verstuurd worden. Echter wil ik deze functie uitbreiden dat de data ook terecht komt in een PHP formulier op een andere pagina.

Alle hulp wordt zeer gewaardeerd :)

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<form id="ContactForm" action="">
<tr>
<td align="right" style="padding-right:25px;" width="140px">&nbsp;</td><td><font size="-2">* Gelieve alle velden in te vullen.</font></td>
</tr>
<tr>
<td align="right" style="padding-right:25px;" width="140px">Contactpersoon<font size="-2" style="vertical-align:top;">*</font></td><td><input id="contactpersoon" name="contactpersoon" class="inplaceError" maxlength="120" type="text" class="error" autocomplete="off" onFocus="window.scrollTo(0, 0);"/><span class="error" style="display:none; margin-left:6px;"></span></td>
</tr>
<tr>
<td align="right" style="padding-right:25px;" width="140px">Bedrijfsnaam<font size="-2" style="vertical-align:top;">*</font></td><td><input id="bedrijfsnaam" name="bedrijfsnaam" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/><span class="error" style="display:none; margin-left:6px;"></span></td>
</tr>
<tr>
<td align="right" style="padding-right:25px;" width="140px">E-mail<font size="-2" style="vertical-align:top;">*</font></td><td><input id="email" name="email" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/><span class="error" style="display:none; margin-left:6px;"></span></td>
</tr>
<tr>
<td align="right" style="padding-right:25px;" width="140px">Telefoonnummer<font size="-2" style="vertical-align:top;">*</font></td><td><input id="telefoon" name="telefoon" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/><span class="error" style="display:none; margin-left:6px;"></span></td>
</tr>
<tr>
<td align="right" style="padding-right:25px;" width="140px">&nbsp;</td><td><input class="button_verzenden black" id="send" type="button" value="START"/><input id="newcontact" name="newcontact" type="hidden" value="1"></input></td>
</tr>
</form>


Graag in het vervolg bij code, [code] [/code] tags gebruiken.[/modedit]
Gewijzigd op 22/08/2012 14:51:46 door Bas IJzelendoorn
 
PHP hulp

PHP hulp

25/04/2024 12:35:53
 
Chris PHP

Chris PHP

09/08/2012 09:32:53
Quote Anchor link
Dan vul je bij action="" gewoon je script in die zowel het verzenden als de insert in je database verwerkt.

Bijvoorbeeld action="verwerk.php".

Dan verzend je de mail in verwerk.php, en ook maak je daar de insert in je database met de zelfde gegevens uit $_POST.

Toevoeging op 09/08/2012 09:39:41:

En waarom heb je inline css voor je tabel?

Je kunt ook gewoon dit in je css sheet zetten

td {
align: left;
padding-right: 25px;
width: 140px;
}

Wil je het dan ooit anders hebben hoef je maar 1 stukje aan te passen ipv elke regel.
 
Sebas V

Sebas V

09/08/2012 09:44:11
Quote Anchor link
Thanks voor de tip, de inline css was even een opschoon klus..

Over de action functie gesproken, ik heb nu een contact.php waarin alle gegevens staan om de e-mail te versturen. Echter om de data toe te voegen in de database heb ik een db.php bestand (zie hieronder).

Kan ik niet hierin aangeven dat de data ook naar een fomulier moet op een andere pagina?

Quote:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once("config.php"); /* Configuration File */

class DB{
    
    private $link;
    
    public function __construct(){
        $this->link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
        if (mysqli_connect_errno())
            exit();
    }

    
    public function __destruct() {
        mysqli_close($this->link);
    }

    
    public function dbNewMessage($contactpersoon,$bedrijfsnaam,$email,$telefoon){
        $contactpersoon        = mysqli_real_escape_string($this->link,$contactpersoon);
        $bedrijfsnaam         = mysqli_real_escape_string($this->link,$bedrijfsnaam);
        $email                  = mysqli_real_escape_string($this->link,$email);        
        $telefoon             = mysqli_real_escape_string($this->link,$telefoon);        
        
        mysqli_autocommit($this->link,FALSE);
        
        $query = "INSERT INTO aanmeldingen_formulier(pk_contact,contactpersoon,bedrijfsnaam,email,telefoon)
                  VALUES('NULL','$contactpersoon','$bedrijfsnaam','$email','$telefoon')"
;
        mysqli_query($this->link,$query);
        
        if(mysqli_errno($this->link))
            return -1;
        else{
            mysqli_commit($this->link);
            return 1;
        }
    }  
};

?>
 
Chris PHP

Chris PHP

09/08/2012 09:55:49
Quote Anchor link
Waar komen de variabelen vandaan? Zoals $telefoon, $email, etc?

Tevens raad ik het ook aan om je variabelen te escapen in je query op deze manier

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
"VALUES('NULL','".$contactpersoon."','".$bedrijfsnaam."','".$email."','".$telefoon."')";
?>


Je kunt dit hele stuk gewoon in je contact.php zetten, en het daar ook verwerken. Of het php gedeelte van contact.php in je db.php zetten.
Gewijzigd op 09/08/2012 09:56:49 door Chris PHP
 
Sebas V

Sebas V

09/08/2012 10:03:02
Quote Anchor link
Hieronder staat contact.php waaruit de variabelen komen.

Quote:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
require_once("db.php");                    /* Database Class */
require_once('utils/is_email.php');        /* Email Validation Script */

/* Handle Ajax Request */

if(isset($_POST['newcontact'])){
    $contact = new Contact();
    unset($contact);
}

else{
    header('Location: /');
}


/* Class Contact */
class Contact{
    
    private $db;                         /* the database obj */
    
    private $errors         = array();  /* holds error messages */
    private $num_errors;                   /* number of errors in submitted form */
    
    public function __construct(){
        $this->db = new DB();
        if(isset($_POST['newcontact']))
            $this->processNewMessage();
        else
            header("Location: /");
    }


    public function processNewMessage(){
        
        $contactpersoon        = $_POST['contactpersoon'];        
        $bedrijfsnaam        = $_POST['bedrijfsnaam'];
        $telefoon            = $_POST['telefoon'];
        $email                = $_POST['email'];
            
        /* Server Side Data Validation */
        
        /* Contactpersoon Validation */

        if(!$contactpersoon || mb_strlen($contactpersoon = trim($contactpersoon)) == 0)
            $this->setError('contactpersoon', 'Vul uw contactpersoon in');
        else if(mb_strlen(trim($contactpersoon)) > 120)
            $this->setError('contactpersoon', 'Te lang! 120 karakters max.');
                
        /* Bedrijfsnaam Validation */
            if(!$bedrijfsnaam || mb_strlen($bedrijfsnaam = trim($bedrijfsnaam)) == 0)
            $this->setError('bedrijfsnaam', 'Vul uw bedrijfsnaam in');
        else if(mb_strlen(trim($bedrijfsnaam)) > 120)
            $this->setError('bedrijfsnaam', 'Te lang! 120 karakters max.');
            
            /* Telefoon Validation */
            if(!$telefoon || mb_strlen($telefoon = trim($telefoon)) == 0)
            $this->setError('telefoon', 'Vul uw telefoonnummer in');
        else if(mb_strlen(trim($telefoon)) > 120)
            $this->setError('telefoon', 'Te lang! 120 karakters max.');
            
            /* Email Validation */
        if(!$email || mb_strlen($email = trim($email)) == 0)
            $this->setError('email','Vul uw e-mail in');
        else{
            if(!is_email($email))
                $this->setError('email', 'Vul een correct email adres in');
            else if(mb_strlen($email) > 120)
                $this->setError('email', 'Te lang! 120 karakters max.');
        }

    
        /* Errors exist */
        if($this->countErrors() > 0){
            $json = array(
                'result' => -1,
                'errors' => array(
                                array('name' => 'contactpersoon'    ,'value' => $this->error_value('contactpersoon')),
                                array('name' => 'bedrijfsnaam'    ,'value' => $this->error_value('bedrijfsnaam')),
                                array('name' => 'email'        ,'value' => $this->error_value('email')),                                
                                array('name' => 'telefoon'    ,'value' => $this->error_value('telefoon')),
                            )
                );
                
            $encoded = json_encode($json);
            echo $encoded;
            unset($encoded);
        }

        /* No errors, insert in db*/
        else{
            if(($ret = $this->db->dbNewMessage($contactpersoon, $bedrijfsnaam, $email, $telefoon)) > 0){
                $json = array('result'         => 1);
                if(SEND_EMAIL)
                    $this->sendEmail($contactpersoon,$bedrijfsnaam,$email,$telefoon);
            }
    
            else
                $json = array('result'         => -2); /* something went wrong in database insertion  */
            $encoded = json_encode($json);
            echo $encoded;
            unset($encoded);
        }
    }

    
    public function sendEmail($contactpersoon,$bedrijfsnaam,$email,$telefoon){
        /* Just format the email text the way you want ... */
        $message_body    = "<div style=\"font-size:12px; font-weight:normal;\">Hallo,<br><br>"
                                    ."Het volgende persoon heeft zich zojuist aangemeld:</div><br>"
                                    ."<table cellpadding=\"1\" cellspacing=\"1\" width=\"550px\"><tr><td style=\"font-size:12px; color:#000000\">Bedrijfsnaam:</td><td style=\"font-size:12px; color:#000000\">".$bedrijfsnaam."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Contactpersoon:</td><td style=\"font-size:12px; color:#000000\">".$contactpersoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Telefoonnummer:</td><td style=\"font-size:12px; color:#000000\">".$telefoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">E-mail:</td><td style=\"font-size:12px; color:#000000\">".$email."</td></tr></table><br>";
        
            // Geef GELDIGE adressen op
            // Een korte benaming voor jouw website

            $website_naam = 'Aanmelding';
            // Jouw eigen geldige emailadres
            $eigen_emailadres = 'EMAIL ADRES';
            // Een geldig emailadres voor errors
            $error_emailadres = 'EMAIL ADRES';
            // De naam van de verzender
            $naam_verzender = ''.$bedrijfsnaam.'';
            // Het geldige emailadres van de afzender
            $email_verzender = ''.$email.'';
            // Een geldig emailadres of helemaal leeg laten
            $bcc_emailadres = '';
            // HTML mail? True/False
            $html = true;
            
            // De headers samenstellen
            $headers     = 'From: ' . $website_naam . ' <' . $eigen_emailadres . '>' . PHP_EOL;
            $headers    .= 'Reply-To: ' . $naam_verzender . ' <' . $email_verzender . '>' . PHP_EOL;
            $headers    .= 'Return-Path: Mail-Error <' . $error_emailadres . '>' . PHP_EOL;
            $headers    .= ($bcc_emailadres != '') ? 'Bcc: ' . $bcc_emailadres . PHP_EOL : '';
            $headers    .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
            $headers    .= 'X-Priority: Normal' . PHP_EOL;
            $headers    .= ($html) ? 'MIME-Version: 1.0' . PHP_EOL : '';
            $headers    .= ($html) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';

        
            mail(EMAIL_TO,MESSAGE_SUBJECT,$message_body,$headers);
            
    }

    
    public function setError($field, $errmsg){
        $this->errors[$field]     = $errmsg;
        $this->num_errors         = count($this->errors);
    }

    
    public function error_value($field){
        if(array_key_exists($field,$this->errors))
            return $this->errors[$field];
        else
            return '';
    }

    
    public function countErrors(){
        return $this->num_errors;
    }
};

    
?>
 
Chris PHP

Chris PHP

09/08/2012 10:38:13
Quote Anchor link
Dan voeg je hier je db.php stukje aan toe zodat hij ook de insert maakt.
Gewijzigd op 09/08/2012 10:39:13 door Chris PHP
 
Erwin H

Erwin H

09/08/2012 10:43:25
Quote Anchor link
Sebastian Veldman op 09/08/2012 10:03:02:
/* Handle Ajax Request */
if(isset($_POST['newcontact'])){
$contact = new Contact();
unset($contact);
}
else{
header('Location: /');
}

// ... knip ...

$encoded = json_encode($json);
echo $encoded;
unset($encoded);

Begrijp ik hieruit dat je dit via een Ajax request doet? Prima natuurlijk, maar dan kan je niet zomaar even de oplossing die Chris aanbiedt toepassen. En als het zo is had je dat misschien in je eerste post even moeten zeggen....
 
Chris PHP

Chris PHP

09/08/2012 10:51:13
Quote Anchor link
@Erwin,
Goed punt, dat stukje heb ik over het hoofd gezien.

@Sebastian,
Is er een speciale reden dat je een AJAX request gebruikt?
 
Sebas V

Sebas V

09/08/2012 11:21:28
Quote Anchor link
In principe niet,

Dit is een basis script die ik altijd hanteer. Ik gebruik AJAX vanwege het uploaden naar Mysql database, validatie en bevestiging pagina denk ik zo..
 
Chris PHP

Chris PHP

09/08/2012 11:27:50
Quote Anchor link
Ok, ik werk zelf voor dit soort dingen eigenlijk nooit met AJAX maar gewoon puur php/html.
 
Sebas V

Sebas V

09/08/2012 11:45:22
Quote Anchor link
Bedankt voor jullie reactie! :)
 
Chris PHP

Chris PHP

09/08/2012 11:47:02
Quote Anchor link
Geen probleem, is het gelukt?
 
Sebas V

Sebas V

22/08/2012 14:49:35
Quote Anchor link
Hee Chris, het is me nog niet gelukt. Ik heb inmiddels de AJAX methode verlaten, maar ik krijg de data nog steeds niet getransformeerd naar result.php

Ik werk nu met onderstaande bestanden, echter krijg ik de data niet in de tabel van RESULT.PHP. In mijn optiek dien ik met een GET of POST functie te werken toch? Wat dien ik in contact.php aan te maken zodat de gewenste gegevens overgezet worden naar RESULT.PHP? De action en method van QUIZ.PHP lijken mij goed?

QUIZ.PHP
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<table width="675px" cellpadding="0" cellspacing="0">
<form id="ContactForm" action="php/contact.php" method="post">
<tr>
<td class="left_td">Aanhef<font size="-2" style="vertical-align:top;">*</font></td><td><label class="label_aanhef" for="aanhef_1"><input name="aanhef" id="aanhef_1" value="Dhr." type="radio" /> Dhr.</label><label class="label_aanhef" for="aanhef_2"><input name="aanhef" id="aanhef_2" value="Mevr." type="radio" /> Mevr.</label></td>
</tr>
<tr class="rij_contactpersoon">
<td class="left_td">Contactpersoon<font size="-2" style="vertical-align:top;">*</font></td><td><input id="contactpersoon" name="contactpersoon" class="inplaceError" maxlength="120" type="text" class="error" autocomplete="off" onFocus="window.scrollTo(0, 0);"/></td>
</tr>
<tr class="rij_bedrijf">
<td class="left_td">Bedrijfsnaam<font size="-2" style="vertical-align:top;">*</font></td><td><input id="bedrijfsnaam" name="bedrijfsnaam" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/></td>
</tr>
<tr>
<td class="left_td">E-mail<font size="-2" style="vertical-align:top;">*</font></td><td><input id="email" name="email" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/></td>
</tr>
<tr>
<td class="left_td">Telefoonnummer<font size="-2" style="vertical-align:top;">*</font></td><td><input id="telefoon" name="telefoon" class="inplaceError" maxlength="120" type="text" autocomplete="off" onFocus="window.scrollTo(0, 0);"/></td>
</tr>
</table>
<div class="sizer">
<label class="label_radio" for="vraag1_A"><input name="vraag1_antwoorden" id="vraag1_A" value="A. Dat is helaas fout, het goede antwoord is: C) 1 Ohm" type="radio" />A) Geen eis</label>
<label class="label_radio" for="vraag1_B"><input name="vraag1_antwoorden" id="vraag1_B" value="B. Dat is helaas fout, het goede antwoord is: C) 1 Ohm" type="radio" />B) 0,1 Ohm</label>
<label class="label_radio" for="vraag1_C"><input name="vraag1_antwoorden" id="vraag1_C" value="C. Gefeliciteerd dat is het goede antwoord." type="radio" />C) 1 Ohm</label>
<label class="label_radio" for="vraag1_D"><input name="vraag1_antwoorden" id="vraag1_D" value="D. Dat is helaas fout, het goede antwoord is: C) 1 Ohm" type="radio" />D) 10 Ohm</label>
</div>
<div class="sizer">
<label class="label_radio" for="vraag2_A"><input name="vraag2_antwoorden" id="vraag2_A" value="A. Gefeliciteerd dat is het goede antwoord." type="radio" />A) 10 Ohm</label>
<label class="label_radio" for="vraag2_B"><input name="vraag2_antwoorden" id="vraag2_B" value="B. Dat is helaas fout, het goede antwoord is: A) 10 Ohm" type="radio" />B) 1 Ohm</label>
<label class="label_radio" for="vraag2_C"><input name="vraag2_antwoorden" id="vraag2_C" value="C. Dat is helaas fout, het goede antwoord is: A) 10 Ohm" type="radio" />C) 0,1 Ohm</label>
<label class="label_radio" for="vraag2_D"><input name="vraag2_antwoorden" id="vraag2_D" value="D. Dat is helaas fout, het goede antwoord is: A) 10 Ohm" type="radio" />D) Geen eis</label>
</div>
<input type="submit" class="verzenden_image" value="" /><input type="hidden" id="newcontact" name="newcontact" value="1"></input></form>



CONTACT.PHP
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
require_once("db.php");                    /* Database Class */
require_once('utils/is_email.php');        /* Email Validation Script */

if ( $_SERVER[REQUEST_METHOD] == 'POST' ){
    $myVar = new Contact();
}


/* Class Contact */
class Contact{
    
    private $db;                         /* the database obj */
    
    private $errors         = array();  /* holds error messages */
    private $num_errors;                   /* number of errors in submitted form */
    
    public function __construct(){
        $this->db = new DB();
        if(isset($_POST['newcontact']))
            $this->processNewMessage();
        else
            header('Location: ../result.php');
    }


    public function processNewMessage(){
    
        $aanhef                = $_POST['aanhef'];            
        $contactpersoon        = $_POST['contactpersoon'];        
        $bedrijfsnaam        = $_POST['bedrijfsnaam'];
        $telefoon            = $_POST['telefoon'];
        $email                = $_POST['email'];
        $vraag1_antwoorden    = $_POST['vraag1_antwoorden'];
        $vraag2_antwoorden    = $_POST['vraag2_antwoorden'];
        
            
        /* Server Side Data Validation */
        
        /* Aanhef Validation */

        if(!$aanhef || mb_strlen($aanhef = trim($aanhef)) == 0)
            $this->setError('aanhef', 'Selecteer uw aanhef');
        
        /* Contactpersoon Validation */
        if(!$contactpersoon || mb_strlen($contactpersoon = trim($contactpersoon)) == 0)
            $this->setError('contactpersoon', 'Vul uw contactpersoon in');
                
        /* Bedrijfsnaam Validation */
            if(!$bedrijfsnaam || mb_strlen($bedrijfsnaam = trim($bedrijfsnaam)) == 0)
            $this->setError('bedrijfsnaam', 'Vul uw bedrijfsnaam in');
            
            /* Telefoon Validation */
            if(!$telefoon || mb_strlen($telefoon = trim($telefoon)) == 0)
            $this->setError('telefoon', 'Vul uw telefoonnummer in');
            
            /* Vraag 1 Validation */
            if(!$vraag1_antwoorden || mb_strlen($vraag1_antwoorden = trim($vraag1_antwoorden)) == 0)
            $this->setError('vraag1_antwoorden', 'Selecteer uw antwoord');
                
            /* Vraag 2 Validation */
            if(!$vraag2_antwoorden || mb_strlen($vraag2_antwoorden = trim($vraag2_antwoorden)) == 0)
            $this->setError('vraag2_antwoorden', 'Selecteer uw antwoord');
                
            /* Email Validation */
        if(!$email || mb_strlen($email = trim($email)) == 0)
            $this->setError('email','Vul uw e-mail in');
        else{
            if(!is_email($email))
                $this->setError('email', 'Vul een correct email adres in');
        }

    
            /* Errors exist */
        if($this->countErrors() > 0){
            $json = array(
                'result' => -1,
                'errors' => array(
                                array('name' => 'aanhef'    ,'value' => $this->error_value('aanhef')),                
                                array('name' => 'contactpersoon'    ,'value' => $this->error_value('contactpersoon')),
                                array('name' => 'bedrijfsnaam'  ,'value' => $this->error_value('bedrijfsnaam')),
                                array('name' => 'email'     ,'value' => $this->error_value('email')),                              
                                array('name' => 'telefoon'  ,'value' => $this->error_value('telefoon')),
                                array('name' => 'vraag1_antwoorden' ,'value' => $this->error_value('vraag1_antwoorden')),
                                array('name' => 'vraag2_antwoorden' ,'value' => $this->error_value('vraag2_antwoorden')),
                            )
                );

        
            // The code below is an example and was not tested
            echo("<ol>");
            echo("Please correct the following errors:");
            foreach ($json['errors'] as $item) {
                echo("<li>".$item['value']."</li>");
            }

            echo("</ol>");
        }

        /* No errors, insert in db*/
        else{
            if(($ret = $this->db->dbNewMessage($aanhef, $contactpersoon, $bedrijfsnaam, $email, $telefoon, $vraag1_antwoorden, $vraag2_antwoorden)) > 0){
                $json = array('result'         => 1);
                if(SEND_EMAIL)
                    $this->sendEmail($aanhef,$contactpersoon,$bedrijfsnaam,$email,$telefoon,$vraag1_antwoorden,$vraag2_antwoorden);
                    header('Location: ../result.php');
        
            }
  
            else
                $json = array('result'      => -2); /* something went wrong in database insertion  */
            $encoded = json_encode($json);
            echo $encoded;
            unset($encoded);
        }

        
    }

    
    public function sendEmail($aanhef,$contactpersoon,$bedrijfsnaam,$email,$telefoon,$vraag1_antwoorden,$vraag2_antwoorden){
        /* Just format the email text the way you want ... */
        $message_body   = "<div style=\"font-size:12px; font-weight:normal;\">Hallo,<br><br>"
                                    ."Het volgende bedrijf heeft zich zojuist aangemeld:</div><br>"
                                    ."<table cellpadding=\"1\" cellspacing=\"1\" width=\"550px\"><tr><td style=\"font-size:12px; color:#000000\">Bedrijfsnaam:</td><td style=\"font-size:12px; color:#000000\">".$bedrijfsnaam."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Aanhef:</td><td style=\"font-size:12px; color:#000000\">".$aanhef."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Contactpersoon:</td><td style=\"font-size:12px; color:#000000\">".$contactpersoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Telefoonnummer:</td><td style=\"font-size:12px; color:#000000\">".$telefoon."</td></tr><tr><td style=\"font-size:12px; color:#000000\">E-mail:</td><td style=\"font-size:12px; color:#000000\">".$email."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Antwoord vraag 1:</td><td style=\"font-size:12px; color:#000000\">".$vraag1_antwoorden."</td></tr><tr><td style=\"font-size:12px; color:#000000\">Antwoord vraag 2:</td><td style=\"font-size:12px; color:#000000\">".$vraag2_antwoorden."</td></tr></table><br>";
        
            // Geef GELDIGE adressen op
            // Een korte benaming voor jouw website

            $website_naam = 'Aanmelding Quiz';
            // Jouw eigen geldige emailadres
            $eigen_emailadres = 'MAIL';
            // Een geldig emailadres voor errors
            $error_emailadres = 'MAIL';
            // De naam van de verzender
            $naam_verzender = ''.$bedrijfsnaam.'';
            // Het geldige emailadres van de afzender
            $email_verzender = ''.$email.'';
            // Een geldig emailadres of helemaal leeg laten
            $bcc_emailadres = '';
            // HTML mail? True/False
            $html = true;
            
            // De headers samenstellen
            $headers     = 'From: ' . $website_naam . ' <' . $eigen_emailadres . '>' . PHP_EOL;
            $headers    .= 'Reply-To: ' . $naam_verzender . ' <' . $email_verzender . '>' . PHP_EOL;
            $headers    .= 'Return-Path: Mail-Error <' . $error_emailadres . '>' . PHP_EOL;
            $headers    .= ($bcc_emailadres != '') ? 'Bcc: ' . $bcc_emailadres . PHP_EOL : '';
            $headers    .= 'X-Mailer: PHP/' . phpversion() . PHP_EOL;
            $headers    .= 'X-Priority: Normal' . PHP_EOL;
            $headers    .= ($html) ? 'MIME-Version: 1.0' . PHP_EOL : '';
            $headers    .= ($html) ? 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL : '';

        
            mail(EMAIL_TO,MESSAGE_SUBJECT,$message_body,$headers);
            
    }

    
    public function setError($field, $errmsg){
        $this->errors[$field]     = $errmsg;
        $this->num_errors         = count($this->errors);
    }

    
    public function error_value($field){
        if(array_key_exists($field,$this->errors))
            return $this->errors[$field];
        else
            return '';
    }

    
    public function countErrors(){
        return $this->num_errors;
    }
};

?>



RESULT.PHP
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
<table width="650px" cellpadding="0" cellspacing="0">
            <tr class="rij_contactpersoon">
                <td class="left_td">Contactpersoon:</td><td><strong><?php echo $_POST["contactpersoon"]; ?></strong></td><td>&nbsp;</td>
            </tr>
            <tr class="rij_bedrijf">
                <td class="left_td">Bedrijfsnaam:</td><td><strong><?php echo $_POST["bedrijfsnaam"]; ?></strong></td><td>&nbsp;</td>
            </tr>
</table>
Gewijzigd op 22/08/2012 14:52:58 door Sebas V
 
Obelix Idefix

Obelix Idefix

22/08/2012 15:29:44
Quote Anchor link
Is dit niet een vervolg op/vergelijkbaar met http://www.phphulp.nl/php/forum/topic/quiz-probleem/86175/ ?

In contact.php is geen formulier/post je niets. Hoe zou in result.php dan de $_POST waarde beschikbaar kunnen zijn (uit quiz.php?

Nog wat opmerkingen bij je code:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<?php $email_verzender = ''.$email.'';?>

Waarom die ''?

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?php
$message_body
   = "<div style=\"font-size:12px; font-weight:normal;\">Hallo,<br><br>"
?>

Gebruik in PHP ' en in HTML " --> scheelt je escapen.
Zie ook http://www.phphulp.nl/php/tutorial/php-algemeen/correct-quoten/772/
 
Sebas V

Sebas V

22/08/2012 16:19:08
Quote Anchor link
Bedankt voor de opmerkingen, ik zal ze doorvoeren.

Heb je een voorbeeld hoe een tabel geïntegreerd zou kunnen worden in contact.php zodat deze uitgelezen kan worden op result.php?

Dien ik met een echo te werken?
 
Obelix Idefix

Obelix Idefix

22/08/2012 16:29:23
Quote Anchor link
Sebastian V op 22/08/2012 16:19:08:
een tabel geïntegreerd zou kunnen worden in contact.php zodat deze uitgelezen kan worden op result.php?


Een tabel integreren???? Geen idee wat je daarmee bedoelt.

Je kunt de variabelen in je header meegeven, zodat ze op result met een $_GET kunnen worden uitgelezen. Of je zet ze in een SESSION.
 
Sebas V

Sebas V

22/08/2012 16:53:46
Quote Anchor link
Oke ik heb nu het volgende, wat mis ik hierin nog?

De variabelen staan in de header van en de $_GET staan in de tabel op RESULT.PHP


CONTACT.PHP (IN DIT GEDEELTE WORDT AANGEGEVEN WAT TE DOEN NA DE SUBMIT)
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* No errors, insert in db*/
else{
if(($ret = $this->db->dbNewMessage($aanhef, $contactpersoon, $bedrijfsnaam, $email, $telefoon, $vraag1_antwoorden, $vraag2_antwoorden)) > 0){
$json = array('result'         => 1);
if(SEND_EMAIL)
                    $this->sendEmail($aanhef,$contactpersoon,$bedrijfsnaam,$email,$telefoon,$vraag1_antwoorden,$vraag2_antwoorden);
header('Location: ../result.php');
        
}  
else
$json = array('result'      => -2); /* something went wrong in database insertion  */
$encoded = json_encode($json);
echo $encoded;
unset($encoded);
}



RESULT.PHP
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<head>
<meta charset="UTF-8" />
<title>Quiz</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=0;">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,900' rel='stylesheet' type='text/css'>        
<link rel="stylesheet" type="text/css" href="css/print.css" />

<?php
$contactpersoon
        = $_POST['contactpersoon'];            
$bedrijfsnaam        = $_POST['bedrijfsnaam'];          
?>

</head>
<body>
<table width="650px" cellpadding="0" cellspacing="0">
<tr class="rij_contactpersoon">
<td class="left_td">Contactpersoon:</td><td><strong><?php echo $_GET["contactpersoon"]; ?></strong></td><td>&nbsp;</td>
</tr>
<tr class="rij_bedrijf">
<td class="left_td">Bedrijfsnaam:</td><td><strong><?php echo $_GET["bedrijfsnaam"]; ?></strong></td><td>&nbsp;</td>
</tr>
</table>
Gewijzigd op 22/08/2012 16:54:28 door Sebas V
 
Obelix Idefix

Obelix Idefix

22/08/2012 17:19:35
Quote Anchor link
Zet error-reporting eens aan in je bestanden; in result zul je sowieso meldingen krijgen.

In je header in contact zie ik geen variabelen meegegeven worden.
wat is het nut/de bedoeling in result van regel 9 en 10?

Waarom drie bestanden? Maak het jezelf makkelijk(er) en copy/paste het result bestand in contact i.p.v. de header.

Kijk verder eens naar een basistut over formulieren.
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.