naspy971
naspy971

Reputation: 1381

Getting $_POST empty string although the input is filled

I'm submitting a form in POST method which initially sends an email with the form informations. The issue here is that when filling the email input and trying to var_dump it, all I get is string(0) "" and I can't figure out why.

Here's the form :

 <form id="form" class="form" name="postuler" method="post" action="/sources/site/composants/recrutement/receive.php" enctype="multipart/form-data" novalidate>

    <div style="width:auto; float:left; padding-left:15px;">
            <label for="nom">Votre nom <span class="required">*</span></label>
            <input type="text" class="nom" placeholder="ex: Doe" name="nom" id="nom" maxlength="40" required="required"/>
            <br/> 

      <div class="not-hidden">
       <label for="mail">Adresse e-mail <span class="required">*</span></label>
       <input type="email" class="email" placeholder="ex: [email protected]" name="mail" id="email" maxlength="40" required="required"/>
      </div>
      <div class="hidden-fields">   
            <label for="prenom">Votre prénom <span class="required">*</span></label>
            <input type="text" class="prenom" placeholder="ex: John" name="prenom" id="nom" maxlength="40"  required="required"/>
       </div>
   </div>
   <div style="width:auto; float:left; padding-left:15px">    

        <div class="not-hidden">
            <label for="prenom">Votre prénom <span class="required">*</span></label>
            <input type="text" class="prenom" placeholder="ex: John" name="prenom" id="nom" maxlength="40" required="required"/>
        </div>

            <div class="hidden-fields"> 
            <label for="mail">Adresse e-mail <span class="required">*</span></label>
            <input type="email" class="email" placeholder="ex: [email protected]" name="mail" id="email" maxlength="40" required="required"/> 
            </div>
            <input type="submit" name="upload" id="envoyez" value="Valider"  class="postu"/>
        </form>

I tried to debug the mail variable with :

if(isset($_POST['mail'])){
    var_dump($_POST['mail']);
} else {
    echo 'Did not receive var, sorry';
}

Upvotes: 1

Views: 1326

Answers (2)

Kostas Banys
Kostas Banys

Reputation: 11

From the code that you posted i see that the problem could be that your form has two input fields with same name, you have to have different names for them. Maybe you just thought it's something like input type "radio". Look here for correct information how to deal with forms and their names: All information you need about forms and their inputs

But also the question is why you haven't posted where the form begins because we can understand your code wrong or something. Because you form closing tag is inside a div which has no form start tag.

Upvotes: 1

Aref Ben Lazrek
Aref Ben Lazrek

Reputation: 1064

That's because you'r using duplicated input name mail

Upvotes: 0

Related Questions