html form with php issue - php

I have made a html form where the user can enter his name/email/phone etc. and also select quantity of the listed products.
Here is the product code and I'm wondering how do I do to include in the email message I get from the form to include how many of what product the user wants.
This is the form code:
<div class="col-sm-6 col-md-6 bottom-padding">
<?php
process_si_contact_form();
if (isset($_SESSION['ctform']['error']) && $_SESSION['ctform']['error'] == true):
?>
<div class="alert alert-danger">
<strong>Oops!</strong> Something went wrong.
</div>
<?php
elseif (isset($_SESSION['ctform']['success']) && $_SESSION['ctform']['success'] == true):
?>
<div class="alert alert-success">
<strong>Message sent!</strong> We'll get in touch asap.
</div>
<?php
endif;
?>
<form class="form-box register-form contact-form" method="POST" id="contact_form">
<input type="hidden" name="do" value="contact" />
<h3 class="title">Form</h3>
<label>Name: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_name_error'] ?>
<input class="form-control" type="text" name="ct_f_name" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_name']) ?>">
<label>E-mail: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_email_error'] ?>
<input class="form-control" type="email" name="ct_f_email" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_email']) ?>">
<label>Phone: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['f_tel_error'] ?>
<input class="form-control" type="text" name="ct_f_tel" value="<?php echo htmlspecialchars(#$_SESSION['ctform']['ct_f_tel']) ?>">
<div class="panel-group" id="accordion">
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="collapsed">
Hardware
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" style="height: 0px;">
<div class="panel-body">
<ul class="list-group checked-list-box">
<?php
$my_products = array(
'1' => 'Product 1',
'2' => 'Product 2',
'3' => 'Product 3'
);
foreach ($my_products as $key => $value) {
echo "<div class=\"col-xs-6\" style=\"margin: 10px 0 5px 0;\">";
echo "<li class=\"list-group-item\" data-style=\"button\">";
echo $value;
echo "<select class=\"form-control\" name=\"quantity[$key]>\"";
for ($i = 0; $i <= 10; $i++) echo "<option value=\"$i\">$i</option>";
echo "</select>";
echo "</li>";
echo "</div>";
}
?>
</ul>
</div>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" class="collapsed">
Software
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Empty.
</div>
</div>
</div>
</div>
<label>Message: <span class="required">*</span></label>
<?php echo #$_SESSION['ctform']['message_error'] ?>
<textarea class="form-control" name="ct_message"><?php echo htmlspecialchars(#$_SESSION['ctform']['ct_message']) ?></textarea>
<div class="clearfix"></div>
<div class="buttons-box clearfix">
<input type="submit" class="btn btn-default" value="Send">
<span class="required"><b>*</b> Required fields</span>
</div>
</form>
</div>
Anything else I need to post? I don't know if this is the best way coded but it does the work. Now it won't let me save this question because it's much code included in this post so I'm writing to be able to save it lol.
EDIT: ADDING PHP FORM CODE.
<?php
function process_si_contact_form() {
$_SESSION['ctform'] = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && #$_POST['do'] == 'contact') {
foreach($_POST as $key => $value) {
if (!is_array($key)) {
if ($key != 'ct_message') $value = strip_tags($value);
$_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
}
}
$f_name = #$_POST['ct_f_name'];
$f_tel = #$_POST['ct_f_tel'];
$f_email = #$_POST['ct_f_email'];
$message = #$_POST['ct_message'];
$f_name = substr($f_name, 0, 64);
$errors = array();
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
if (strlen($f_name) < 3) {
$errors['f_name_error'] = 'Your name please.';
}
if (strlen($f_tel) < 10) {
$errors['f_tel_error'] = 'Your phone please.';
} else if (!preg_match('/^([-+0-9()]+)$/', $f_tel)) {
$errors['f_tel_error'] = 'Thats not a phone number!';
}
if (strlen($f_email) == 0) {
$errors['f_email_error'] = 'Your e-mail please.';
} else if (!preg_match('/^(?:[\w\d]+\.?)+#(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/i', $f_email)) {
$errors['f_email_error'] = 'Thats not an e-mail!';
}
if (strlen($message) < 10) {
$errors['message_error'] = 'Your message must contain atleast 10 characters.';
}
}
if (sizeof($errors) == 0) {
$time = date('r');
$message = "<strong>Name:</strong><br /><em>$f_name</em><br />"
. "<br />"
. "<strong>E-mail:</strong><br /><em>$f_email</em><br />"
. "<br />"
. "<strong>Phone:</strong><br /><em>$f_tel</em>"
. "<br /><br /><br />"
. "<strong>Message:</strong><br />"
. "<pre>$message</pre>"
. "<br /><br />"
. "<strong>IP:</strong><br /><em>{$_SERVER['REMOTE_ADDR']}</em><br />"
. "<br />"
. "<strong>Time:</strong><br /><em>$time</em><br />"
. "<br />"
. "<strong>Browser:</strong><br /><em>{$_SERVER['HTTP_USER_AGENT']}</em>";
$message = wordwrap($message, 70);
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient_no_reply']}\r\nReply-To: {$f_email}\r\nContent-type: text/html; charset=utf8\r\nMIME-Version: 1.0");
}
$_SESSION['ctform']['error'] = false;
$_SESSION['ctform']['success'] = true;
} else {
$_SESSION['ctform']['ct_f_name'] = $f_name;
$_SESSION['ctform']['ct_f_tel'] = $f_tel;
$_SESSION['ctform']['ct_f_email'] = $f_email;
$_SESSION['ctform']['ct_message'] = $message;
foreach($errors as $key => $error) {
$_SESSION['ctform'][$key] = "<span class=\"error\" style=\"float: right; color: 00ff00;\">$error</span>";
}
$_SESSION['ctform']['error'] = true;
}
}
}
$_SESSION['ctform']['success'] = false;
?>
EDIT 2: ADDING NEW PHP MAIL CODE.
<?php
function process_si_contact_form() {
$_SESSION['ctform'] = array();
if ($_SERVER['REQUEST_METHOD'] == 'POST' && #$_POST['do'] == 'contact') {
foreach($_POST as $key => $value) {
if (!is_array($key)) {
if ($key != 'ct_message') $value = strip_tags($value);
$_POST[$key] = htmlspecialchars(stripslashes(trim($value)));
}
}
$f_name = #$_POST['ct_f_name'];
$f_tel = #$_POST['ct_f_tel'];
$f_email = #$_POST['ct_f_email'];
$message = #$_POST['ct_message'];
$f_name = substr($f_name, 0, 64);
$products = array(
#$_POST['quantity[1]'],
#$_POST['quantity[2]'],
#$_POST['quantity[3]'],
#$_POST['quantity[4]'],
#$_POST['quantity[5]'],
#$_POST['quantity[6]'],
#$_POST['quantity[7]'],
#$_POST['quantity[8]'],
#$_POST['quantity[9]'],
#$_POST['quantity[10]']);
$errors = array();
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
if (strlen($f_name) < 3) {
$errors['f_name_error'] = 'Fyll i ditt namn';
}
if (strlen($f_tel) < 10) {
$errors['f_tel_error'] = 'Fyll i ditt tel.nr';
} else if (!preg_match('/^([-+0-9()]+)$/', $f_tel)) {
$errors['f_tel_error'] = 'Felaktigt tel.nr';
}
if (strlen($f_email) == 0) {
$errors['f_email_error'] = 'Fyll i din e-postadress';
} else if (!preg_match('/^(?:[\w\d]+\.?)+#(?:(?:[\w\d]\-?)+\.)+\w{2,4}$/i', $f_email)) {
$errors['f_email_error'] = 'Felaktig e-postadress';
}
if (strlen($message) < 10) {
$errors['message_error'] = 'Ditt meddelande måste bestå av minst 10 tecken';
}
}
if (sizeof($errors) == 0) {
$time = date('r');
$message = "<strong>Namn:</strong><br /><em>$f_name</em><br />"
. "<br />"
. "<strong>E-postadress:</strong><br /><em>$f_email</em><br />"
. "<br />"
. "<strong>Telefon:</strong><br /><em>$f_tel</em>"
. "<br /><br /><br />"
. "<strong>Meddelande:</strong><br />"
. "<pre>$message</pre>"
. "<br />"
. "<strong>IP:</strong><br /><em>{$_SERVER['REMOTE_ADDR']}</em><br />"
. "<br /><strong>".$products[1]." - Ingenico IPP350</strong>"
. "<br /><strong>".$products[2]." - Ingenico ICT250</strong>"
. "<br /><strong>".$products[3]." - Yomani</strong>"
. "<br /><strong>".$products[4]." - Ingenico IWL250 GPRS</strong>"
. "<br /><strong>".$products[5]." - PosBank® AnyShop II</strong>"
. "<br /><strong>".$products[6]." - Ingenico IWL250 Wifi</strong>"
. "<br /><strong>".$products[7]." - Ingenico IWL250 BT</strong>"
. "<br /><strong>".$products[8]." - PosBank&reg AnyShop e2</strong>"
. "<br /><strong>".$products[9]." - Ingenico IWL285 3G</strong>"
. "<br /><strong>".$products[10]." - Ingenico iCMP</strong>"
. "<br /><br /><strong>Tid:</strong><br /><em>$time</em><br />"
. "<br />"
. "<strong>Webbläsare:</strong><br /><em>{$_SERVER['HTTP_USER_AGENT']}</em>";
$message = wordwrap($message, 70);
if (isset($GLOBALS['DEBUG_MODE']) && $GLOBALS['DEBUG_MODE'] == false) {
mail($GLOBALS['ct_recipient'], $GLOBALS['ct_msg_subject'], $message, "From: {$GLOBALS['ct_recipient_no_reply']}\r\nReply-To: {$f_email}\r\nContent-type: text/html; charset=utf8\r\nMIME-Version: 1.0");
}
$_SESSION['ctform']['error'] = false;
$_SESSION['ctform']['success'] = true;
} else {
$_SESSION['ctform']['ct_f_name'] = $f_name;
$_SESSION['ctform']['ct_f_tel'] = $f_tel;
$_SESSION['ctform']['ct_f_email'] = $f_email;
$_SESSION['ctform']['ct_message'] = $message;
foreach($errors as $key => $error) {
$_SESSION['ctform'][$key] = "<span class=\"error\" style=\"float: right; color: 00ff00;\">$error</span>";
}
$_SESSION['ctform']['error'] = true;
}
}
}
$_SESSION['ctform']['success'] = false;
?>

