<?php
require_once('template_header.php');
?>

<section>
<div id="response"></div>
<div><a href="index.php">Se connecter</a></div>
</section>

<section>
<!-- 'create identite' html form -->
<form id="form_signup" action="#" method="POST" >
        <div>
            <label>Login</label>
            <input type='text' id='login' name='login' class="form-control" required />
        </div>

        <div>
            <label>Password</label>
            <input type='text' id='password' name='password' class="form-control"  required />
        </div>

        <div>
            <label>Pseudo</label>
            <input type='text' id='pseudo' name='pseudo' class="form-control" required/>
        </div>

        <div>
            <label>Âge</label>
            <input type='text' id='age' name='age' class="form-control" required />
        </div>

        <div>
            <label>Poids(kg)</label>
            <input type='text' id='poids' name='poids' class="form-control" required/>
        </div>

        <div>
            <label>Taille(cm)</label>
            <input type='text' id='taille' name='taille' class="form-control" required/>
        </div>
       
        <div class="form-group">
            <label>Sexe</label>
            <select class="form-control" id="sexe" name="sexe">
            <option selected>Choisir...</option>
            <option>Femme</option>
            <option>Homme</option>
        </select>
        </div>

        <div class="form-group">
            <label>Niveau de sport</label>
            <select class="form-control" id="niveaudusport" name="niveaudusport">
            <option selected>Choisir...</option>
            <option>Bas</option>
            <option>Moyen</option>
            <option>Elevé</option>
        </select>
        </div>

        <!-- button to submit form -->
        </div>
            <div  class="form-action-buttons">
            <input type="submit" value="Créer">
        </div>
</form>



<script
    src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
    crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-serialize-object/2.5.0/jquery.serialize-object.min.js" ></script>

<script type="text/javascript">

$(document).ready( function($) {
    // will run if create identite form was submitted
    $(document).on('submit', '#form_signup', function(){
        // get form data
        var form_data=JSON.stringify($(this).serializeObject());
        // console.log(form_data);

        // submit form data to api
        $.ajax({
            url: "https://eden.imt-lille-douai.fr/~liang.wu/API_LOGIN/identite/create.php",
            type : "POST",
            contentType : 'application/json',
            data : form_data,
            success : function(result){
            $('#response').html("<div class='alert alert-danger'>success.</div>");
                
            },
            error: function(xhr, resp, text){
            // on error, tell the user login has failed & empty the input boxes
            $('#response').html("<div class='alert alert-danger'>failed</div>");
            login_form.find('input').val('');
            }



        });
    });
});
</script>

</section>

<?php
    require_once('template_footer.php');
?>
