What happens is that when I fill the first 4 labels it "seems" to work, but when I fill all the form it says that the page which is in the action can't be found. Does it have any sense? Why is it happening? Is there any limit of information I can POST? My form looks like this:
<form action="http://www.example.com/php/" enctype="multipart/form-data" method="POST" class="dark-matter">
<fieldset><legend><b> Datos Cliente </b></legend><label>
<b> Email : </b> <label> <input name="mail" type="text" /> </label>
<b> Página : </b> <label> <input name="pagina" type="text" /> </label>
<b> Contraseña : </b> <label> <input name="pass" type="text" /> </label>
<b> Teléfono : </b> <label> <input name="telefono" type="text" /> </label>
<b> Producto : </b> <label> <input name="product" type="text" /> </label>
<b> Precio mínimo : </b> <label> <input name="preciomin" type="text" /> </label>
<b> Precio a añadir : </b> <label> <input name="precioplus" type="text" /> </label>
<b> Límite X max : </b> <label> <input name="limitex" type="text" /> </label>
<b> Límite Y max : </b> <label> <input name="limitey" type="text" /> </label>
<b> Límite Z max : </b> <label> <input name="limitez" type="text" /> </label>
<b> Límite X min : </b> <label> <input name="limitexmin" type="text" /> </label>
<b> Límite Y min : </b> <label> <input name="limiteymin" type="text" /> </label>
<b> Límite Z min : </b> <label> <input name="limitezmin" type="text" /> </label>
<b> Precio material(cm3) : </b> <label> <input name="preciomaterial" type="text" /> </label>
<b> Precio volumen(cm3) : </b> <label> <input name="preciovolumen" type="text" /> </label>
<b> Colores (separar colores mediante comas) : </b> <label> <input name="Color" type="text" /> </label>
<div class="buttonHolder">
<input type="submit" value="Continuar" />
</div>
</form>
Here you have the code of the URL action:
PHP
$mail=$_POST['mail'];
$pagina=$_POST['pagina'];
$pass=$_POST['pass'];
$telefono=$_POST['telefono'];
$product=$_POST['product'];
$preciomin=$_POST['preciomin'];
$precioplus=$_POST['precioplus'];
$limitex=$_POST['limitex'];
$limitey=$_POST['limitey'];
$limitez=$_POST['limitez'];
$limitexmin=$_POST['limitexmin'];
$limiteymin=$_POST['limiteymin'];
$limitezmin=$_POST['limitezmin'];
$preciomaterial=$_POST['preciomaterial'];
$preciovolumen=$_POST['preciovolumen'];
$color=$_POST['Color'];
mysql_connect("localhost", "root", "");
mysql_select_db('wordpress');
$numero=mysql_insert_id();
$sql="INSERT INTO `wordpress`.`intermediarios` (`producto`, `preciomaterial`, `preciovolumen`, `limitex` , `limitey`, `limitez`, `preciomin`, `precioplus` , `pagina`, `telefono`, `mail`, `pass` , `id`, `color`, `comentarios`, `limitexmin` , `limiteymin`, `limitezmin`, `intermediario`) VALUES ('$product','$preciomaterial', '$preciovolumen', '$limitex' , '$limitey', '$limitez', '$preciomin', '$precioplus' , '$pagina', '$telefono', '$mail', '$pass' , NULL , '$color', '$comentarios', '$limitexmin' , '$limiteymin', '$limitezmin' , '$numero')";
mysql_query($sql);
I'm using wordpress but I have created forms in the same page that works properly.
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 2 years ago.
I'm sure it's a stupid mistake, but i can not find what is wrong in my code. I have a simple page, where I can choose a test, and then settle it. I wanted that when we arrive on the page, if the variable $testType doesn't exists, we display test's choice. Once we click on the test we want, we are redirected to the same page, with the variable $testType. So we can settle our test. The 2 first tests have the same settle (Only the way to display the test change, what I do on a third page), so once i verified $testType exists, I would like to verify if($testType == "japTofr" || $testType == "frTojap") but it's not working :
if(isset($_POST['testType'])) {
$testType = $_POST['testType'];
if($testType == "japTofr" || $testType == "frTojap") {
?>
<form method="post" action="test_verb.php">
<legend> Paramétrer le test de verbe : </legend>
<label for="nbr"> Nombre de mot à réviser : </label> <input type="number" name="nbr" id="nbr" max="99" required="#"> <br>
</p> Que voulez-vous réviser ? </p>
<input type="checkbox" name="learned[]" id="pas_appris" value="0"> <label for="pas_appris">Pas appris</label> <br>
<input type="checkbox" name="learned[]" id="en_cours" value="1"> <label for="en_cours">En cours</label> <br>
<input type="checkbox" name="learned[]" id="appris" value="2" checked="#"> <label for="appris">Appris</label> <br>
<p> Réviser des leçons du Minna No Nihongo ? </p>
<input type="checkbox" name="lesson[]" id="0" value="0"> <label for="0"> Vocabulaire hors MNN </label> <br>
<input type="checkbox" name="lesson[]" id="1" value="1"> <label for="1"> 1 </label>
<input type="checkbox" name="lesson[]" id="2" value="2"> <label for="2"> 2 </label>
<input type="checkbox" name="lesson[]" id="3" value="3"> <label for="3"> 3 </label>
<input type="checkbox" name="lesson[]" id="4" value="4"> <label for="4"> 4 </label>
<input type="checkbox" name="lesson[]" id="5" value="5"> <label for="5"> 5 </label> <br>
<input type="checkbox" name="lesson[]" id="6" value="6"> <label for="6"> 6 </label>
<input type="checkbox" name="lesson[]" id="7" value="7"> <label for="7"> 7 </label>
<input type="checkbox" name="lesson[]" id="8" value="8"> <label for="8"> 8 </label>
<input type="checkbox" name="lesson[]" id="9" value="9"> <label for="9"> 9 </label>
<input type="checkbox" name="lesson[]" id="10" value="10"> <label for="10"> 10 </label> <br>
<input type="checkbox" name="lesson[]" id="11" value="11"> <label for="11"> 11 </label>
<input type="checkbox" name="lesson[]" id="12" value="12"> <label for="12"> 12 </label>
<input type="checkbox" name="lesson[]" id="13" value="13"> <label for="13"> 13 </label>
<input type="checkbox" name="lesson[]" id="14" value="14"> <label for="14"> 14 </label>
<input type="checkbox" name="lesson[]" id="15" value="15"> <label for="15"> 15 </label> <br>
<input type="checkbox" name="lesson[]" id="16" value="16"> <label for="16"> 16 </label>
<input type="checkbox" name="lesson[]" id="17" value="17"> <label for="17"> 17 </label>
<input type="checkbox" name="lesson[]" id="18" value="18"> <label for="18"> 18 </label>
<input type="checkbox" name="lesson[]" id="19" value="19"> <label for="19"> 19 </label>
<input type="checkbox" name="lesson[]" id="20" value="20"> <label for="20"> 20 </label> <br>
<input type="checkbox" name="lesson[]" id="21" value="21"> <label for="21"> 21 </label>
<input type="checkbox" name="lesson[]" id="22" value="22"> <label for="22"> 22 </label>
<input type="checkbox" name="lesson[]" id="23" value="23"> <label for="23"> 23 </label>
<input type="checkbox" name="lesson[]" id="24" value="24"> <label for="24"> 24 </label>
<input type="checkbox" name="lesson[]" id="25" value="25"> <label for="25"> 25 </label> <br>
<input type="hidden" name="test" value="verb">
<input type="hidden" name="testType" value="<?php echo $testType; ?>">
<input type="submit" value="Démarrer le test">
</form>
<?php
} elseif($testType == "conjugation") {
?>
<form method="post" action="test_verb.php">
<legend> Paramétrer le test de verbe : </legend>
<label for="nbr"> Nombre de mot à réviser : </label> <input type="number" name="nbr" id="nbr" max="49" required="#"> <br>
<p> Temps que vous souhaitez réviser : </p>
<input type="checkbox" name="tense[]" id="masu_form" value="masu_form"> <label for="masu_form" required="#">Forme en masu</label>
<input type="checkbox" name="tense[]" id="neg_present" value="neg_present"> <label for="neg_present">Présent négatif</label>
<input type="checkbox" name="tense[]" id="past" value="past"> <label for="past">Passé</label>
<input type="checkbox" name="tense[]" id="neg_past" value="neg_past"> <label for="neg_past">Passé négatif</label>
<input type="checkbox" name="tense[]" id="te_form" value="te_form"> <label for="te_form">Forme en Te</label>
<input type="checkbox" name="tense[]" id="potential" value="potential"> <label for="potential">Potentielle</label>
<input type="checkbox" name="tense[]" id="passive" value="passive"> <label for="passive">Passive</label>
<input type="checkbox" name="tense[]" id="causative" value="causative"> <label for="causative">Causative</label>
<input type="checkbox" name="tense[]" id="conditional" value="conditional"> <label for="conditional">Conditionnelle</label>
<input type="checkbox" name="tense[]" id="volitional" value="volitional"> <label for="volitional">Volationnelle</label>
<input type="checkbox" name="tense[]" id="imperative" value="imperative"> <label for="imperative">Imperative</label>
<input type="hidden" name="test" value="verb">
<input type="hidden" name="testType" value="<?php echo $testType; ?>">
<input type="submit" value="Démarrer le test">
</form>
<?php
// $testType == group
} else {
?>
<form method="post" action="test_verb.php">
<legend> Paramétrer le test de verbe : </legend>
<label for="nbr"> Nombre de mot à réviser : </label> <input type="number" name="nbr" id="nbr" max="49" required="#"> <br>
<input type="hidden" name="test" value="verb">
<input type="hidden" name="testType" value="<?php echo $testType; ?>">
<input type="submit" value="Démarrer le test">
</form>
<?php
}
} else {
?>
<div class="container">
<div class="row">
<div class="offset-4 col-md-4"> Test de verbe </div>
</div>
<div class="row">
<div class="col-md-6">
<p> Traduire du Japonais au Français </p>
<p> Les verbes sont écrits en kanji + hiragana et il faut donner leur traduction française. </p>
<form method="post" action="settle_test_verb.php">
<input type="hidden" name="testType" value="japTofr">
<input type="submit" value="Faire ce test" class="btn btn-primary">
</form>
</div>
<div class="col-md-6">
Traduire du Français au Japonais
<p> Les verbes sont écrits en français et il faut donner leur traduction en romaji. </p>
<form method="post" action="settle_test_verb.php">
<input type="hidden" name="testType" value="frTojap">
<input type="submit" value="Faire ce test" class="btn btn-primary">
</form>
</div>
</div>
<div class="row">
<div class="col-md-6">
Conjugaison des verbes
<p> Choisissez un temps, et conjuguez les verbes dans le temps choisi. </p>
<form method="post" action="settle_test_verb.php">
<input type="hidden" name="testType" value="conjugation">
<input type="submit" value="Faire ce test" class="btn btn-primary">
</form>
</div>
<div class="col-md-6">
Trouver les groupes des verbes
<p> Trouver à quel groupe appartiennent les verbes </p>
<form method="post" action=""> <!-- Le mettre directement sur la page qui traite les parametre du test -->
<input type="hidden" name="testType" value="group">
<input type="submit" value="Faire ce test" class="btn btn-primary">
</form>
</div>
</div>
</div>
Here is the error i get : Parse error: syntax error, unexpected '$testType' (T_VARIABLE) in /Users/Nico/Sites/lesTests/settle_test_verb.php on line 16
First clean up your mess by doing this. instead of using if-elseif-else. go with the switch case method.
<?php
if(isset($_POST['testType'])){
$testType = $_POST['testType'];
switch($testType){
case 'japTofr':
case 'frTojap': ?>
//put your HTML FORM here
<?php
break;
case 'conjugation': ?>
//put your conjugation html here
<?php
break;
default: ?>
//put your HTML here for testType == group (your else condition)
<?php
}
}else{ ?>
//put yout HTML here if no testType has been set
<?php
}
?>
or another way is this
<?php
if(isset($_POST['testType'])):
$testType = $_POST['testType'];
switch($testType):
case 'japTofr':
case 'frTojap': ?>
//put your HTML FORM here
<?php
break;
case 'conjugation': ?>
//put your conjugation html here
<?php
break;
default: ?>
//put your HTML here for testType == group (your else condition)
<?php
endswitch;
else: ?>
//put yout HTML here if no testType has been set
<?php
endif;
?>
I have a form like this and I would like to know if there is a way to add an image input and upload it to the server.
I would like to be able to upload images to [ROOT]/upload_img/ but, to be honest I don't know how to do it and most of the code parts I found don't work with mine...
Se here I am.
Here's my code :
<html>
<head></head>
<body>
<div id="main">
<div id="login">
<form action="" method="post">
<label>Titre de l'annonce :</label>
<input type="text" name="i_title" id="name" required="required" placeholder=""/>
<br />
<br />
<label>Adresse : </label>
<input type="text" name="i_adress" id="email" required="required" placeholder=""/>
<br/>
<br />
<label>Ville :</label>
<input type="text" name="i_city" id="city" required="required" placeholder="Please Enter Your City"/>
<br/>
<br />
<label>Surface du logement entier :</label>
<input type="text" name="i_surf_room" id="surf_room" required="required" placeholder=""/> En m2
<br/>
<br />
<label>Surface de la chambre :</label>
<input type="text" name="i_surf_home" id="surf_home" required="required" placeholder=""/>
<br/>
<br />
<label>Description :</label>
<input type="text" name="i_description" id="description" required="required" placeholder=""/>
<br/>
<br />
<label>Date de début de disponibilité :</label>
<input type="month" name="i_start_date" id="start_date" required="required" placeholder=""/>
<br/>
<br />
<label>Date de fin de disponibilité :</label>
<input type="month" name="i_end_date" id="end_date" required="required" placeholder=""/>
<br/>
<br />
<label>Photographies du logement</label>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="reset"> -
<input type="submit" name="submit"/>
<br />
</form>
</div>
</div>
<?php
if(isset($_POST["submit"])) {
$hostname='xxxx';
$username='xxxx';
$password='xxx';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=xxxx",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO students (title, adress, city, surf_home, surf_room, description, start_date, end_date)
VALUES ('".$_POST["i_title"]."','".$_POST["i_adress"]."','".$_POST["i_city"]."','".$_POST["i_surf_home"]."','".$_POST["i_surf_room"]."','".$_POST["i_description"]."','".$_POST["i_start_date"]."','".$_POST["i_end_date"]."')";
if ($dbh->query($sql)) {
echo "
<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>";
} else {
echo "
<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
</body>
</html>
Everything is working fine except, instead of writing the data on the form, it writes zeros. The table (new_reservation) looks like this after submitting some values:
PK: res_id (AI, NN)
Not Null: All except "ext_bed"
Model: (reservations_model.php)
class Reservations_model extends CI_Model {
function add_reservations($data) {
$this->db->insert('new_reservation', $data);
return;
}
}
Controller: (reservations.php)
class Reservations extends CI_Controller {
function index() {
$this->load->view('/main/new_reservation');
$this->load->model('reservations_model');
}
function add_reservations() {
$data = array (
'room_type' => $this->input->post('room_type'),
'meal_type' => $this->input->post('meal_type'),
'bed_type' => $this->input->post('bed_type'),
'ext_beds' => $this->input->post('ext_beds'),
'number_of_guests' => $this->input->post('number_of_guests'),
'start_date' => $this->input->post('start_date'),
'end_date' => $this->input->post('end_date'),
'reservation_duration' => $this->input->post('reservation_duration'),
'room_number' => $this->input->post('room_number'),
'total' => $this->input->post('total')
);
$this->reservations_model->add_reservations($data);
$this->index();
}
}
View: (new_reservation.php in /views/main folder)
<?php echo form_open('reservations/add_reservations'); ?>
<p>
<label for="room_type">Room Type*: </label>
<select id="room_type"></select>
</p>
<p>
<label for="meal_type">Meal Type*: </label>
<select size="1" multiple="multiple" id="meal_type"></select>
</p>
<p>
<label for="bed_type">Bed Type*: </label>
<select id="bed_type"></select>
</p>
<p>
<label for="ext_beds">Extra Bed(s): </label>
<input type="text" id="ext_beds" />
</p>
<p>
<label for="number_of_guests">Number of Guests: </label>
<input type="text" id="number_of_guests" />
</p>
<p>
<label for="start_date">Check-in Date*: </label>
<input type="text" id="start_date" />
</p>
<p>
<label for="end_date">Checkout Date*: </label>
<input type="text" id="end_date" />
</p>
<p>
<label for="reservation_duration">Duration: </label>
<input type="text" id="reservation_duration" />(Nights)
</p>
<p>
<label for="room_number">Room Number: </label>
<input type="text" id="room_number" />
</p>
<p>
<label for="total">Total: </label>
<input type="text" disabled="disabled" id="total" readonly="readonly" />
</p>
<p>
<input class="btn" type="reset" />
<input class="btn btn-primary" type="submit" value="Check-in" />
</p>
<?php echo form_close(); ?>
In view
Use name not id
sample example from your code
<p>
<label for="start_date">Check-in Date*: </label>
<input type="text" id="start_date" name="start_date" />
</p>
Your form data.. they should have a name value ex:
<input type="text" id="end_date" name="end_data"/>
Use name along with id, eg:
<input type="text" id="number_of_guests" name="number_of_guests">
for all the input statements
get a value using name not by id
<input type="text" id="number_of_guests" name="number_of_guests">
Here is my code:
<script type="text/javascript">
jQuery(document).ready(function(){
// binds form submission and fields to the validation engine
jQuery("#formIDRegister").validationEngine(); //--> this is the jQuery Validation Engine. The code below has no relation with it.
});
function func(){
$(document).ready(function() {
$(document).ajaxStop($.unblockUI);
$("#formIDRegister").submit(function() {
$("input[type=submit]").attr("disabled", "disabled");
$.blockUI({message: '<h1><img src="./images/misc/ajax-loader.gif" /> Espere um momento...</h1>'});
var trueName = $("#trueName").val();
var trueSurname = $("#trueSurname").val();
var phoneHomeCountryId = $("#phoneHomeCountryId").val();
var phoneHomeCityId = $("#phoneHomeCityId").val();
var phoneHome = $("#phoneHome").val();
var phoneCellCountryId = $("#phoneCellCountryId").val();
var phoneCellCityId = $("#phoneCellCityId").val();
var phoneCell = $("#phoneCell").val();
var userCpf = $("#userCpf").val();
var userBirth = $("#userBirth").val();
var userAddressCountry = $("#userAddressCountry").val();
var userAddressState = $("#userAddressState").val();
var userAddressCity = $("#userAddressCity").val();
var userAddressStreet = $("#userAddressStreet").val();
var userAddressNumber = $("#userAddressNumber").val();
var userAddressCompl = $("#userAddressCompl").val();
var userAddressDistrict = $("#userAddressDistrict").val();
$.post('./cadastro/processa/identificacao', {trueName:trueName, trueSurname:trueSurname, phoneHome:phoneHome, phoneHomeCountryId:phoneHomeCountryId, phoneHomeCityId:phoneHomeCityId, phoneCell:phoneCell,phoneCellCountryId:phoneCellCountryId, phoneCellCityId:phoneCellCityId, userCpf:userCpf, userBirth:userBirth, userAddressCountry:userAddressCountry, userAddressState:userAddressState, userAddressCity:userAddressCity, userAddressStreet:userAddressStreet, userAddressNumber:userAddressNumber, userAddressCompl:userAddressCompl, userAddressDistrict:userAddressDistrict, },
function(resposta) {
$("#ErrorBarContent1").hide();
$("#ErrorBarContent2").hide();
$("#ErrorBarContent3").hide();
$("input[type=submit]").removeAttr("disabled");
if (resposta != false) {
if(resposta == "11"){
$("#ErrorBarContent1").show();
}
if(resposta == "12"){
$("#ErrorBarContent2").show();
}
if(resposta == "1"){
$("#ErrorBarContent3").show();
}
} else {
location.href ="cadastro/caracteristicas-gerais/";
}
});
return false;
});
});
}
</script>
Here is the HTML
<form id="formIDRegister" class="" method="post" action="javascript:func()" accept-charset="UTF-8">
<div id="ErrorBarContent1" onclick="$(this).fadeOut('slow');" style="display:none;"><div class="yellowErrorBar">Todos os campos devem ser preenchidos</div></div>
<div id="ErrorBarContent2" onclick="$(this).fadeOut('slow');" style="display:none;"><div class="yellowErrorBar">Cpf já está sendo utilizado por outro usuário.</div></div>
<div id="ErrorBarContent3" onclick="$(this).fadeOut('slow');" style="display:none;"><div class="redErrorBar">Opps, ocorreu um erro ao atualizar seu cadastro, nossa equipe já foi avisada. Por favor, tente novamente mais tarde.</div></div>
<!-- name -->
<div class="rowOff" id="name">
<p><i>1.</i> Identificação</p>
<label>
<span class="trueName">Seu(s) nome(s)</span><br />
<input value="" class="validate[required] text-input" type="text" name="trueName" id="trueName" />
</label>
<label>
<span class="trueSurname">e seu(s) sobrenome(s)</span><br />
<input value="" class="validate[required] text-input" type="text" name="trueSurname" id="trueSurname" />
</label>
</div>
<!-- phone -->
<div class="rowOn" id="phone">
<p><i>2.</i> Telefones para contato</p>
<div class="phone1">
<span class="phoneHome">Telefone de contato 1</span><br />
<input onmouseover="tooltip.show('Insira o código de seu país');" onmouseout="tooltip.hide();" value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneHomeCountryId" id="phoneHomeCountryId" maxlength="3" />
<input onmouseover="tooltip.show('Insira o código de área');" onmouseout="tooltip.hide();" value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneHomeCityId" id="phoneHomeCityId" maxlength="2" />
<input value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneHome" id="phoneHome" />
</div>
<br />
<br />
<br />
<div class="phone2">
<span class="phoneCell">Telefone de contato 2</span><br />
<input onmouseover="tooltip.show('Insira o código de seu país');" onmouseout="tooltip.hide();" value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneCellCountryId" id="phoneCellCountryId" maxlength="3" />
<input onmouseover="tooltip.show('Insira o código de área');" onmouseout="tooltip.hide();" value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneCellCityId" id="phoneCellCityId" maxlength="2" />
<input value="" class="validate[required,custom[onlyNumberSp]] text-input" type="text" name="phoneCell" id="phoneCell" />
</div>
<div id="divPhoneInfo">Seu número de telefone não será divulgado. Garantimos o sigilo.</div>
</div>
<!-- cpf -->
<div class="rowOff" id="cpf">
<p><i>3.</i> CPF</p>
<label>
<span class="userCpf">Insira seu CPF </span><br />
<input value="" class="validate[required] text-input" type="text" name="userCpf" id="userCpf" /> <span class="hotspot" onmouseover="tooltip.show('Insira o número de seu CPF de 11 dígitos');" onmouseout="tooltip.hide();"><img src="./images/userInterface/info.png" /></span>
</label>
<div id="divCpfInfo">Insira um número de CPF válido. O uso de números falsos implica no descumprimento dos Termos de Utilização, e estará sujeito às penas da Lei.</div>
</div>
<!-- birth -->
<div class="rowOn" id="birth">
<p><i>4.</i> Data de nascimento</p>
<label>
<span class="userBirth">Insira sua data de nascimento </span><br />
<input value="" class="validate[required] text-input" type="text" name="userBirth" id="userBirth" /> <span class="hotspot" onmouseover="tooltip.show('Você PRECISA ser maior de 18 anos para se cadastrar! O formato é dd/mm/aaaa');" onmouseout="tooltip.hide();"><img src="./images/userInterface/info.png" /></span>
</label>
</div>
<!-- address -->
<div class="rowOff" id="adress">
<p><i>5.</i> Endereço</p>
<label id="pais">
<span class="userAddressCountry">País</span><br />
<select name="userAddressCountry" id="userAddressCountry" class="validate[required]" onchange="buscaEstados(this.value)" /></select>
</label >
<label id="estado" style="display: none">
<span class="userAddressState">Estado</span><br />
<select value="" class="validate[required] text-input" type="text" name="userAddressState" id="userAddressState" onchange="buscaCidades(this.value)"/><option value="">Primeiramente, selecione o pais</option></select>
</label>
<label id="cidade" style="display: none">
<span class="userAddressCity">Cidade</span><br />
<select value="" class="validate[required] text-input" type="text" name="userAddressCity" id="userAddressCity" readonly="readonly" /><option value="">Primeiramente, selecione o pais</option></select>
</label>
<br />
<br />
<br />
<div id="endereco" style="display: none">
<label>
<span class="userAddressStreet">Escreva seu Endereço</span><br />
<input value="" class="validate[required] text-input" type="text" name="userAddressStreet" id="userAddressStreet" />
</label>
<label>
<span class="userAddressNumber">Número</span><br />
<input value="" class="validate[required] text-input" type="text" name="userAddressNumber" id="userAddressNumber" />
</label>
<label>
<span class="userAddressCompl">Complemento</span><br />
<input value="" class="" type="text" name="userAddressCompl" id="userAddressCompl" />
</label>
<label>
<span class="userAddressDistrict">Bairro</span><br />
<input value="" class="validate[required] text-input" type="text" name="userAddressDistrict" id="userAddressDistrict" />
</label>
</div>
</div>
<div id="divAddressInfo">Assim como os números de contato e o CPF, seu endereço estará sob total sigilo. Em seu perfil aparecerão apenas <b>País</b>, <b>Estado</b> e <b>Cidade</b></div>
<!-- submit -->
<div class="rowOn" style="margin-top: 40px; padding-top: 40px;">
<label style="margin-left: 170px;">
<input class="submit" type="submit" value="Enviar e Prosseguir" id="sendButtonRegister" />
</label>
</div>
<!-- /formID4 -->
</form>
When I click in submit, in the first click, nothing happens (actually, the position of the screen goes to its middle). The form is submited only in the second click. What is wrong?
You should not use the $(document).ready(function() into function func()
best of all use the next code
$('#formIDRegister').submit(function(e){
e.preventDefault();
func();//your function
});
this code you can put into $(document).ready function or after your form
also remove action="javascript:func()" attribute from form tag
My contact form is not correctly working.
There is 2 section : first fieldset enables you to choose a type of form to display (with jquery) and the other fieldset is for name, email...
Validation is done with jquery.HTML5Form plugin
Validation works fine, email is sent with contact infos (second fieldset) but without any inputs texts of the first fieldset (except values for radio buttons).
HTML :
$(document).ready(function() {
$('#projet').change(function(e) {
var current = $(this).val();
$('#cadreinfos').show();
$('#visible-spec').html($('#' + current).html());
initHTML5form ();
$('#devisresponse').empty();
});
});
<form action="devis.php" method="POST" id="devisform">
<fieldset id="cadreprojet">
<legend>Mon projet</legend>
<select name="projet" id="projet" title="Type de projet"/>
<OPTION selected >Type de projet
<OPTION value='devis-vitrine' >Formule "Vitrine"
<OPTION value='devis-site' >Formule "Mon site"
</select>
<div id="visible-spec">
</div>
<div id="devis-vitrine" class="hidden-spec">
<input type="text" name="activite" id="activite" title="Activité" size="30" maxlength="100" placeholder="Activité (entreprise, association...)" autocomplete="off" required/>
<input type="text" name="fonction" id="fonction" title="Fonction" size="40" maxlength="120" placeholder="Quelle doit être pour vous la fonction du site ?" autocomplete="off" />
<input type="text" name="public" id="public" title="Public" size="10" maxlength="120" placeholder="Public visé ?" autocomplete="off" />
<input type="text" name="image" id="image" title="Image" size="35" maxlength="120" placeholder="Quelle image voulez-vous véhiculer ?" autocomplete="off"/>
<div id="charte">Charte graphique existante ? <input type="radio" name="charte" id="charteN" value="Non" onClick="javascript:$('#couleurs').show();" required/>Non<input type="radio" name="charte" id="charteY" value="Oui" onClick="javascript:$('#couleurs').hide()" required>Oui</div>
<input type="text" name="couleurs" id="couleurs" title="Couleurs" size="18" maxlength="120" placeholder="Couleurs souhaitées ?" autocomplete="off" required/>
<input type="text" name="pages" id="pages" title="Nombre de pages" size="22" maxlength="3" placeholder="Nombre de pages estimé ?" autocomplete="off" required/>
<input type="text" name="exemple" id="exemple" title="Exemple de site" size="35" maxlength="40" placeholder="Adresse d'un site existant pour inspiration" autocomplete="off"/>
<input type="date" name="deadline" id="deadline" title="Deadline" size="27" maxlength="20" placeholder="Date de mise en ligne souhaitée" autocomplete="off" required/>
<textarea name="comment" id="comment" title="Message" cols="80" rows="7" maxlength="1000" placeholder="Merci d'indiquer ici un court descriptif de votre futur site : sujet, rubriques, type de contenu (texte, images, vidéos...), fonctionnalités spécifiques, demandes particulières..." required ></textarea>
</div>
<div id="devis-site" class="hidden-spec">
<input type="text" name="activite" id="activite" title="Activité" size="30" maxlength="100" placeholder="Activité (entreprise, association...)" autocomplete="off" required/>
<input type="text" name="fonction" id="fonction" title="Fonction" size="40" maxlength="120" placeholder="Quelle doit être pour vous la fonction du site ?" autocomplete="off" />
<input type="text" name="public" id="public" title="Public" size="10" maxlength="120" placeholder="Public visé ?" autocomplete="off" />
<input type="text" name="image" id="image" title="Image" size="35" maxlength="120" placeholder="Quelle image voulez-vous véhiculer ?" autocomplete="off"/>
<div id="charte">Charte graphique existante ? <input type="radio" name="charte" id="charteN" value="Non" onClick="javascript:$('#couleurs').show();" required/>Non<input type="radio" name="charte" id="charteY" value="Oui" onClick="javascript:$('#couleurs').hide()" required>Oui</div>
<input type="text" name="couleurs" id="couleurs" title="Couleurs" size="18" maxlength="120" placeholder="Couleurs souhaitées ?" autocomplete="off" required/>
<input type="text" name="admins" id="admins" title="Nombre d'administrateurs" size="27" maxlength="3" placeholder="Nombre d'administrateurs du site ?" autocomplete="off" required/>
<input type="text" name="exemple" id="exemple" title="Exemple de site" size="35" maxlength="40" placeholder="Adresse d'un site existant pour inspiration" autocomplete="off"/>
<input type="date" name="deadline" id="Deadline" title="Deadline" size="27" maxlength="20" placeholder="Date de mise en ligne souhaitée" autocomplete="off" required/>
<div id="charte">Quel contenu voulez-vous mettre à jour vous-même : <input type="checkbox" name="actu" id="actu" value="Actualités" required/>Actualités<input type="checkbox" name="photos" id="photos" value="Photos" required/>Photos<input type="checkbox" name="videos" id="videos" value="Vidéos" required/>Vidéos<input type="checkbox" name="cal" id="cal" value="Calendrier" required/>Calendrier / Réservations</div>
<textarea name="comment" id="comment" title="Message" cols="80" rows="7" maxlength="1000" placeholder="Merci d'indiquer ici un court descriptif de votre futur site : sujet, rubriques, type de contenu (texte, images, vidéos...), fonctionnalités spécifiques, demandes particulières..." required ></textarea>
</div>
</fieldset>
<fieldset id="cadreinfos">
<legend>Mes coordonnées</legend>
<label for="name"></label>
<input type="text" name="name" id="name" title="Nom" maxlength="60" placeholder="Nom" autocomplete="off" required/>
<label for="lastname"></label>
<input type="text" name="lastname" id="lastname" title="Prénom" maxlength="60" placeholder="Prénom" autocomplete="off" required/>
<label for="email"></label>
<input type="email" name="email" id="email" title="Email" maxlength="40" placeholder="Email" autocomplete="off" required/>
<label for="website"></label>
<input type="url" name="website" id="website" title="Site internet" maxlength="40" placeholder="http://" autocomplete="off" />
<label for="telephone"></label>
<input type="tel" name="telephone" id="telephone" title="Téléphone" maxlength="20" placeholder="Téléphone" autocomplete="off"/>
<input type="submit" value="Envoyer" class="submit"/><div id="devisresponse"></div>
</fieldset>
</form>
function initHTML5form(){
$('#devisform').html5form({
allBrowsers : true,
responseDiv : '#devisresponse',
messages : 'fr',
colorOn :'#8ab29f',
colorOff :'#494343'
});
}
PHP :
$to = "julien#divstudio.fr";
$subject = "Demande de devis";
$name_field = $_POST['name'];
$lastname_field = $_POST['lastname'];
$email_field = $_POST['email'];
$url_field = $_POST['website'];
$tel_field = $_POST['telephone'];
$activite = $_POST['activite'];
$fonction = $_POST['fonction'];
$public = $_POST['public'];
$image = $_POST['image'];
$charte = $_POST['charte'];
$couleurs = $_POST['couleurs'];
$pages = $_POST['pages'];
$exemple = $_POST['exemple'];
$deadline = $_POST['deadline'];
$message = $_POST['comment'];
$from = "From: $email_field\r\n";
$body = "De: $name_field $lastname_field\n $tel_field\n $url_field\n\n
Type de projet: $projet\n\n
Activité:$activite\n
Fonction:$fonction\n
Public:$public\n
Image:$image\n
Charte graphique:$charte\n
Couleurs:$couleurs\n
Nombre de pages:$pages\n
Exemple de site:$exemple\n
Deadline:$deadline\n\n
Message:\n $message";
echo "Merci $lastname_field, votre email a été envoyé !";
mail($to, $subject, $body, $from);
(sorry it's in french)
See it here live.
Then click on bottom left corner and choose the first select option
Well unless you omitted code from your example $projet is not being set in your PHP code.