I'm using a form on my website to allow user to create posts on my wordpress admin.
It works fine, but I have an issue, I don't get the tags meta inside my admin.
here is my php code :
<?php
if(isset($_POST['submit'])){
$err = array();
$err['status'] = true;
$output = "";
if(empty($_POST['pseudo'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Pseudo" ne peut être vide.';
}
if(empty($_POST['mail']) || !preg_match('/[a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}/',$_POST['mail'])){
$err['status'] = false;
$err['msg'][] = 'Le champs "Mail" est mal renseigné';
}
if(empty($_POST['title'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Titre" ne peut être vide.';
}
if(empty($_POST['content'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Article" ne peut être vide.';
}
if($err['status']){
$insert = array(
'post_status' => 'publish',
'post_title' => htmlentities($_POST['title']),
'post_content' => htmlentities($_POST['content']),
'post_category' => array(11),
'post_author' => 999,
);
$post_id = wp_insert_post($insert);
if($post_id != 0){
/*
TAGS
*/
if(!empty($_POST['keywords'])){
$keywords = explode(',',$_POST['keywords']);
foreach($keywords as $k=>$v){
$tag = trim(strip_tags($v));
wp_insert_term(
$tag,
'post_tag',
array(
'slug' => sanitize_title($tag)
)
);
}
}
$user_meta_values = array(
'pseudo' => htmlentities($_POST['pseudo']),
'mail' => $_POST['mail']
);
$output = add_post_meta($post_id, "user_meta", json_encode($user_meta_values)) ? 'Article inséré avec succès.' : 'Une erreur est survenue lors de l\enregistrement.' ;
}
}
else{
foreach($err['msg'] as $k=>$v)
$output .= $v . '<br />';
}
}
?>
my html form :
<form method="post" action="<?php echo site_url().'/ajouter'; ?>">
<p><label for="pseudo">Pseudo</label><input type="text" name="pseudo" id="pseudo" value="" /></p>
<p><label for="mail">Mail</label><input type="text" name="mail" id="mail" value="" /></p>
<p><label for="title">Titre</label><input type="text" name="title" id="title" value="" /></p>
<p><label for="content">Article</label><textarea name="content" id="content" rows="10" cols="15"></textarea></p>
<p><label for="keywords">Mots clés</label><input type="text" name="keywords" id="keywords" value="" /> ( séparez les mots clés par des virgules )</p>
<p><input type="submit" name="submit" value="enregistrer" /></p>
</form>
Anyone know what I'm doing wrong ? can't find out why it's not working,
thanks for your help
Related
I'm currently working on a school project and i'm trying to upload a "post" of a recipe. this includes image, title, instructions,ingredients and also 1 or multiple categories.
all of them insert fine and well. the only issue is with the categories. It only inserts 1 category even if I select multiple checkboxes.
It's supossed to insert every checkbox into a new row in the database.
My DAO
public function insertCategory($data, $title) {
if (empty($errors)) {
$sql = "INSERT INTO `recipes_categories` (`category_id`, `recipe_id`) VALUES(:category_id,:recipe_id);";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':category_id', $data['category_id']);
$stmt->bindValue(':recipe_id', $title['id']);
if ($stmt->execute()) {
return $this->selectcategoryById($this->pdo->lastInsertId());
}
}
return false;
}
My Controller (relevant parts)
public function upload() {
// variabele om foutmelding bij te houden
$error = '';
// controleer of er iets in de $_POST zit
if(!empty($_POST['action'])){
// controleer of het wel om het juiste formulier gaat
if($_POST['action'] == 'add-image') {
// controleren of er een bestand werd geselecteerd
if (empty($_FILES['image']) || !empty($_FILES['image']['error'])) {
$error = 'Gelieve een bestand te selecteren';
}
if(empty($error)){
// controleer of het een afbeelding is van het type jpg, png of gif
$whitelist_type = array('image/jpeg', 'image/png','image/gif');
if(!in_array($_FILES['image']['type'], $whitelist_type)){
$error = 'Gelieve een jpeg, png of gif te selecteren';
}
}
if(empty($error)){
// controleer de afmetingen van het bestand: pas deze gerust aan voor je eigen project
// width: 270
// height: 480
$size = getimagesize($_FILES['image']['tmp_name']);
if ($size[0] < 100 || $size[1] < 100) {
$error = 'De afbeelding moet minimum 100x100 pixels groot zijn';
}
}
if(empty($error)){
// map met een random naam aanmaken voor de upload: redelijk zeker dat er geen conflict is met andere uploads
$projectFolder = realpath(__DIR__);
$targetFolder = $projectFolder . '/../assets/ads';
$targetFolder = tempnam($targetFolder, '');
unlink($targetFolder);
mkdir($targetFolder, 0777, true);
$targetFileName = $targetFolder . '/' . $_FILES['image']['name'];
// via de functie _resizeAndCrop() de afbeelding croppen en resizen tot de gevraagde afmeting
// pas gerust aan in je eigen project
$this->_resizeAndCrop($_FILES['image']['tmp_name'], $targetFileName, 100, 100);
$relativeFileName = substr($targetFileName, 1 + strlen($projectFolder));
$data = array(
'image' => $relativeFileName,
'title' => $_POST['title'],
'instructions' => $_POST['stappenplan'],
'description' => $_POST['ingredienten'],
'category_id' => $_POST['category'],
);
// TODO: schrijf de afbeelding weg naar de database op basis van de array $data
if (!empty($_POST['action'])) {
if ($_POST['action'] == 'add-image') {
// array met data invullen
$data = array(
'path' => '/' . $relativeFileName,
'title' => $_POST['title'],
'instructions' => $_POST['stappenplan'],
'description' => $_POST['ingredienten'],
'category_id' => $_POST['category'],
);
// aanspreken van de DAO
$insertImage = $this->uploadDAO->insertImage($data);
$title = $this->uploadDAO->ImageInsterId($data);
$this->set('title', $title);
$ingredientsArray = explode( ',', $data['description'] );
foreach($ingredientsArray as $ingredient){
$insertIngredient = $this->uploadDAO->insertIngredients($ingredient , $title);
}
$insertCategory = $this->uploadDAO->insertCategory($data, $title);
// TODO 2: zorg dat de variabele $error getoond wordt indien er iets fout gegaan is
if (!$insertImage) {
$errors = $this->uploadDAO->validate($data);
$this->set('errors', $errors);
} else {
$_SESSION['info'] = 'Thank you for adding a Post!';
header('Location: index.php?page=detail&id='. $title['id']);
exit();
}
}
}
}
}
}
There is some code here for the image upload too, but it isn't relevant since that is working.
My HTML
<span class="error"><?php if(!empty($error)){ echo $error;} ?></span>
<section class="upload_box">
<h1 class="hidden">upload-form</h1>
<form method="post" action="index.php?page=upload" enctype="multipart/form-data" class="form__box">
<input type="hidden" name="action" value="add-image" />
<div class="form-field">
<label class="upload__title form_container">Kies een afbeelding
<span class="error"><?php if(!empty($errors['title'])){ echo $errors['title'];}?></span>
<input type="file" name="image" accept="image/png, image/jpeg, image/gif" required class="upload__button filter__submit input">
</label>
</div>
<div class="form-field">
<label class="upload__title form_container">Titel
<span class="error"><?php
if(!empty($errors['title'])){
echo $errors['title'];} ?></span>
<input type="text" name="title" required class="upload__title form_field input">
</label>
</div>
<div class="form-field">
<label class="upload__title form_container">Stappenplan
<span class="error"><?php if(!empty($errors['instructions'])){ echo $errors['instructions'];} ?></span>
<textarea name="stappenplan" id="stappenplan" cols="50" rows="5" required class="form_field upload__title input"></textarea>
</label>
</div>
<div class="form-field">
<label class="upload__title form_container">Ingredienten
<span class="error"><?php if(!empty($errors['description'])){ echo $errors['description '];} ?></span>
<input type="text" TextMode="MultiLine" name="ingredienten" maxlength="255" required class="form_field upload__title input" id="ingredienten">
</label>
</div>
<div class="category_container">
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="pasta" name="category" value="1">
Pasta</label>
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="veggie" name="category" value="2">
Veggie</label>
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="vlees" name="category" value="3">
Vlees</label>
</div>
<div class="form-field">
<input type="submit" value="uploaden" class="filter__button filter__submit">
<input type="reset" value="wissen" class="filter__button filter__submit">
</div>
</form>
</section>
<script src="js/validate.js"></script>
What I do know:
I know the recipe_id isn't an issue. I use the same for other SQL inserts.
I don't want an explode() or implode() as they don't work in this case.
Tried several foreaches but haven't gotten it to work, just yet.
it's also nothing to do with brackets or comma's or whatever.
It's just the insert only doing it once while I have 2 checkbox values. and I don't know how to make it loop over both or all 3 when all 3 are selected
<div class="category_container">
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="pasta" name="category[]" value="1">
Pasta</label>
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="veggie" name="category[]" value="2">
Veggie</label>
<label class="category_label filter__button">
<input class="category_input" type="checkbox" id="vlees" name="category[]" value="3">
Vlees</label>
</div>
You need to use category[], rather than just category to send multiple values in form submit.
Now, you can fetch the values of categories
$categories = (is_array($_POST['category'])) ? $_POST['category'] : [];
I have assigned categories a default value if there is no checkbox selected.
Then use implode function of php:
$categories_string = implode(',', $categories);
or use a foreach loop based on how you want to save in your database table:
foreach ($category as $category)
{
//use each category
}
i'm doing a whole new login form in Wordpress.
I can register users but the wp_signon does not work at all.
Users are well registered because i can log them on the classic /wp-admin but not on my custom one.
I have an error like that :
WP_Error Object ( [errors] => Array ( [empty_password] => Array ( [0] => Erreur : le champ du mot de passe est vide. ) ) [error_data] => Array ( ) )
Where "Erreur : le champ du mot de passe est vide." means "Error : the password field is empty".
Here is my code :
<?php
/*
Template Name : Connexion
*/
$error = false;
if(!empty($_POST)) {
$userlog = array(
'user_login' => $_POST['user_login'],
'user_pass' => $_POST['user_password'],
);
$user = wp_signon($userlog);
do_action('init', $user);
if(is_wp_error($user)){
$user->get_error_message();
print_r($user);
}else{
header("Location: /");
};
}
get_header();?>
<div class="main_container">
<div class="container_form">
<h2>Se connecter</h2>
<div class="form_logo">
</div>
<?php if($error) {?>
<div class="error">
<?php echo $error ?>
</div>
<?php } ?>
<form action="<?php echo $_SERVER['REQUEST_URI'];?>" method="POST">
<label for="user_login">Identifiant</label>
<input type="text" name="user_login" id="user_login">
<label for="user_password">Mot de passe</label>
<input type="password" name="user_password" id="user_password">
<div id="button_container">
<input type="submit" name="button1" value="Se connecter" id='save'/>
</div>
</form>
</div>
</div>
<?php get_footer(); ?>
I have tried do call it on init, without init... Lot of things !
Thanks if you can help.
EDIT
The error came from the 'user_pass' it has to be 'user_password' for the wp_signon and 'user_pass' for wp_insert_user
Here is the register page on which the user is registered but not log in.
$error = false;
if(!empty($_POST)) {
if($_POST['user_password'] != $_POST['user_password2']) {
$error = "Les mots de passe ne correspondent pas";
} else {
if(!is_email($_POST['user_email'])) {
$error = "Veuillez entrer un email valide";
} else {
$user = array(
'user_login' => $_POST['user_login'],
'user_pass' => $_POST['user_password'],
'user_email' => $_POST['user_email'],
);
$user_add = wp_insert_user($user);
if (is_wp_error($user_add)) {
$error = $user_add->get_error_message();
} else {
update_field('player_league_of_legends', $_POST['user_login'], 'user_'.$user_add);
$user_login = wp_signon($user);
do_action('template_redirect', $user_login);
if(is_wp_error($user_login)){
$error = $user_login->get_error_message();
} else {
header("Location: /login");
}
}
}
}
}
This code is in index.php?
According to documentation https://developer.wordpress.org/reference/functions/wp_signon/ you must use wp_signon in function.php.
You can also use plugin https://wordpress.org/plugins/custom-login/#developers or by inspired by him
I'm trying to upload an image to my local server but a boolean value is not set in my code .
I include a php file to upload the file and do my checks there .
There is no error during the process but my variable is still not set.
Verification.php
// Verification si une image a été sélectionné :
if(isset($_POST['photo']) && !empty($_POST['photo']))
{
// Upload l'image dans le dossier upload si tout est valide
include_once "upload.php";
$uploaded = true;
}
//$bdd->query('INSERT INTO users(pseudo,email,password,birthday) VALUES(');
$req = $bdd->prepare('INSERT INTO users(pseudo,email,password,DateInscription,Photo) VALUES(:identifiant,:email,:password,NOW(),:photo)');
$req->execute(array(
'identifiant' => $_POST["pseudo"],
'email' => $_POST["email"],
'password' => cryptPassword($_POST["password"]),
'photo' => isset($uploaded) == true ? $directory : "test",
));
Upload.php
$form_name = "photo";
$max_size = 5000000; // = 5 MO
$validExtension = array('png','gif','jpg','jpeg');
$directory = "uploads/" .$_POST["pseudo"];
// Vérification si l'image s'est bien uploadé
if(!isset($_FILES[$form_name]) OR $_FILES[$form_name]['error'] > 0 )
{
$error = "codeerreur : " .$_FILES[$form_name]['error'];
header("Location: http://localhost/serveur_web/inscription.php?error-photo=invalid_upload" .$error);exit;
}
// Vérification si l'image est trop lourde : > 5 MO
if($_FILES[$form_name]['size'] > $max_size) header("Location: http://localhost/serveur_web/inscription.php?error-photo=invalid_size");exit;
// Verification de l'extension de l'image
$imageExtension = substr(strrchr($_FILES[$form_name]['name'],'.'),1);
if(!in_array($imageExtension,$validExtension)) header("Location: http://localhost/serveur_web/inscription.php?error-photo=invalid_extension");exit;
// tout est ok déplacement de l'image dans le dossier
if(!move_uploaded_file($_FILES[$form_name]['tmp_name'],$directory))
{
header("Location: http://localhost/serveur_web/inscription.php?error-photo=move");
exit;
}
This part of the code : isset($uploaded) == true ? $directory : "test" always return : test .
Thank you for help.
EDIT : I already have enctype definition in my html code
<form accept-charset="UTF-8" method="post" action="verif.php?protocol=inscription" enctype="multipart/form-data">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Pseudo" name="pseudo" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="E-mail" name="email" type="text">
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" value="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Confirm Password" name="password_confirm" type="password" value="">
</div>
<div class="form-group">
<input class="form-control" placeholder="Photo de profil" name="photo" type="file" value="">
</div>
<input class="btn btn-lg btn-success btn-block" type="submit" value="Inscription">
</fieldset>
</form>
You have problem in this line
'photo' =>isset($uploaded) == true ? $directory : "test"
change this line to
'photo' =>($uploaded === true) ? $directory : "test";
if $uploaded is set true then it takes $directory value and if it is set to false then it takes "test"
set $upload to false in Verification.php
$uploaded = false;
if(isset($_FILES['photo']) && !empty($_FILES['photo']))
{
include_once "upload.php";
$uploaded = true;
}
I'm using a form on my website using wordpress to allow users to create posts.
It works perfectly fine, I'm abble to assign the posts to a custom post type, add Advanced Custom Fields, content, tags...
What I'm trying to do is to allow the user to also upload images, using the same coding architecture, as it works fine this way since.
User don't have to be registred, so when uploading an image, He'll be abble to browse is computer and then upload the image.
the image should then be saved in my media library and database, and assign to the post.
I want to be abble to assign images to post_tumbnails for example, or to custom fields.
8 new inputs for 8 images in my form.
image_1
image_2, and so on...
like this : , and then being abble to use the image object inside my insert array.
here is my php code :
<?php
if(isset($_POST['submit'])){
$err = array();
$err['status'] = true;
$output = "";
if(empty($_POST['nom'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Nom" ne peut être vide.';
}
if(empty($_POST['prenom'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Nom" ne peut être vide.';
}
if(empty($_POST['telephone'])){
$err['status'] = false;
$err['msg'][] = 'Le champ "Nom" ne peut être vide.';
}
if(empty($_POST['#mail']) || !preg_match('/[a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}/',$_POST['#mail'])){
$err['status'] = false;
$err['msg'][] = 'Le champs "Mail" est mal renseigné';
}
if($err['status']){
$insert = array(
'post_status' => 'publish',
'post_title' => $_POST ['nom'] . ' ' . $_POST ['prenom'],
'post_category' => array(11),
'post_author' => 999,
'tags_input' => htmlentities($_POST['tags']),
'post_type' => 'vendre',
);
$post_id = wp_insert_post($insert);
if($post_id != 0){
/* CUSTOM FIELDS */
update_field('field_546f2983c57ae',htmlentities($_POST['civilite']),$post_id);
update_field('field_546f22db11f3e',htmlentities($_POST['nom']),$post_id);
update_field('field_546f22e011f3f',htmlentities($_POST['prenom']),$post_id);
update_field('field_546f22e611f40',htmlentities($_POST['adresse']),$post_id);
update_field('field_546f22f311f41',htmlentities($_POST['code_postal']),$post_id);
update_field('field_546f230211f42',htmlentities($_POST['ville']),$post_id);
update_field('field_546f230811f43',htmlentities($_POST['pays']),$post_id);
update_field('field_546f230d11f44',htmlentities($_POST['telephone']),$post_id);
update_field('field_546f231611f45',htmlentities($_POST['#mail']),$post_id);
update_field('field_546f232011f46',htmlentities($_POST['localisation']),$post_id);
update_field('field_546f232611f47',htmlentities($_POST['prix_souhaite']),$post_id);
update_field('field_546f233211f48',htmlentities($_POST['description_']),$post_id);
$output = add_post_meta($post_id, "user_meta", json_encode($user_meta_values)) ? 'Article inséré avec succès.' : 'Une erreur est survenue lors de l\enregistrement.' ;
}
}
else{
foreach($err['msg'] as $k=>$v)
$output .= $v . '<br />';
}
}
?>
and my Html :
<form method="post" action="<?php echo site_url().'/vendre'; ?>">
<label class="civilite">M.</label><input type="radio" name="civilite" id="civilite" value="monsieur">
<label class="civilite">Mme</label><input type="radio" name="civilite" id="civilite" value="madame"> <br>
<label for="nom">Nom</label><input type="text" name="nom" id="nom" value="" /><br>
<label for="prenom">Prénom</label><input type="text" name="prenom" id="prenom" value="" /><br>
<label for="adresse">Adresse</label><input type="text" name="adresse" id="adresse" value="" /><br>
<label for="code_postal">Code Postal</label><input type="text" name="code_postal" id="code_postal" value="" /><br>
<label for="ville">Ville</label><input type="text" name="ville" id="ville" value="" /><br>
<label for="pays">Pays</label><input type="text" name="pays" id="pays" value="" /><br>
<label for="telephone">Téléphone</label><input type="text" name="telephone" id="telephone" value="" /><br>
<label for="#mail">#mail</label><input type="text" name="#mail" id="#mail" value="" /><br>
<label for="localisation">Localisation</label><input type="text" name="localisation" id="localisation" value="" /><br>
<label for="prix_souhaite">Prix souhaité</label><input type="text" name="prix_souhaite" id="prix_souhaite" value="" /><br>
<label for="description_">Description rapide de votre bien et commentaires</label><textarea name="description_" id="description_" rows="10" cols="15"></textarea><br>
<p><input type="submit" name="submit" value="envoyer" /></p>
</form>
<div class="ok"><?php echo isset($output) ? $output : '' ; ?></div>
hope someone can help me with this,
thanks a lot
I do a form in html for a little website, i want users to subscribe themselves but my PHP control seems to not work and i don't know why!
My javascript control works but PHP doesn't...
Source:
<!-- HTML -->
<form action="InscriptionSucces.html" method="POST" name="Inscription" onSubmit="return verif(this);">
<h2>Identifiants</h2>
<ul>
<li>Pseudo* : <input type="text" name="pseudo" id="pseudo" size="30" /></li>
<li>Mot de passe* : <input type="password" name="pass" id="pass" size="30" /></li>
<li>Veuillez retaper votre mot de passe* : <input type="password" name="pass2" id="pass2" size="30" /></li>
<li>Adresse mail (valide)* : <input type="text" name="mail" id="mail" size="30" value="" />#
<select name="groupe1" id="groupe1">
<option value="0">Selectionnez votre adresse...</option>
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Veuillez retaper votre adresse mail* : <input type="text" name="mail_verif" id="mail_verif" size="30" value="" />#
<select name="groupe2" id="groupe2">
<option value="0">Selectionnez votre adresse...</option>
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Date de naissance : <input type="text" name="date_naissance" id="date_naissance" size="30" value="" /> <em>(JJ/MM/AAAA)</em></li>
<h5>Les champs signales par * sont obligatoires.</h5>
<li>
<td id="envoyer">
<input type="submit" name="Submit" value="M'inscrire">
</td>
<td id="effacer">
<input type="reset" name="Effacer" >
</td>
</td>
</li>
</form>
Here is my javascript which works:
<script type="text/javascript">
function verif(f)
{
var regnm = /^[a-zàâäéèêëîïôöùûüç0123456789]+((( |-)[a-zàâäéèêëîïôöùûüç]+$)|$)/i;
var regmail = /^[a-z]/i;
if(!regnm.test(f.pseudo.value)) {
alert("Erreur dans la saisie de votre pseudo");
return false;
}
if(!regnm.test(f.pass.value)) {
alert("Erreur dans la saisie de votre mot de passe");
return false;
}
if(f.pass.value != f.pass2.value){
alert("Les mots de passe sont differents");
return false;
}
if(!regmail.test(f.mail.value)){
alert("adresse mail incorrecte");
return false;
}
if(f.mail.value != f.mail_verif.value){
alert("adresses mail differentes");
return false;
}
if (document.getElementById('groupe1').options[0].selected){
alert("Vous avez oublie de mentionner votre adresse mail");
return false;
}
if (document.getElementById('groupe1').value != document.getElementById('groupe2').value){
alert("adresses mail differentes");
return false;
}
return confirm("Vous confirmez l'envoi des donnees?");
}
</script>
PHP Code:
<?php
if(!empty($_POST)) {
$errors = array();
$pseudo=$_POST['pseudo'];
echo $pseudo; // Pseudo
if(!isset($pseudo)){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
} elseif($pseudo == '') {
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
// Mot de passe
if(!isset($_POST['pass'])){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
} elseif($_POST['pass'] == ''){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
// Verif mot de passe
if($_POST['pass2'] =! $_POST['pass']){
$errors[] = 'Les mots de passe sont differents';
} elseif($_POST['mdp_verif'] == ''){
$errors[] = 'Les mots de passe sont differents';
} else if(!isset($_POST['mdp_verif'])){
$errors[] = 'Les mots de passe sont differents';
}
// Adresse mail
if(!isset($_POST['mail'])){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
} elseif($_POST['mail'] == ''){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
// Verif adresse mail
if($_POST['mail_verif'] != $_POST['mail']){
$errors[] = 'Les adresses mail sont differentes';
} elseif($_POST['mail_verif'] == ''){
$errors[] = 'Les adresses mail sont differentes';
} else if(!isset($_POST['mail_verif'])){
$errors[] = 'Les adresses mail sont differentes';
}
// Compte les erreurs
if(count($errors) > 0)
{
echo '<ul>' . PHP_EOL;
for($i=0; $i < count($errors); $i++)
echo '<li>'. $errors[$i] .'.</li>' . PHP_EOL;
echo '<ul>';
}
}
?>
Is it an error in my variables?
with $_POST ?
Thx to help :)
I do this and it works fine. Here i give my edited code for your convenience.
<html>
<head>
<title>form</title>
</head>
<body>
<form action="" method="POST" name="Inscription" onSubmit="return verif(this);">
<h2>Identifiants</h2>
<ul>
<li>Pseudo* : <input type="text" name="pseudo" id="pseudo" size="30" /></li>
<li>Mot de passe* : <input type="password" name="pass" id="pass" size="30" /></li>
<li>Veuillez retaper votre mot de passe* : <input type="password" name="pass2" id="pass2" size="30" /></li>
<li>Adresse mail (valide)* : <input type="text" name="mail" id="mail" size="30" value="" />#
<select name="groupe1" id="groupe1">
<option value="0">Selectionnez votre adresse...
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Veuillez retaper votre adresse mail* : <input type="text" name="mail_verif" id="mail_verif" size="30" value="" />#
<select name="groupe2" id="groupe2">
<option value="0">Selectionnez votre adresse...
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Date de naissance : <input type="text" name="date_naissance" id="date_naissance" size="30" value="" /> <em>(JJ/MM/AAAA)</em></li>
<h5>Les champs signales par * sont obligatoires.</h5>
<li><td id="envoyer">
<input type="submit" name="Submit" value="M'inscrire">
</td>
<td id="effacer">
<input type="reset" name="Effacer" >
</td>
</td></li>
</form>
</body>
<!-- Here is my javascript which works
<script type="text/javascript">
function verif(f)
{
var regnm = /^[a-zàâäéèêëîïôöùûüç0123456789]+((( |-)[a-zàâäéèêëîïôöùûüç]+$)|$)/i;
var regmail = /^[a-z]/i;
if(!regnm.test(f.pseudo.value))
{
alert("Erreur dans la saisie de votre pseudo");
return false;
}
if(!regnm.test(f.pass.value))
{
alert("Erreur dans la saisie de votre mot de passe");
return false;
}
if(f.pass.value != f.pass2.value){
alert("Les mots de passe sont differents");
return false;
}
if(!regmail.test(f.mail.value)){
alert("adresse mail incorrecte");
return false;
}
if(f.mail.value != f.mail_verif.value){
alert("adresses mail differentes");
return false;
}
if (document.getElementById('groupe1').options[0].selected){
alert("Vous avez oublie de mentionner votre adresse mail");
return false;
}
if (document.getElementById('groupe1').value != document.getElementById('groupe2').value){
alert("adresses mail differentes");
return false;
}
return confirm("Vous confirmez l'envoi des donnees?");
}
</script>
-->
<?php if(!empty($_POST))
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
$errors = array();
$pseudo=$_POST['pseudo'];
echo $pseudo;
if(!isset($pseudo)){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
elseif($pseudo == ''){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
if(!isset($_POST['pass'])){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
elseif($_POST['pass'] == ''){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
// Verif mot de passe
if($_POST['pass2'] =! $_POST['pass']){
$errors[] = 'Les mots de passe sont differents';
}
elseif($_POST['mdp_verif'] == ''){
$errors[] = 'Les mots de passe sont differents';
}
else if(!isset($_POST['mdp_verif'])){
$errors[] = 'Les mots de passe sont differents';
}
if(!isset($_POST['mail'])){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
elseif($_POST['mail'] == ''){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
// Verif adresse mail
if($_POST['mail_verif'] != $_POST['mail']){
$errors[] = 'Les adresses mail sont differentes';
}
elseif($_POST['mail_verif'] == ''){
$errors[] = 'Les adresses mail sont differentes';
}
else if(!isset($_POST['mail_verif'])){
$errors[] = 'Les adresses mail sont differentes';
}
// Compte les erreurs
if(count($errors) > 0)
{
echo '<ul>' . PHP_EOL;
for($i=0; $i < count($errors); $i++)
echo '<li>'. $errors[$i] .'.</li>' . PHP_EOL;
echo '<ul>';
}
}
?>
First: PHP code must be enclosed with <?php .. ?> tags.
Second: seems that file you posted here is *.html file. It either needs to be *.php file or have the webserver configured to parse html files as .php
In the form tag you use InscriptionSucces.html. Instead, you must use the name InscriptionSucces.php, and your filename must be InscriptionSucces.php.
When you use any PHP code, you must use the correct start and end syntax: <?php and ?>.