The name of these elements would be: quantity[0], quantity[1], and quantity[2] which contains the value gave for each product. Notice if you want a quantity[0] you need to include that in the $my_products array. The value for Product 1 would be in quantity[1]. The information is from this code here:
$my_products = array(
'0' => 'Product 0', /* Added Product 0 */
'1' => 'Product 1',
'2' => 'Product 2'
);
foreach ($my_products as $key => $value) {
...
// $key is 0,1,2 through the loop so the name would be
// quantity[0] quantity[1], and quantity[2]
echo "<select class=\"form-control\" name=\"quantity[$key]>\"";
for ($i = 0; $i <= 10; $i++) echo "<option value=\"$i\">$i</option>";
echo "</select>";
...
}
So you would just get name in the same way you got your other POST data in your PHP form code:
$products = array(
#$_POST['quantity[0]'],
#$_POST['quantity[1]'],
#$_POST['quantity[2]'] );
Now just include those values in your $message:
$message =
/* Your normal message content here from the code */
. "<strong>Product0:</strong><br /><em>".$products[0]."</em><br />"
. "<br />"
. "<strong>Product1:</strong><br /><em>".$products[1]".</em><br />"
. "<br />"
. "<strong>Product2:</strong><br /><em>".$products[2]."</em><br />"
. "<br />";

Related

Export list CRUD with MPDF + OB_start()

Good morning guys, developing a CRM using the CodeIgniter framework and I'm not managing to export some CRUD lists using an MPDF library.
I'm trying to use an ob_start () function as indicated in the library's own manual, but when exporting, I get the following
formatting error as a return:
error formatting
When in fact a pdf spreadsheet would return
Below, the codes used:
view:
<li><i class="fas fa-download"></i></li>
<div class="conteudo tabelaMovCaixa">
<div class="col-xs-12 usuarioTitulo">
<div class="input entrada1">
<input type="checkbox" id="checkboxAll" onclick="selecionaTodosCheckbox()" value="Selecione">
</div>
<div class="conta">
Conta
</div>
<div class="descricao">
Descrição
</div>
<div class="data">
Vencimento
</div>
<div class="tipo">
Tipo
</div>
<div class="valor">
Valor
</div>
</div>
</form>
<form action="<?php echo base_url('configuracoes/excContasCheckbox') ?>" method="POST">
<?php if ($dados_caixa_filtro == null) { ?>
<?php
$data = date('d/m/Y');
$data2 = date('d/m/Y', strtotime('-1 days', strtotime(date('Y-m-d'))));
$data3 = date('d/m/Y', strtotime('-2 days', strtotime(date('Y-m-d'))));
?>
<div class="col-xs-12 vencimento">
<h5>Vencimento: <?php echo $data ?></h5>
</div>
<?php
if (!empty($dados_caixa)) {
foreach ($dados_caixa as $dados) {
$checkbox = [];
$checkbox[] = $dados->id_contas_pagar_receber;
foreach ($checkbox as $checkbox => $value) {
//echo "ID da conta : ".$value."<br />";
}
if (date("d/m/Y", strtotime($dados->vencimento)) == $data) {
$urlExcluir = base_url('configuracoes/excContaPR') . "/" . $dados->id_contas_pagar_receber;
if ($dados->tipo_pessoa == '1') {
echo "<div class='col-xs-12 usuario saida'>";
} else if ($dados->tipo_pessoa == '2') {
echo "<div class='col-xs-12 usuario entrada'>";
}
echo "<div class='input entrada1'>"
. "<input type='checkbox' name='emp_id[]' value='$value' id='emp_id' onclick=verificarCheckBox() >"
. "</div>"
. "<div class='conta'>"
. "$dados->nome"
. "</div>"
. "<div class='descricao'>"
. $dados->descricao
. "</div>"
. "<div class='data'>";
if ($dados->vencimento == '') {
echo "----------";
} else {
echo date('d/m/Y', strtotime($dados->vencimento));
}
echo "</div>"
. "<div class='tipo'>"
. $dados->forma_pagamento
. "</div>"
. "<div class='valor'>"
. "<span class='entrada2'>" . 'R$ ' . number_format($dados->valor, 2, ',', '.') . "</span>"
. "</div>"
. "<div class='actions2'>"
. "<li><a onclick='pagar2($dados->id_contas_pagar_receber, $dados->tipo_pessoa)' title='Editar'><i class='fas fa-pencil-alt'></i></a></li>"
. "<li><a onclick='pagar($dados->id_contas_pagar_receber, $dados->tipo_pessoa)' title='Pagar'><i class='fas fa-file-invoice-dollar'></i></a></li>"
. "<li><a href='#' onclick = \"confirmExclusaoContaPR(" . '\'0' . $dados->id_contas_pagar_receber . '\',' . '\'' . $urlExcluir . '\'' . ");\" title='Excluir'><i class='fa fa-trash'></i></a></li>"
. "</div>"
. "</div>";
for ($i = 0; $i < count(['checkbox']); $i++) {
$id = $value;
//echo $value;
}
}
}
}
?>
I am placing the ob_start () function right at the beginning of the view containing the HTML of the page.
Controler:
function gerarPdfRelatorio()
{
if ($this->session->userdata('logado') == true) {
date_default_timezone_set('America/Fortaleza');
setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
$dadosC['dados_caixa'] = $this->financeiro->retornaListaMovimentacaoCaixa();
$dadosC['dados_caixa_filtro'] = null;
if ($this->session->userdata('tipo_filtro_movcaixa')) {
$this->session->unset_userdata("tipo_filtro_movcaixa");
}
$this->load->view('admin/head');
$dadosC['lista_cliente'] = $this->relatorio->buscaClienteFornecedor();
$dadosC['lista_centro_custo'] = $this->financeiro->listaCentroCusto();
$this->load->view('admin/head');
$this->load->view('admin/relatorio', $dadosC);
} else {
$dados['mensagem'] = null;
$dados['mensagem_tipo'] = 'error';
$this->paginas($dados);
}
}
This is where I generate the PDF:
<?php
set_time_limit(0);
include_once __DIR__ . '/../../../vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
$conteudoPDF = $this->load->view('admin/relatorios/relatorio_geral.php', '', true);
$header = '<div><img src="assets/img/logo_contrato2.jpeg" width="800"></div>';
$conteudoPDF = mb_convert_encoding($conteudoPDF, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($conteudoPDF);
ob_clean();
$mpdf->WriteHTML($conteudoPDF, 0);
ob_clean();
$mpdf->Output();
This is the list I'm trying to generate
tabela
I would like to know how I can format this data to appear in spreadsheet format in pdf

PHP search MySQL table with dropdown box

I am trying to create a search box that searches the county field of the database. If the criteria matches then the records will be displayed in the table. I have got the different counties in the dropdown box however when I click the record the table does not change. Any help would be appreciated!
<?php
require_once("includes/session.php");
include_once("includes/masterinclude.php");
$preferences = getPreferences();
$category = "";
$attribute1 = ""; $attribute2 = ""; $attriute3 = ""; $attribute4 = "";
$top_level="0";
$name = $_GET['members'];
$information = getInformationPage($name);
$infopagename=$information->IN_NAME;
//meta data for information pages now taken from the information table
$pageTitle = $information->IN_NAME . html_entity_decode($information->IN_TITLE);
$pageMetaDescription = html_entity_decode($information->IN_META_DESC);
$pageMetaKeywords = html_entity_decode($information->IN_META_KEYWORDS);
$pageCustomHead = html_entity_decode($information->IN_CUSTOM_HEAD, ENT_QUOTES);
//initialise screen fields
$selected_member = "";
$id = "";
$username = ""; $username_original = "";
$password = ""; $password_original = "";
$password_test = "";
$title = "MR"; $first_name = ""; $last_name = ""; $company_name = "";
$address1 = ""; $address2 = ""; $town = ""; $county = ""; $country = ""; $postcode = ""; $phone = ""; $mobile = ""; $email = "";
$member_confirmed = "N";
$ast_first = 0; $ast_last = 0; $ast_company = 0; $ast_add1 = 0; $ast_add2 = 0; $ast_town = 0; $ast_county = 0; $ast_country = 0; $ast_post = 0; $ast_phone = 0;
$ast_mobile = 0; $ast_email = 0;
$ast_user = 0; $ast_pass = 0; $ast_passconf = 0;
$members = Get_All_Members("ALL");
$_GET['searchdata'] = $_POST['SEARCH_DATA']; $_GET['searchmember'] = $_POST['MEMBER'];
include_once("includes/header.php");
?>
<!-- start: Page header / Breadcrumbs -->
<div id="breadcrumbs">
<div class="container">
<div class="breadcrumbs">
Home<i class="icon-angle-right"></i>Stockists
</div>
</div>
</div>
<!-- end: Page header / Breadcrumbs -->
<!-- start: Container -->
<div id="container">
<div class="container">
<div class="row-fluid">
<form class="form-horizontal form-box" role="form" name="enter_thumb" action="/stockists.php" enctype="multipart/form-data" method="post" onsubmit="return validate_discount_table();">
<!-- start: Page section -->
<section class="span12">
<div class="row-fluid shop-result">
<div class="inner darken clearfix">
<h1>Stockists</h1>
</div>
</div>
<div class="row-fluid">
<div class="form-group">
<label class="col-lg-4">Search County: </label>
<div class="col-lg-4">
<Input class="form-control" name="SEARCH_DATA" type="text" size="72" value="<?php echo isset($_POST['SEARCH_DATA']) ? $_POST['SEARCH_DATA'] : "" ?>"/>
</div>
<div class="col-lg-4">
<Input name="SEARCH" type="submit" value="search" class="btn btn-primary"/>
</div>
<div class="col-lg-4">
<select name="search_results" id="jumpMenu" onchange="MM_jumpMenu('parent',this,1)">
<option value="#">Choose from...</option>
<?php
if (isset($_POST['SEARCH_DATA'])){
$members = Search_member($_POST['SEARCH_DATA']);
foreach($members as $m){
if(isset($_POST['SELECTED_MEMBER']) and $_POST['SELECTED_MEMBER'] == $m->MB_COUNTY){
$selected = "selected";
}else{
$selected = "";
}
echo "<option value=\"/stockists.php?searchdata=" . $_POST['SEARCH_DATA'] . "&searchmember=" . $m->MB_COUNTY . "\"" . $selected . ">" . $m->MB_COUNTY . " - " . html_entity_decode($m->MB_COUNTY) . "</option>";
}
}
?>
</select>
<input type="hidden" name="SELECTED_MEMBER" value="<?php echo (isset($selected_member) ? $selected_member : "") ?>"/>
</div>
</div>
<div class="form-group">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>
Name
</th>
<th>
Website
</th>
<th>
Phone
</th>
<th>
Address
</th>
</tr>
</thead>
<?php if($county != ""): ?>
<?php
foreach($members as $m){
echo "<tr>";
echo "<td>";
echo "<span class=\"member_line\">" . $m->MB_COMPANY . "</span>";
echo "</td>";
echo "<td>";
echo "" . $m->MB_MOBILE . "";
echo "</td>";
echo "<td>";
echo "<span class=\"member_line\">" . $m->MB_PHONE . "</span>";
echo "</td>";
// echo "<td>";
// echo "<span style=\"color:#669999;\" class=\"member_line\">" . $m->MB_EMAIL . "</span>";
// echo "</td>";-->
echo "<td>";
echo "<span class=\"member_line\">" . $m->MB_ADDRESS1 . ", " . $m->MB_ADDRESS2 . ", " . $m->MB_TOWN . ", " . $m->MB_COUNTY . ", " . $m->MB_POSTCODE . "</span>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
</table>
<?php endif; ?>
</div>
</div>
</form>
</section>
<!-- end: Page section -->
</div>
</div>
</div>
<!-- end: Container -->
<?php
include_once("includes/footer.php");
?>
Your PHP page isn't going to be able to change what is in the bale without a page refresh or alternatively using javascript to rewrite the page.
I see you're using a MM_jumpMenu() JS function when the drop down change. This function will need to retrieve the data for your selection then rewrite the table to include the new data. If you are already doing this in the JS code then we'll need to see that code to find what the problem is.
An alternative to this would be to do away with the JS and allow the form to submit the page to itself. Then at the top of the page read the selected value that has been passed from the form, load the data and write the bale accordingly.

Contact form issues wordpress

I've got a problem with a contact form on my webpage.
When someone fills it in, i always got the error message that something isn't filled in right.
It seems to be the telephone number.
The link to the webpage is http://www.tiggelovend-kok.nl/index.php/contact/
<?php
/*
Template Name: Contact
*/
?>
<?php get_header(); ?>
<div class="wider_blog">
<div class="_blog">
<div class="topbar"><div class="row">
<?php
echo beopen_main_title();
if (beopen_get_option('show_breadcrumbs') == '2') {
echo beopen_breadcrumb();
}
?>
</div></div>
<?php
if (beopen_get_option('show_map') != 1) {
?>
<div id="map_canvas_shadow"></div>
<div id="map_canvas"></div>
<?php
}
?>
<div class="row">
<!-- Row for main content area -->
<div id="content" class="eight columns rightfade" role="main">
<div class="post-box">
<article class="contact">
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php if (beopen_get_option('show_contact_form') == 2) { ?>
<?php echo beopen_get_option('contact_form_text'); ?>
<form class="beopen-contact-form" action="<?php echo get_permalink(); ?>" method="post">
<?php
require_once(THEME_LIBRARY . '/recaptchalib.php');
$error_contact_name = '';
$error_contact_email = '';
$error_contact_phone = '';
$error_contact_company = '';
$error_contact_message = '';
$contact_name = '';
$contact_email = '';
$contact_company = '';
$contact_phone = '';
$contact_message = '';
$publickey = beopen_get_option('recaptcha_public_key');
$privatekey = beopen_get_option('recaptcha_private_key');
if (isset($_POST['beopen_form'])) {
foreach ($_POST as $key => $val) {
$GLOBALS[$key] = wp_filter_kses($val);
}
$send = 0;
if (beopen_get_option('show_recaptcha') == 2) {
$recaptcha_challenge_field = '';
if (isset($_POST["recaptcha_challenge_field"])) {
$recaptcha_challenge_field = $_POST["recaptcha_challenge_field"];
}
$recaptcha_response_field = '';
if (isset($_POST["recaptcha_response_field"])) {
$recaptcha_response_field = $_POST["recaptcha_response_field"];
}
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
echo '<div class="alert-box alert">';
echo (__("The reCAPTCHA wasn't entered correctly. Go back and try it again.", 'beopen') .
"(" . __('reCAPTCHA said:', 'beopen') . " " . $resp->error . ")");
echo '</div>';
} else {
// Your code here to handle a successful verification
$send = 1;
}
} else {
$send = 1;
}
if (!(isset($_POST['contact_name']) && ($_POST['contact_name']) != '')) {
$error_contact_name = 'error';
$send = 2;
}
if (!(isset($_POST['contact_message']) && ($_POST['contact_message']) != '')) {
$error_contact_message = 'error';
$send = 2;
}
if ($send == 2) {
echo '<div class="alert-box alert">';
_e('U bent een veld vergeten in te vullen!', 'beopen');
echo '</div>';
} else
if ($send == 1) {
$mail_content = __('Name:', 'beopen') . PHP_EOL . $_POST['contact_name'] . PHP_EOL . PHP_EOL .
__('E-mail:', 'beopen') . PHP_EOL . $_POST['contact_email'] . PHP_EOL . PHP_EOL .
__('Company:', 'beopen') . PHP_EOL . $_POST['contact_company'] . PHP_EOL . PHP_EOL .
__('Phone:', 'beopen') . PHP_EOL . $_POST['contact_phone'] . PHP_EOL . PHP_EOL .
__('Message:', 'beopen') . PHP_EOL . $_POST['contact_message'] . PHP_EOL;
if ($_POST['contact_email'] == '') {
$mail_headers = 'From: ' . beopen_get_option('contact_email_from') . PHP_EOL .
'Reply-To: ' . beopen_get_option('contact_email_from');
} else {
$mail_headers = 'From: ' . $_POST['contact_email'] . PHP_EOL .
'Reply-To: ' . $_POST['contact_email'];
}
if (mail(beopen_get_option('contact_email_to'), beopen_get_option('contact_email_subject'), $mail_content, $mail_headers)) {
echo '<div class="alert-box success">';
_e('Bericht verzonden!', 'beopen');
echo '</div>';
} else {
echo '<div class="alert-box alert">';
_e('Voer de juiste gegevens in!', 'beopen');
echo '</div>';
}
}
}
?>
<div class="row">
<div class="six columns">
<div class="beopen-wrap author-icon <?php echo $error_contact_name; ?>">
<input type="text" name="contact_name" value="<?php echo $contact_name; ?>" placeholder="<?php _e('Uw naam', 'beopen'); ?>" />
</div>
</div>
<div class="six columns">
<div class="beopen-wrap email-icon <?php echo $error_contact_email; ?>">
<input type="text" name="contact_email" value="<?php echo $contact_email; ?>" placeholder="<?php _e('Uw e-mail', 'beopen'); ?>" />
</div>
</div>
</div>
<div class="row">
<div class="six columns">
<div class="beopen-wrap company-icon <?php echo $error_contact_company; ?>">
<input type="text" name="contact_company" value="<?php echo $contact_company; ?>" placeholder="<?php _e('Uw organisatie', 'beopen'); ?>" />
</div>
</div>
<div class="six columns">
<div class="beopen-wrap phone-icon <?php echo $error_contact_phone; ?>">
<input type="text" name="contact_phone" value="<?php echo $contact_phone; ?>" placeholder="<?php _e('Uw telefoonnummer', 'beopen'); ?>" />
</div>
</div>
</div>
<textarea name="contact_message" placeholder="<?php _e('Voer hier uw bericht in', 'beopen'); ?>" <?php if ($error_contact_message) { echo 'class="' . $error_contact_message . '"'; } ?>><?php echo $contact_message; ?></textarea>
<div id="recaptcha_div"></div>
<input type="hidden" name="beopen_form" value="1" />
<button class="button send-message" type="submit"><span class="send-message"></span><?php _e('Verzenden', 'beopen'); ?></button>
</form>
<?php } ?>
</article>
</div>
</div><!-- End Content row -->
<div class="four columns">
<div class="contact-sidebar">
<?php echo wpautop(beopen_get_option('map_address')); ?>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>

multiple inputs - Problems with array

it is such that I need to use multiple inputs on my side,
I've tried to do like this but it does not work as it will not show up on the page at all in some manner.
HTML
<div id="onlinetestside">
<div id="onlinetestsidealt"><?php echo $ordet;?></div>
<input type="text" name="ord[]" maxlength="190">
<div style="clear:both;"></div>
</div>
PHP
//ordetalt its coming from database.
$alt = $_POST["ord"];
if($ordetalt == $alt)
{
echo $ordetalt . " og " . $alt;
}
else
{
echo "Error " . $ordetalt . " and " . $alt;
}
error appears like this:
Error Hej and Array
What I want to get to it shall be such that "$ordetalt == $alt" have the same content and it fits together.
EIDT
Here I show the entire code where I need to download some code to the side.
if ($stmt = $this->mysqli->prepare('SELECT id, ordet, ordetalt FROM test WHERE getid = ?')) {
$stmt->bind_param('i', $id);
$id = $_GET['id'];
$stmt->execute();
$stmt->bind_result($id, $ordet, $ordetalt);
while ($stmt->fetch()) {
?>
<div id="onlinetestside">
<div id="onlinetestsidealt"><?php echo $ordet;?></div>
<input type="text" name="ord[]" maxlength="190">
<div style="clear:both;"></div>
</div>
<?php
//ordetalt its coming from database
$alt = $_POST["ord"];
if($ordetalt == $alt)
{
echo $ordetalt . " og " . $alt;
}
else
{
echo "Error " . $ordetalt . " and " . $alt;
}
}
$stmt->close();
}
EIDT EIDT
$i = 0;
$a = $i++;
$alt = $_POST["ord"][$a];
if($ordetalt == $alt)
{
echo $ordetalt . " og " . $alt;
}
else
{
echo "Error " . $ordetalt . " and " . $alt;
}
Barmar is spot on, your line
$alt = $_POST["ord"];
Should read
$alt = $_POST["ord"][0];
OR
change your html like so:
<div id="onlinetestside">
<div id="onlinetestsidealt"><?php echo $ordet;?></div>
<input type="text" name="ord" maxlength="190">
<div style="clear:both;"></div>
</div>

Having Trouble Outputting Data correctly From SQL Table

I am trying to outputting data from a SQL table
Table cols are:
sheduleID, userID, empID, timeSlot, WeekSlot, daySlot
Connecting to DB
$schedQ = "SELECT * FROM seo_schedule WHERE empID=1 AND weekSlot=1";
$Em1Wk1Res = mysql_query($schedQ) or die(mysql_error());
Displaying Data
echo "<div class='week1'>";
while ($Em1WkRow = mysql_fetch_array($Em1Wk1Res)) {
$clientQ = "SELECT * FROM clients WHERE userID=".$Em1WkRow["userID"]."";
$clientRes = mysql_query($clientQ) or die(mysql_error());
$clientRow = mysql_fetch_array($clientRes);
echo "<div class='day".$Em1WkRow["daySlot"]."'>";
if ($Em1WkRow["timeSlot"] == "am") {
echo "<span class='".$Em1WkRow["timeSlot"]."'>";
echo $clientRow["company"];
echo "</span>";
}
else if ($Em1WkRow["timeSlot"] == "pm") {
echo "<span class='".$Em1WkRow["timeSlot"]."'>";
echo $clientRow["company"];
echo "</span>";
}
echo "</div>";
}
echo "</div>";
Current Output
<div class="week1">
<div class="day1">
<span class="am">Company 1</span>
</div>
<div class="day1">
<span class="pm">Company 1</span>
</div>
<div class="day2">
<span class="am">Company 2</span>
</div>
<div class="day2">
<span class="pm">Company 2</span>
</div>
...etc fir rest of days in week 1
</div>
What I want to be displayed is:
<div class="week1">
<div class="day1">
<span class="am">Company 1</span>
<span class="pm">Company 1</span>
</div>
<div class="day2">
<span class="am">Company 2</span>
<span class="pm">Company 2</span>
</div>
...etc fir rest of days in week 1
</div>
How do I go about doing this....?
You need a nested while to go through the days of the week rendering <span />s inside the week container. I'm not a php dev so can't help you with the implementation, sorry.
The question is do these events depend on a specific time or are you just trying to throw them in 1 company event per day AM and PM? In which case, you can just do:
$arr = array(0 => "am", 1 => "pm");
echo "<div class='week1'>";
while($Em1WkRow = mysql_fetch_array($Em1Wk1Res))
{
$clientQ = "SELECT * FROM clients WHERE userID='" . $Em1WkRow["userID"] . "'";
$clientRes = mysql_query($clientQ) or die(mysql_error());
$i = 0;
$out .= "<div class='day" . $Em1WkRow["daySlot"] . "'>"; // start day
while($clientRow = mysql_fetch_array($clientRes) && $i < 2)
{
// add current day's event
$out .= "<span class='" . $arr[$i++] . "'>";
$out .= $clientRow["company"];
$out .= "</span";
}
$out .= "</div>" // end day
}
echo $out; // display all week's info
echo "</div>"; // end week
This is what I ended up doing...
function emp_schedule($empID) {
$weeks = array(1, 2, 3, 4);
foreach ($weeks as $i => $week) {
$schedQ = "SELECT * FROM seo_schedule WHERE empID=$empID AND weekSlot=$week";
$Em1WkRes = mysql_query($schedQ) or die(mysql_error());
echo "<div class='week'>";
echo "<div class='head'><span class='ts'>Wk ".$week."</span> <span>Monday</span> <span>Tuesday</span> <span>Wednesday</span> <span>Thursday</span> <span>Friday</span></div>";
echo "<div class='ts'><span><strong>AM</strong></span><span><strong>PM</strong></span></div>";
while ($Em1WkRow = mysql_fetch_array($Em1WkRes)) {
$clientQ = "SELECT * FROM clients WHERE userID='".$Em1WkRow["userID"]."'";
$clientRes = mysql_query($clientQ) or die(mysql_error());
while($clientRow = mysql_fetch_array($clientRes)) {
$schd = "<div class='".$Em1WkRow["timeSlot"]."'>";
$schd .= "<span class='client'>".$clientRow["company"]."</span>";
$schd .= "</div>";
$days = array(1, 2, 3, 4, 5);
foreach ($days as $i => $day) {
if ($Em1WkRow["daySlot"] == $day && $Em1WkRow["timeSlot"] == "am" ) {
echo "<div class='day ".$Em1WkRow["daySlot"]."'>";
echo $schd;
}
if ($Em1WkRow["daySlot"] == $day && $Em1WkRow["timeSlot"] == "pm" ) {
echo $schd;
echo "</div>";
}
}
}
}
echo "</div>";
}
}
Mess I Know but it works.

Categories