Chris PHP
28-08-2012 12:22
gewijzigd op 28-08-2012 12:24
Wat doet hij als je dit doet?
<?php
if(isset($aanhef) || $aanhef == ''){
$this->setError['aanhef' => 'Vul uw aanhef in'];
}
?>
Link gekopieerd
@Erwin: Dat is idd mijn oude opzet
Link gekopieerd
1) En waar declareer je setError dan als een array in je object?
2) Gebruik je php 5.4?
Link gekopieerd
@Chris: Hee Chris, ik krijg nu 2 syntax errors op beide regels code.
Link gekopieerd
@Erwin: Bovenaan declareer ik deze.
<?php
require_once("php/db.php"); /* Database Class */
require_once('php/utils/is_email.php'); /* Email Validation Script */
if(isset($_POST['newcontact'])){
$contact = new Contact();
//We'll refer to that later on, to display errors.
//unset($contact);
}
else{
//header('Location: result.php');
}
/* Class Contact */
class Contact{
private $db; /* the database obj */
//private $errors = array(); /* holds error messages */
//we have to init $errors array, as otherwise form will produce errors on missing array entry
private $errors = array( /* holds error messages */
'aanhef' => '',
'bedrijfsnaam' => '',
'email' => '',
'telefoon' => '',
'vraag1_antwoorden' => '',
'vraag2_antwoorden' => ''
);
private $num_errors; /* number of errors in submitted form */
public function __construct(){
$this->db = new DB();
if(isset($_POST['newcontact']))
$this->processNewMessage();
/* We don't need this anymore
*
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 */
if(!$aanhef || mb_strlen($aanhef = trim($aanhef)) == '') {
$this->setError('aanhef', 'Vul uw aanhef in' );
}
if(!$contactpersoon || mb_strlen($contactpersoon = trim($contactpersoon)) == '') {
$this->setError('contactpersoon', 'Vul uw contactpersoon in');
} else if (mb_strlen(trim($contactpersoon)) > 120) {
$this->setError('contactpersoon', 'Te lang! 120 karakters max.'); }
if(!$bedrijfsnaam || mb_strlen($bedrijfsnaam = trim($bedrijfsnaam)) == '') {
$this->setError('bedrijfsnaam', 'Vul uw bedrijfsnaam in');
} else if (mb_strlen(trim($bedrijfsnaam)) > 120) {
$this->setError('bedrijfsnaam', 'Te lang! 120 karakters max.'); }
if(!$telefoon || mb_strlen($telefoon = trim($telefoon)) == '') {
$this->setError('telefoon', 'Vul uw telefoon in');
} else if (mb_strlen(trim($telefoon)) > 120) {
$this->setError('telefoon', 'Te lang! 120 karakters max.'); }
if(!$vraag1_antwoorden || mb_strlen($vraag1_antwoorden = trim($vraag1_antwoorden)) == '') {
$this->setError('vraag1_antwoorden', 'Selecteer een antwoord a.u.b.'); }
if(!$vraag2_antwoorden || mb_strlen($vraag2_antwoorden = trim($vraag2_antwoorden)) == '') {
$this->setError('vraag2_antwoorden', 'Selecteer een antwoord a.u.b.'); }
if(!$email || mb_strlen($email = trim($email)) == '') {
$this->setError('email', 'Vul uw email in');
} else if (mb_strlen(trim($email)) > 120) {
$this->setError('email', 'Te lang! 120 karakters max.'); }
/* No errors, insert in db
else*/
if($this->countErrors() == 0) {
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);
//This is for relocating to successful result page
header('Location: result.php');
} else {
// else
// $json = array('result' => -2); /* something went wrong in database insertion */
//This will need special treatment. You have to prepare an errorpage
//for database-related issues.
header("Location: database-error.html");
}
/*$encoded = json_encode($json);
echo $encoded;
unset($encoded);*/
}
}
Link gekopieerd
E
Erwin H
28-08-2012 12:28
gewijzigd op 28-08-2012 12:28
Ik zie nergens private $setError = array(); staan, of ben ik gek?
En twee, gebruik je php 5.4. De syntax die Chris geeft is namelijk pas bruikbaar vanaf 5.4 en niet veel mensen/hosters draaien dat al.
Link gekopieerd
Dan is het toch niet $this->setError maar $this->errors ?
Link gekopieerd
@Chris: Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ']' in C:\domains\projecten\wwwroot\iPad\quiz.php on line 130
Link gekopieerd
E
Erwin H
28-08-2012 12:30
gewijzigd op 28-08-2012 12:45
dat zeg ik, je gebruikt dus geen 5.4, de syntax is dus incorrect.
Gebruik $this->errors['aanhef'] = 'Vul uw aanhef in';
Link gekopieerd