I got this code working (i´m not programmer, but I really need this), it´s sending email with all values, but the checkbox values are blank on the email, even when they´re checked... any help please?
important: serv-opcao(x) and doc-opcao(x) are the ckeckboxes names.
<?php
$nome = $_POST['nome'];
$email = $_POST['email'];
$telefone = $_POST['telefone'];
$serv_opcao1 = $_POST[serv-opcao1];
$serv_opcao2 = $_POST[serv-opcao2];
$serv_opcao3 = $_POST[serv-opcao3];
$serv_opcao4 = $_POST[serv-opcao4];
$serv_opcao5 = $_POST[serv-opcao5];
$serv_opcao6 = $_POST[serv-opcao6];
$serv_opcao7 = $_POST[serv-opcao7];
$outros = $_POST[outros];
$slogan = $_POST[slogan];
$url = $_POST[url];
$doc_opcao1 = $_POST[doc-opcao1];
$doc_opcao2 = $_POST[doc-opcao2];
$doc_opcao3 = $_POST[doc-opcao3];
$doc_opcao4 = $_POST[doc-opcao4];
$doc_opcao5 = $_POST[doc-opcao5];
$doc_opcao6 = $_POST[doc-opcao6];
$outros = $_POST[outros2];
$mensagem1 = $_POST[mensagem1];
$mensagem2 = $_POST[mensagem2];
$mensagem3 = $_POST[mensagem3];
$emaildestino = 'lucasvallimdacosta#me.com';
$email_from='lucasvallimdacosta#me.com';
$mensagem = $_POST['mensagem'];
$assunto = $_POST['assunto'];
$titulo = 'Site Lucas Vallim - Nova Mensagem';
$juntando = '<p>Esta mensagem foi enviada pelo site</p><br/>
<p><b>Nome:</b> '.$nome.'</p>
<p><b>Email:</b> '.$email.' </p>
<p><b>Telefone:</b> '.$telefone.'</p>
<p><b>Serviços desejados:</b></p>
<p> '.$serv_opcao1.' '.$serv_opcao2.' '.$serv_opcao3.' '.$serv_opcao4.' '.$serv_opcao5.' '.$serv_opcao6.' '.$serv_opcao7.' </p>
<p><b>Outros (se houver):</b> '.$outros.'</p>
<p><b>Slogan:</b>'.$slogan.'</p>
<p><b>Url:</b>'.$url.'</p>
<p><b>Documentação disponível:</b></p>
<p> '.$doc_opcao1.' '.$doc_opcao2.' '.$doc_opcao3.' '.$doc_opcao4.' '.$doc_opcao5.' '.$doc_opcao6.'</p>
<p><b>Outros (se houver):</b> '.$outros2.'</p>
<p><b>Existe hoje algum problema de comunicação com o público-alvo?</b></p>
<p>'.$mensagem1.'</p>
<p><b>Você pretende que o trabalho esteja pronto em quanto tempo?</b></p>
<p>'.$mensagem2.'</p>
<p><b>Descreva, com suas palavras, tudo sobre o serviço desejado</b></p>
<p>'.$mensagem3.'</p>
<hr>';
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= "From: $email_from " . "\n";
$envio = mail($emaildestino, $titulo, $juntando, $headers, "-r".$email_from);
if($envio)
header('Location:http://www.google.com');
else
echo "A mensagem não pode ser enviada";
?>
here´s the HTML form:
<form method="POST" name="contactform" id="meu_form" class="form-horizontal" action="design.php">
<br>
<fieldset>
<legend>Dados Pessoais</legend>
<div class="control-group">
<label class="control-label" for="inputNome">Nome</label>
<div class="controls">
<input type="text" name="nome" id="nome" id="inputNome" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" name="email" id="email" id="inputEmail" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputTelefone">Telefone</label>
<div class="controls">
<input type="text" name="telefone" id="telefone" id="inputTelefone" placeholder="">
</div>
</div>
</fieldset>
<br>
<fieldset id="fundo_safari">
<legend>Formulário para criação de <b>Design Gráfico</b></legend>
<div class="control-group">
<label class="control-label" for="inputPassword">Qual o serviço de interesse?<br>
</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="serv-opcao1" id="serv-opcao1" value="Cartão de Visitas">
Cartão de Visitas
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao2" id="serv-opcao2" value="Banner">
Banner
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao3" id="serv-opcao3" value="Folheto">
Folheto
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao4" id="serv-opcao4" value="Papel Timbrado">
Papel Timbrado
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao5" id="serv-opcao5" value="Pasta Institucional">
Pasta Institucional
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao6" id="serv-opcao6" value="Assinatura de Email">
Assinatura de e-mail
</label>
<label class="checkbox">
<input type="checkbox" name="serv-opcao7" id="serv-opcao7" value="Outros">
Outros
</label>
<input type="text" name="outros" id="outros" id="inputOutros" placeholder="Especifique">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEndereço">Possui um slogan?<span id="complemento_label"> (se houver, indique qual).</span></label>
<div class="controls">
<input type="text" name="slogan" id="slogan" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEndereço">Endereço do website atual<span id="complemento_label"> (se houver).</span></label>
<div class="controls">
<div class="input-prepend">
<span class="add-on">http://</span>
<input type="text" id="url" name="url" id="inputNome" placeholder="">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Qual a documentação disponível?<br>
</label>
<div class="controls">
<label class="checkbox">
<input type="checkbox" name="doc-opcao1" id="doc-opcao1" value="Logo Tipo">
Logotipo
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao2" id="doc-opcao2" value="Impresso Institucional">
Impresso Institucional
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao3" id="doc-opcao3" value="Manual">
Manual
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao4" id="doc-opcao5" value="Fotos">
Fotos
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao5" id="doc-opcao5" value="Videos">
Videos
</label>
<label class="checkbox">
<input type="checkbox" name="doc-opcao6" id="doc-opcao6" value="Outros">
Outros
</label>
<input type="text" name="outros2" id="outros2" id="inputOutros" placeholder="Especifique">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Existe hoje algum problema de comunicação com o público-alvo?
</label>
<div class="controls">
<textarea rows="4" name="mensagem1" id="mensagem1"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Você pretende que o trabalho esteja pronto em quanto tempo? <span id="complemento_label">(Prazo máximo)</span>
</label>
<div class="controls">
<textarea rows="4" name="mensagem2" id="mensagem2"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Descreva, com suas palavras, tudo sobre o serviço desejado <span id="complemento_label">(objetivo, funcionalidade, exigências, etc.)</span>
</label>
<div class="controls">
<textarea rows="4" name="mensagem3" id="mensagem3"></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Enviar</button>
</div>
</div>
</fieldset>
</form>
Hint by simple code highlighting:
$telefone = $_POST['telefone'];
$serv_opcao1 = $_POST[serv-opcao1];
Spot the difference between working and not-working. Without quotes, PHP sees constant serv minus constant opaco1. Since both are undefined, they are treated as strings. And those strings doe not have any numerical value, so result of 0 - 0 is 0 and there is no $_POST[0]; If you have error reporting / logging on your server, you would see many notices about undefined constants / indexes. Error reporting and logs are first things to refer to when something does not work.
Moreover, php will not allow you to use some characters in request variables, automatically converting them to underscores, so try $_POST['serv_opcao1']; This should not be true for dashes, only spaces and dots.
Related
I have a website where the user can create a profile. However, if he decides to make any alteration on that profile, he can go to alterar_cadastro.php and make that changes he desire. Code of the file bellow:
<?php
session_start();
include('verifica_login.php');
$email = $_SESSION['usuario'];
$busca_nivel = "SELECT * FROM cadastro WHERE email = '$email' OR sobrenome = '$email'";
$resultado_busca_nivel = mysqli_query($conexao, $busca_nivel);
$rows = mysqli_fetch_array($resultado_busca_nivel);
?>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<br>
<h3>Preencha os dados abaixo para alterar seu cadastro:</h3>
<br>
<form method="post" action="processa_alteracao.php" enctype="multipart/form-data">
<div class="form-group">
<label for="nome">Nome: </label>
<input class="form-control" type="text" name="nome" placeholder="<?php echo $rows['nome'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Apelido: </label>
<input class="form-control" type="text" name="sobrenome" placeholder="<?php echo $rows['sobrenome'] ?>">
<small class="form-text text-muted">Atenção! Mudar seu apelido significa mudar o seu login.</small>
</div>
<div class="form-group">
<label for="nome">Cidade: </label>
<input class="form-control" type="text" name="cidade" placeholder="<?php echo $rows['cidade'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Estado: </label>
<input class="form-control" type="text" name="estado" placeholder="<?php echo $rows['estado'] ?>">
<small class="form-text text-muted">Escreva o seu estado de forma abreviada. Ex.: AM, AC, DF, TO.</small>
</div>
<div class="form-group">
<label class="form-group">Quem é você? </label>
<textarea class="form-control" rows="5" name="geral" placeholder="<?php echo $rows['geral'] ?>"></textarea>
<small class="form-text text-muted">Nos fale um pouquinho sobre quem é você e o que espera da nossa plataforma :) Máximo de caracteres: 100.</small>
</div>
<div class="form-group">
<label class="form-group">E-mail: </label>
<input class="form-control" type="text" name="email" placeholder="<?php echo $rows['email']; ?>" readonly>
</div>
<div class="form-group">
<label class="form-group">Foto para o perfil: </label><input type="file" name="foto_perfil">
</div>
<div class="form-group">
<label class="form-group">Senha: </label><input class="form-control" type="password" name="senha" placeholder="Insira sua senha para confirmar"><br><br>
<button class="btn btn-primary" type="submit">Alterar Perfil</button>
</div>
</form>
</div>
<div class="col-1"></div>
</div>
</body>
</html>
However, if the user leaves one of the inputs blank, that's the value going to MYSQL. I put bellow the php file that process this information:
<?php
session_start();
include 'db.php';
$email = $_SESSION['usuario'];
$nome = mysqli_real_escape_string($conexao, $_POST['nome']);
$sobrenome = mysqli_real_escape_string($conexao, $_POST['sobrenome']);
$cidade = mysqli_real_escape_string($conexao, $_POST['cidade']);
$estado = mysqli_real_escape_string($conexao, $_POST['estado']);
$geral = mysqli_real_escape_string($conexao, $_POST['geral']);
$perfil = $_FILES['foto_perfil'];
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);
$query_cad = "SELECT * FROM cadastro WHERE email = '$email' AND senha = '$senha' OR sobrenome = '$sobrenome' AND senha = '$senha'";
$result = mysqli_query($conexao, $query_cad);
$row = mysqli_num_rows($result);
$row2 = mysqli_fetch_array($result);
$fk_cad = $row2['entry_cod_cad'];
if($row == 1) {
if(isset($perfil)){
$extensao = strtolower(substr($_FILES['foto_perfil']['name'], -4));
$novo_nome = md5(time()) . $extensao;
$diretorio = "img/perfil/";
move_uploaded_file($_FILES['foto_perfil']['tmp_name'], $diretorio.$novo_nome);
}
$query = "UPDATE cadastro SET nome = '$nome', sobrenome = '$sobrenome', cidade = '$cidade', estado = '$estado', geral = '$geral', perfil = '$novo_nome' WHERE entry_cod_cad = '$fk_cad'";
$result_alteracao = mysqli_query($conexao, $query);
$msg = "success";
echo "<script>alert('$msg');window.location.assign('/index.php?pagina=perfil');</script>";
} else {
$msg = "incorrect";
echo "<script>alert('$msg');window.location.assign('/index.php?pagina=inicio');</script>";
}
My question is: How do I make the empty fields have a pre existing value, where this value is the one that already is in his profile. I thought that the value attribute inside <input> would do the trick, however, I was not successful.
Use value parameter instead of placeholder
<?php
session_start();
include('verifica_login.php');
$email = $_SESSION['usuario'];
$busca_nivel = "SELECT * FROM cadastro WHERE email = '$email' OR sobrenome = '$email'";
$resultado_busca_nivel = mysqli_query($conexao, $busca_nivel);
$rows = mysqli_fetch_array($resultado_busca_nivel);
?>
<html>
<head>
</head>
<body>
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<br>
<h3>Preencha os dados abaixo para alterar seu cadastro:</h3>
<br>
<form method="post" action="processa_alteracao.php" enctype="multipart/form-data">
<div class="form-group">
<label for="nome">Nome: </label>
<input class="form-control" type="text" name="nome" value="<?php echo $rows['nome'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Apelido: </label>
<input class="form-control" type="text" name="sobrenome" value="<?php echo $rows['sobrenome'] ?>">
<small class="form-text text-muted">Atenção! Mudar seu apelido significa mudar o seu login.</small>
</div>
<div class="form-group">
<label for="nome">Cidade: </label>
<input class="form-control" type="text" name="cidade" value="<?php echo $rows['cidade'] ?>"><br>
</div>
<div class="form-group">
<label class="form-group">Estado: </label>
<input class="form-control" type="text" name="estado" value="<?php echo $rows['estado'] ?>">
<small class="form-text text-muted">Escreva o seu estado de forma abreviada. Ex.: AM, AC, DF, TO.</small>
</div>
<div class="form-group">
<label class="form-group">Quem é você? </label>
<textarea class="form-control" rows="5" name="geral" value="<?php echo $rows['geral'] ?>"></textarea>
<small class="form-text text-muted">Nos fale um pouquinho sobre quem é você e o que espera da nossa plataforma :) Máximo de caracteres: 100.</small>
</div>
<div class="form-group">
<label class="form-group">E-mail: </label>
<input class="form-control" type="text" name="email" value="<?php echo $rows['email']; ?>" readonly>
</div>
<div class="form-group">
<label class="form-group">Foto para o perfil: </label><input type="file" name="foto_perfil">
</div>
<div class="form-group">
<label class="form-group">Senha: </label><input class="form-control" type="password" name="senha" placeholder="Insira sua senha para confirmar"><br><br>
<button class="btn btn-primary" type="submit">Alterar Perfil</button>
</div>
</form>
</div>
<div class="col-1"></div>
</div>
</body>
</html>
I been trying to figure out where my mistake is without success. I get no reported errors. I want to insert data into the supplier table from a PHP form. id_drugstore is a foreign key into the supplier table and can be chosen form a drop-down list (drop-down is working perfect). Another date is filled in by the user, except id_supplier.
<?
error_reporting(-1);
$conn = mysqli_connect("localhost", "root", "", "retete");
if(mysqli_connect_errno())
{
echo "Nu ma pot conecta la baza de date medical:" .mysqli_connect_error();
}
if(isset($_POST['submit']){
$id_drugstore=$_POST['id_drugstore'];
$name_suplier=$_POST['name_suplier'];
$country_supplier=$_POST['county_supplier'];
$county_supplier=$_POST['county_supplier'];
$town_supplier=$_POST['town_supplier'];
$street_supplier=$_POST['street_supplier'];
$bank_suplier=$_POST['bank_suplier'];
$no_cont_Bank=$_POST['$no_cont_Bank'];
$qry=mysqli_query("INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']";`
$inserted=($qry,$conn);
if($inserted){
echo "Datele au fost inserate cu suucess";
}else{
echo "datele nu au putut fi salvate in baza de date".mysqli_error($conn);
}
}
mysqli_close($conn);
}
?>
<body>
<div class="jumbotron">
<div class="container">
<h4 class="display-5">Adaugare Furnizori in baza de date</h4>
<p class="lead">Completati formularul de mai jos</p>
</div>
</div>
<form action="AdaugareFurnizori.php" method="POST">
<div class="form-row">
<div class="col-md-2 mb-3">
<label for="validationServer01">Farmacie</label>
<select name="name_drugstore">
<option>Selecteaza farmacie</option>
<?php
$conn = mysqli_connect("localhost", "root", "", "retete");
if(mysqli_connect_errno()){
echo "Nu ma pot conecta la baza de date medical:".mysqli_connect_error();
}
$q=mysqli_query($conn,"SELECT * FROM drugstore")or die(mysqli_error());
$c=mysqli_num_rows($q);
if($c==0){
echo 'Nu exista farmacie in baza de date';
}else{
while($row=mysqli_fetch_array($q)){
$id_drugstore=$row['id_drugstore'];
$name_drugstore=$row['name_drugstore'];
echo "<option value='$id_drugstore'>$id_drugstore/$name_drugstore<option>
}
}
mysqli_close($conn);
?>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationServer01">Denumire Furnizori</label>
<input type="text" name="name_suplier" class="form-control is-valid" id = "validationServer01" placeholder="Denumire Furnizor" required>
</div>
</div>
<div class="form-row">
<div class="col-md-2 mb-3">
<label for="validationServer02">Tara</label>
<input type="text" name="country_supplier" class="form-control is-valid" id="validationServer02" placeholder="Tara" required>
<div class="invalid-feedback">
Va rugam sa introduceti tara.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer03">Judet</label>
<input type="text" name="county_supplier" class="form-control is-valid" id="validationServer03" placeholder="Judet" required>
<div class="invalid-feedback">
Va rugam sa introduceti judetul.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer04">Oras</label>
<input type="text" name="town_supplier"class="form-control is-valid" id="validationServer04" placeholder="Oras" required>
<div class="invalid-feedback">
Va rugam sa introduceti orasul.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer05">Strada si numar</label>
<input type="text" name="street_supplier" class="form-control is-valid" id="validationServer05" placeholder="Strada" required>
<div class="invalid-feedback">
Va rugam sa introduceti strada.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer04">Banca</label>
<input type="text" name="bank_suplier"class="form-control is-valid" id="validationServer04" placeholder="Denumire Banca" required>
<div class="invalid-feedback">
Va rugam sa introduceti banca.
</div>
</div>
<div class="col-md-2 mb-3">
<label for="validationServer05">Cont</label>
<input type="text" name="no_cont_Bank" class="form-control is-valid" id="validationServer05" placeholder="Numar Cont" required>
<div class="invalid-feedback">
Va rugam sa introduceti numarul contului.
</div>
</div>
<div class="submit">
<button class="btn btn-primary" type="submit">Submit form</button>
</div>
</div>
</form>
</body>
</html>
That query looks strange:
$qry=mysqli_query("INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']";`
Remove the backticks `
Missing an opening ' before $_POST['name_suplier']'
All of your $_POST variables in that string will never get replaced, put them in curly brackts: {$_POST['name_suplier']}
Make sure you have no typos in there name_suplier vs. town_supplier
Missing a closing bracket at the end of the query AND as a closing bracket for mysql_query()
Side note: Shouldn't there be a list of fields in that INSERT too?
your code should be.
If your supplier table have all this field which you are going to insert then this will works fine but if u skip any of the field then mysqli_query does not work
$qry="INSERT INTO supplier `VALUES('sss','%$id_drugstore%',$_POST['name_suplier']','$_POST['county_supplier']','$_POST['county_supplier']','$_POST['town_supplier']','$_POST['street_supplier']','$_POST['bank_suplier']','$_POST['$no_cont_Bank']')";
$inserted=mysqli_query($qry,$conn);
I have been trying to add php to a bootstrap form via the following tutorial: https://bootstrapbay.com/blog/working-bootstrap-contact-form/. But nothing happens when I click the submit button - I just go back/stay to the same page with an empty form. I don't receive an email nor any error actions when I don't fill out some fields either. Below my code. The name of the document is werkwijze.php. Does someone have an idea what I'm doing wrong? Thanks a lot in advance!
<?php
if (isset($_POST['submit'])){
$voornaam = $_POST['voornaam'];
$familienaam = $_POST['familienaam'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$vraag = $_POST['vraag'];
$from = 'info#tbep.be';
$to = 'eefje.vanhemelryck#gmail.com';
$subject = 'Vraag van op uw website www.tbep.be';
$body = "From: $voornaam $familienaam\n E-Mail: $email\n Telefoon: $tel\n Vraag: $vraag";
// Check if name has been entered
if (!$_POST['voornaam']) {
$errVoornaam = 'Gelieve uw voornaam op te geven';
}
if (!$_POST['familienaam']) {
$errFamilienaam = 'Gelieve uw familienaam op te geven';
}
// Check if email en phone has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Gelieve uw emailadres op te geven';
}
if (!$_POST['tel']) {
$errTel = 'Gelieve uw telefoonnummer op te geven';
}
//Check if message has been entered
if (!$_POST['vraag']) {
$errVraag = 'Gelieve uw vraag te stellen';
}
// If there are no errors, send the email
if (!$errVoornaam && !$errFamilienaam && !$errEmail && !$errTel && !$errVraag) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Hartelijk dank. Ik neem zo snel mogelijk contact met u op!</div>';
} else {
$result='<div class="alert alert-danger">Sorry, er was een probleem met het versturen van dit formulier. Alternatief kan u ons een email sturen op info#tbep.be</div>';
}
}
}
?>
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="text/plain">
<div class="form-group">
<label class="control-label col-sm-3" for="voornaam">Voornaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="voornaam" name="voornaam" placeholder="Voornaam">
<?php echo "<p class='text-danger'>$errVoornaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="familienaam">Familienaam:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="familienaam" name="familienaam" placeholder="Familienaam">
<?php echo "<p class='text-danger'>$errFamilienaam</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="telefoon">Telefoonnummer:</label>
<div class="col-sm-9">
<input type="tel" class="form-control" id="tel" name="tel" placeholder="Telefoonnummer">
<?php echo "<p class='text-danger'>$errTel</p>";?>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="vraag">Uw vraag:</label>
<div class="col-sm-9">
<textarea class="form-control" rows="5" id="vraag" name="vraag" placeholder="Uw vraag"></textarea>
<?php echo "<p class='text-danger'>$errVraag</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" id="submit" name="submit" value="Send" class="btn btn-default">Versturen</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<?php echo $result; ?>
</div>
</div>
</form>
Please Remove enctype="text/plain" from your form.
<form class="form-horizontal" role="form" action="werkwijze.php" method="post">
Or use
<form class="form-horizontal" role="form" action="werkwijze.php" method="post" enctype="multipart/form-data">
hello people have to be a form to use all form controls available and after processing all the values show , I have the following code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Contacto</title>
</head>
<body>
<?php
// define variables and set to empty values
$nombre = $email = $comment = $consulta = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$nombre = test_input($_POST["nombre"]);
$email = test_input($_POST["email"]);
$evento = test_input($_POST["evento"]);
$consulta = test_input($_POST["consulta"]);
// $comment = test_input($_POST["comment"]);
$evento = test_input($_POST["evento"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div class="contenedor">
<div id="encabezado">
</div>
<div id="contenido">
<h1>Como contactarnos</h1>
<h2>Formulario de contacto</h2>
<form id="formulario" class="formulario" action="#" method="post">
<div class="campo">
<label for="nombre">Nombre o razón social: <span>(*)</span></label>
<input name="nombre" id="nombre" type="text">
</div>
<div class="campo">
<label for="email">E-Mail: <span>(*)</span></label>
<input name="email" id="email" type="text">
</div>
<div class="campo">
Tipo de evento: <span>(*)</span>
<input name="evento" id="evento_empresarial" value="empresarial" type="radio" checked>
<label for="evento_empresarial">Empresarial</label>
<input name="evento" id="evento_particular" value="particular" type="radio">
<label for="evento_particular">Particular</label>
</div>
<div class="interlineado"> <!-- Para alinear esos campos del formulario -->
Me interesa consultar sobre: <span>(*)</span>
</div>
<div class="interlineado">
<input name="consulta" id="consulta_catering" value="catering" type="checkbox">
<label for="consulta_catering">Catering</label>
<input name="consulta" id="consulta_salones" value="salones" type="checkbox">
<label for="consulta_salones">Salones</label>
<input name="consulta" id="consulta_musica" value="musica" type="checkbox">
<label for="consulta_musica">Música</label>
<input name="consulta" id="consulta_fotografia" value="fotografia" type="checkbox">
<label for="consulta_fotografia">Fotografía</label>
</div>
<div class="campo">
<input name="consulta" id="consulta_decoracion" value="decoracion" type="checkbox">
<label for="consulta_decoracion">Decoración</label>
<input name="consulta" id="consulta_dj" value="dj" type="checkbox">
<label for="consulta_dj">DJ</label>
<input name="consulta" id="consulta_show" value="show" type="checkbox">
<label for="consulta_show">Show</label>
<input name="consulta" id="consulta_videos" value="videos" type="checkbox">
<label for="consulta_videos">Videos</label>
</div>
<div class="campo">
<label for="ubicacion">Zona donde desea el evento: <span>(*)</span></label>
<select name="ubicacion" id="ubicacion">
<option value="" selected="selected">-</option>
<option value="caba">CABA</option>
<option value="gba">GBA</option>
<option value="fueradegba">Fuera de GBA, Bs As</option>
<option value="interior">Interior</option>
</select>
</div>
<div class="interlineado">
<label for="comments">Mensaje: <span>(*)</span> </label>
</div>
<div class="mensaje">
<textarea name="comments" id="comments" rows="4" cols="50">
</textarea>
</div>
<div class="mensaje">
<input name="check" id="check" value="OK" type="submit">
<input value="Cancelar" onclick="$('form')[0].reset()" type="reset">
</div>
</form>
<div id="contacto"> <!-- Otras formas de comunicarse -->
<h2> Contacto </h2>
<div class="campo">
Teléfono:
(0220) 411-1111
</div>
<div class="campo">
Celular: (011) 15-5956-3215
</div>
<div class="campo">
Email: user#gmail.com
</div>
</div>
</div>
</div>
</div>
<?php
echo "<h2>Vos ingresaste:</h2>";
echo $nombre;
echo "<br>";
echo $email;
echo "<br>";
echo $evento;
echo "<br>";
echo $consulta;
echo "<br>";
//echo $gender;
?>
</body>
</html>
but does not display correctly checkbox displays the first thing I select ; also if I do not select anything shows me a warning , what happens?
All of your checkboxes have the same name, but you aren't saving them as an array. What you have to do is change the name in the form to name="consulta[]" and then to implode (http://php.net/implode) the array (implode(',',$_POST['consulta'])); in PHP.
As for the error you are getting it because if no checkbox is checked there is no value passed to PHP yet you are trying to give its value to a variable. Validate your form before sending to prevent users from sending it with no checkbox checked or create an if statement.
I hope I understood your question right...
So first you've got a multiple name=consulta for all the checkboxes so in $_POST you will get only the last one that has checked.
Second, you do not need the php function to clear the form, this is enough:
<input value="Cancelar" type="reset">
And third, you didn't initialize $evento
i have a problem with the validation form. It does not work if i put "required", example:
controller:
public function updateBenefit(){
$result = array();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('beneficio', 'Nombre del Beneficio', 'required|alpha');
$this->form_validation->set_rules('info', 'Info', 'alpha');
$this->form_validation->set_rules('descrip', 'Descripción', 'alpha');
$this->form_validation->set_rules('orden', 'Orden', 'integer');
// $this->form_validation->set_rules('fecha', 'Fecha', 'date_valid');
$this->form_validation->set_message('required', 'El campo %s es requerido');
if ($this->form_validation->run() == TRUE){
if (isset($_POST['id'])){
$idb = $_POST['id'];
$benefit = BeneficiosManager::getInstance()->getHome($idb);
$result['message'] = "Se ha modificado el Beneficio con éxito";
} else{
$benefit = BeneficiosManager::getInstance()->create();
$result['message'] = "Se ha cargado el Beneficio con éxito";
}
$benefit->nombre = ucfirst(strtolower($_POST['beneficio']));
$benefit->content = ucfirst(strtolower($_POST['descrip']));
$benefit->intro = ucfirst(strtolower($_POST['info']));
$benefit->active = $_POST['optionsRadios2'];
$benefit->orden = $_POST['orden'];
// $benefit->date = $_POST['fecha'];
BeneficiosManager::getInstance()->save($benefit);
}else{
//no se validaron los datos ingresados
$result['message'] = "Error validación";
}
echo json_encode($result);
}
view:
{extends file='admin/base/base.tpl'}
{block name='content'}
<h3>Cargar Beneficio </h3>
</br>
<form action="{site_url()}admin/updateBenefit" class="form-horizontal" method="post" id="" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label">Beneficio</label>
<div class="controls">
<input type="text" name="beneficio" value="" class="m-wrap medium" />
<span class="help-inline">Nombre del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Info</label>
<div class="controls">
<textarea name="info" class="medium m-wrap" rows="3"></textarea>
<span class="help-inline">Información Clave</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Descripción</label>
<div class="controls">
<textarea name="descrip" class="large m-wrap" rows="3"></textarea>
<span class="help-inline">Descripción del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Activo</label>
<div class="controls">
<label class="radio line">
<input type="radio" name="optionsRadios2" value="1"/>Si</input>
</label>
<label class="radio line">
<input type="radio" name="optionsRadios2" value="0"/>No</input>
</label>
<span class="help-inline">Ofrecer Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Orden</label>
<div class="controls">
<input type="text" name="orden" value="" class="m-wrap small" />
<span class="help-inline">Prioridad del Beneficio</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Fecha</label>
<div class="controls">
<input type="text" name="fecha" value="{$smarty.now|date_format}" class="m-wrap medium" />
<span class="help-inline"></span>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn blue"><i class="icon-ok"></i> Guardar</button>
<button type="button" class="btn">Cancelar</button>
</div>
</form>
{/block}
what might the problem be?
if i remove the "required" field, the form validates... but if i put it, it doesn't... i don't know what else to try, can't understand why this is happening
the code is working now, thanks to #Jonathan that corrected me, and i was also making an imput mistake when i was trying this method. I was trying to put two words in the same field (i.e: bon vivir); so the correct input would be: bonvivir.
I'm not sure you are using "title" as the name of your real title input element. Because I found you use this code to assign your title.
$benefit->title = ucfirst(strtolower(trim($_POST['beneficio'])));
So you may want to try to use
$this->form_validation->set_rules('beneficio', 'Nombre del Beneficio', 'required|alpha');
instead.
I am not sure I had the right guess. Just give it a go. Hope this helps.