Beste Leden,
Ik ben al dagen bezig met onderstaande script voor mijn website, maar ik krijg het niet voor elkaar.
Dit heeft met mijn kennis te maken.
Ik hoop dat de experts hier mij kunnen helpen.
Vanwege privacy heb ik delen in mijn html pagina weggelaten.
Mijn website heb ik gebouwd op basis van html, alle pagina's zijn .html
Nu heb ik een aantal formulieren, dit zijn php forms, die ik wil implementeren op mijn .html pagina.
Wat ik ook doe ik blijf een blank pagina behouden.
Ik zet in mijn volgende bericht mijn html pagina en de form scripts.
Ik hoop dat jullie mij hiermee zouden kunnen helpen.
Thanks voor jullie support, waardeer het enorm!
[size=xsmall]Toevoeging op 08/04/2016 01:14:04:[/size]
PHP Formulier :
<?php
use phpformbuilder\Form;
use phpformbuilder\Validator\Validator;
/* =============================================
start session and include form class
============================================= */
session_start();
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Form.php';
/* =============================================
validation if posted
============================================= */
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Validator/Validator.php';
include_once rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR) . '/phpformbuilder/Validator/Exception.php';
$validator = new Validator($_POST);
$required = array('user-name', 'user-first-name', 'user-email', 'user-phone', 'message');
foreach ($required as $required) {
$validator->required()->validate($required);
}
$validator->maxLength(100)->validate('message');
$validator->email()->validate('user-email');
$validator->captcha('captcha')->validate('captcha');
// check for errors
if ($validator->hasErrors()) {
$_SESSION['errors']['contact-form-1'] = $validator->getAllErrors();
} else {
$from_email = '[email protected]';
$adress = addslashes($_POST['user-email']);
$subject = 'phpformbuilder - Contact Form 1';
$filter_values = 'contact-form-1, captcha, submit-btn, captchaHash';
$sent_message = Form::sendMail($from_email, $adress, $subject, $filter_values);
Form::clear('contact-form-1');
}
}
/* ==================================================
The Form
for class and methods documentation,
go to documentation/index.html
================================================== */
$form = new Form('contact-form-1', 'horizontal', 'novalidate=true');
$options = array(
'horizontalLabelCol' => '',
'horizontalOffsetCol' => '',
'horizontalElementCol' => 'col-xs-12'
);
$form->setOptions($options);
$form->startFieldset('Please fill in this form to contact us');
$form->addHtml('<p class="text-warning">All fields are required</p>');
$form->setOptions(array('horizontalElementCol' => 'col-xs-6'));
$form->groupInputs('user-name', 'user-first-name');
$form->addInputWrapper('<div class="input-group"></div>', 'user-name');
$form->addHtml('<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>', 'user-name', 'before');
$form->addInput('text', 'user-name', '', '', 'required=required, placeholder=Name');
$form->addInputWrapper('<div class="input-group"></div>', 'user-first-name');
$form->addHtml('<div class="input-group-addon"><span class="glyphicon glyphicon-user"></span></div>', 'user-first-name', 'before');
$form->addInput('text', 'user-first-name', '', '', 'required=required, placeholder=First Name');
$form->setOptions(array('horizontalElementCol' => 'col-xs-12'));
$form->addInputWrapper('<div class="input-group"></div>', 'user-email');
$form->addHtml('<div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div>', 'user-email', 'before');
$form->addInput('email', 'user-email', '', '', 'required=required, placeholder=Email');
$form->addInputWrapper('<div class="input-group"></div>', 'user-phone');
$form->addHtml('<div class="input-group-addon"><span class="glyphicon glyphicon-earphone"></span></div>', 'user-phone', 'before');
$form->addInput('text', 'user-phone', '', '', 'required=required, placeholder=Phone');
$form->addTextarea('message', '', '', 'cols=30, rows=4, required=required, placeholder=Message');
$form->addPlugin('word-character-count', '#message', 'default', array('%maxAuthorized%' => 100));
$form->addCheckbox('newsletter-checkboxes', 'Suscribe to Newsletter', 'newsletter', 1, 'checked=checked');
$form->printCheckboxGroup('newsletter-checkboxes', '');
$options = array(
'horizontalLabelCol' => 'col-sm-3',
'horizontalOffsetCol' => 'col-sm-offset-3',
'horizontalElementCol' => 'col-sm-9',
);
$form->setOptions($options);
$form->addInput('text', 'captcha', '', 'Type the following characters :', 'size=15');
$form->addPlugin('captcha', '#captcha');
$form->addBtn('submit', 'submit-btn', 1, 'Send <span class="glyphicon glyphicon-envelope append"></span>', 'class=btn btn-success');
$form->endFieldset();
$form->addPlugin('icheck', 'input', 'default', array('%theme%' => 'square-custom', '%color%' => 'green'));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact Form 1</title>
<!-- Bootstrap CSS -->
<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
<?php $form->printIncludes('css'); ?>
</head>
<body>
<h1 class="text-center">Contact Form 1</h1>
<div class="container">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<?php
if (isset($sent_message)) {
echo $sent_message;
}
$form->render();
?>
</div>
</div>
</div>
<!-- jQuery -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- Bootstrap JavaScript -->
<script src="../assets/js/bootstrap.min.js"></script>
<?php
$form->printIncludes('js');
$form->printJsCode();
?>
</body>
</html>
3.297 views