IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[PHP-JS] Convertir une variable javascript en php


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 58
    Points : 47
    Points
    47
    Par défaut [PHP-JS] Convertir une variable javascript en php
    salut à tous,
    J'ai une variable dans une fonction qui est excuter par rapport au clic d'un lien.
    C'est une variable qui s'incremente...
    Seulement, je ne vois pas du tout comment reccuper cette valeur...
    Connaissez vous une solution?

    Cette variable en fait doit etre poster ensuite pour une BD.
    mais je connai le "post" en javascript
    merci d'avance

  2. #2
    Membre régulier Avatar de a_me
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2004
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 84
    Points : 80
    Points
    80
    Par défaut
    je n'aipas bien compris ton problème, tu peux éclaicir un peu plus
    --- Silence of the Bones ---

  3. #3
    Membre confirmé Avatar de mathieugamin
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    572
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 572
    Points : 627
    Points
    627
    Par défaut
    salut,
    peux-tu mettre le code STP?
    GAMIN !!!!
    _______________________________________________
    PHP 5.2 | Apache 2 | MySQL 5 | WinXP Pro | Mac OSX

  4. #4
    Membre régulier
    Inscrit en
    Août 2005
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 177
    Points : 73
    Points
    73
    Par défaut
    Je crois avoir compris ce qu'il veux dire. Je prends un autre exemple : avec un code javascript, je peux savoir par exemple la résolution de l'écran du client. J'aurais donc un variable dans mon code javascript m'indiquant cette valeur. Mais dès que je ferme ma balise <script>, ma variable est détruite (normal, c'était une variable javascript). Si j'ai bien compris, roxxxy voudrait savoir comment récupérer la valeur de cette variable, pour l'utiliser dans son code php.

    Ai-je été clair?

  5. #5
    Membre expérimenté

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    1 138
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 138
    Points : 1 504
    Points
    1 504
    Par défaut
    Je vois pas trop comment c'est possible, car php c'est coté serveur et javascript c'est coté client.
    Une fois la page généré par le serveur c'est fini et il n'y a plus que javascript qui rentre en jeu donc il me semble, sauf erreur de ma part, que ce n'est pas possible.

  6. #6
    Membre expérimenté

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    1 138
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Octobre 2002
    Messages : 1 138
    Points : 1 504
    Points
    1 504
    Par défaut
    Je vais quand meme préciser quelque chose, il est possible de récupérer cette variable, mais pas directement.
    Tu peux utiliser HttpRequest et la technologie ajax pour y parvenir (ton code javascript va appeler un script php qui recevra tes variables javascript en parametre).
    Tu peux aussi te tourner vers des solutions moins élégantes comme le rechargement de la page en javascript avec en paramentre les valeurs javascripts ou encore des champs hidden que tu recuperas via un formulaire ou autres encore.

  7. #7
    Membre régulier
    Inscrit en
    Août 2005
    Messages
    177
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 177
    Points : 73
    Points
    73
    Par défaut
    Oui en effet, je viens justement de me documenter un peu sur la mode AJAX, et j'ai vu qu'il était possible d'utiliser des fonctions php via cette "technologie" (qui n'en est pas une, je le sais bien)

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 58
    Points : 47
    Points
    47
    Par défaut
    le probleme c que c pour un formulaire...
    Donc il faut pas que ma page se raffraichisse, sinon le formulaire redevient vide
    C'est en realité un probleme de nombres de dates ajoutés par rapport a un calendrier. Si l'utilisateur veut ajouter plusieurs dates, j'ai creer un lien qui rajoute un champs pour ajouter ces nouvelles dates.
    Il me faudrait savoir en fait combien de dates ont été saisies...
    Donc jai une variable qui sincremente dans ma partie javascript...
    mais comment reccuper cette variable en javascript pour la poster comme les autres variables?
    Je ne vois que cette solution la tranformer en var php.
    Comment faire avec des champs hidden?
    merci pour votre attention en tout cas

  9. #9
    Membre confirmé Avatar de mathieugamin
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    572
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 572
    Points : 627
    Points
    627
    Par défaut
    un champ hidden pourrait être la solution ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <?php
     
    if (isset($_POST['test']) && $_POST['test'] != ""){
    	echo $_POST['test'].'</ br>';
    }
    ?>
     
    <html>
    <head>
    <title>Test form</title>
    <script type="text/javascript">
    i = 0;
    function inc(){
    	i++;
    	document.form.test.value = i;
    }
    </script>
    </head>
    <body>
     
    <a href="#" onclick="javascript:inc()">clic</a><br>
     
    <form name="form" method="POST" action="">
    	<input type="hidden" name="test" />
    	<input type="submit">
    </form>
    </body>
    </html>
    C'est ce genre de truc ?
    GAMIN !!!!
    _______________________________________________
    PHP 5.2 | Apache 2 | MySQL 5 | WinXP Pro | Mac OSX

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 58
    Points : 47
    Points
    47
    Par défaut excatement...
    J'ai essayer ton code...
    ca aurait du marcher...
    mais ca march' po
    si je l'essai sur firefox il maffiche avant ton lien clic: ";} ?>
    a moins que jai pas su reperer lerreur, mais je vois rien la...
    jessayerai dici demain sur un autre ordi

  11. #11
    Membre confirmé Avatar de mathieugamin
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    572
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 572
    Points : 627
    Points
    627
    Par défaut
    Salut,
    peux-tu poster ton code, ça ira sûrement plus vite...
    Merci
    GAMIN !!!!
    _______________________________________________
    PHP 5.2 | Apache 2 | MySQL 5 | WinXP Pro | Mac OSX

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 58
    Points : 47
    Points
    47
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    <?php session_start();
    $_SESSION['type']=$_POST["type"];
    $_SESSION['pays']=$_POST["pays"];
    $_SESSION['duree']=$_POST["duree"];
    $_SESSION['i']=1;
    $type=$_POST["type"];
    $pays=$_POST["pays"];
    $reg=$_POST["duree"];
    ?>
    
    <html>
    <head>
    <title>Tout Tango  : Formulaire</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script>
    var i2;
    function create_champ(i) {
    i2 = i + 1;
    
    document.getElementById('leschamps_'+i).innerHTML = '<input onclick="ds_sh(this);" name="date_'+i+'" readonly="readonly" style="cursor: text" /></span>';
    
    document.getElementById('leschamps_'+i).innerHTML += (i <= 10) ? '<br /><span id="leschamps_'+i2+'"><a href="javascript:create_champ('+i2+')">Ajouter une date</a></span><br/>' : '';
    
    }
    function fin()
    {
    window.close();
    }
    </script>
    </head>
    
    <body>
    
    <form method ="post" action="http:veriform.php" enctype="multipart/form-data"> 
    
    
    <table>
    
    <?php
    if ($type=="evenement"){
    ?>
    <tr><td>Evènements
    <select name="type" size="1">
    <option selected value="0">- Choisir - </option>
    <option value="Concert">Concert</option>
    <option value="Bal">Bal</option>
    <option value="Spectacle">Spectacle</option>
    <option value="Conf&eacute;rence">Conf&eacute;rence</option>
    <option value="D&eacute;bat">D&eacute;bat</option>
    <option value="Rencontre">Rencontre</option>
    <option value="Cin&eacute;ma">Cin&eacute;ma</option>
    <option value="Photo">Photo</option>
    <option value="Peinture">Peinture</option>
    <option value="Autre...">Autres...</option>
    </select><br/><br/>
    <?}
    ?>
    
    <tr><td>Titre </td> 
    <td><input type="text" name="titre" size="20" ></td></tr>
    
    <tr><td>Informations </td>
    <td><textarea rows="10" name="info" cols="40" ></textarea></td></tr>
    
    <tr><td>Photo </td>
    <td><input type="file" size=60 name="photo" /></p></td></tr>
    
    <table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
    <tr><td id="ds_calclass">
    </td></tr>
    
    <tr><td>Dates </td>
    <td><input onclick="ds_sh(this);" name="date_1" readonly="readonly" style="cursor: text" /></td></tr>
    <tr><td></td><td><span id="leschamps_1"><a href="javascript:create_champ(1)" >Ajouter une date</a></span></td></tr>
    
    
    <td>Exception</td>
    <td><textarea rows="3" name="except" cols="40" ></textarea></td></tr>
    
    <?php
    if ($type=="evenement" or $type=="milongas")
    {
    ?>
    <tr><td>Horaires</td><td><input type="text" name="horaire" size="20" ></td></tr>
    <tr><td>Prix</td><td><input type="text" name="prix" size="5" > E</td></tr>
    
    <?
    }
    ?>
    
    <!--etc...la suite d'un formulaire-->
    </table>
    
    <center><input type="submit" name="valider" value="valider"/>
    
    <input onClick="javascript:fin();return false;" type="submit" name="annuler" value="annuler"/>
    
    </center>
    
    </body>
    </html>


    Voila le code, merci

  13. #13
    Membre confirmé Avatar de mathieugamin
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    572
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 572
    Points : 627
    Points
    627
    Par défaut
    Désolé mais je vois pas mon code.

    Peux-tu aussi utiliser les balises de Code (le # dans la barre d'outils quand tu rédiges ton message).

    Merci
    GAMIN !!!!
    _______________________________________________
    PHP 5.2 | Apache 2 | MySQL 5 | WinXP Pro | Mac OSX

  14. #14
    Membre régulier Avatar de a_me
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2004
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Novembre 2004
    Messages : 84
    Points : 80
    Points
    80
    Par défaut
    essaie cette petite idée:
    les champs text des dates, écrit les sous cette façon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <input type="text" id="date_x" name="dates[]" />
    où x est le numéro qui change à chaque fois que l'utilisateur ajoute une date.
    cela te permettera de faire les test javascript pour la validation des données de cez zones en utilisant la valeur de l'attribut "id".
    d'autre part aussi, tu pourras récupérer les valeurs des dates saisies dans un tableau avec php grace à la valeur de l'attribut "name".
    dans l'exemple ci-dessus, le nom de la variable tableau contenant les dates est:
    et de cette façon c simple de savoir le nombre de dates (donc de zones de dates du formulaire) en fesant un simple:
    --- Silence of the Bones ---

  15. #15
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    58
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 58
    Points : 47
    Points
    47
    Par défaut
    Finalement,j'trouvé une solution.
    J'ai voulu utiliser un calendrier dans un formulaire, qui me sort une date.
    Je peux en rajouter autant que jen veux:
    les exemples que jai utiliser sont sur
    http://www.toulouse-renaissance.net/...formulaire.htm (pour afficher un calendrier quand on clique sur un champs)
    J'ai ensuite creer un lien Ajouter une date pour creer un nouveau champs pour saisir une nouvelle date. Le but de tout ceci été de reccuperer toutes les dates au format 12/02/2003 par exemple, et de les enregistrer dans ma base de données au format Lundi 12 Février 2003 par ex.

    Voila ma solution :
    "nom de votre fichier".php


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    <html>
    <head>
    <title>Formulaire</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     
    <!--couleurs pour le calendrier-->
    <style type="text/css">
     
    .ds_box {
    	background-color: #FFF;
    	border: 1px solid #000;
    	position: absolute;
    	z-index: 32767;
    }
     
    .ds_tbl {
    	background-color: #66CCFF;
    }
     
    .ds_head {
    	background-color: #000066;
    	color: #FFF;
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 11px;
    	font-weight: bold;
    	text-align: center;
    	letter-spacing: 1px;
    }
     
    /*Couleur de fond des jours (lundi,mardi etc.) */
    .ds_subhead {
    	background-color: #003399;
    	color: #FFF;
    	font-size: 10px;
    	font-weight: bold;
    	text-align: center;
    	font-family: Arial, Helvetica, sans-serif;
    	width: 10px;
    }
     
    /*couleur des numeros de jours*/
    .ds_cell {
    	background-color: #99CCFF;
    	color: #000;
    	font-size: 11px;
    	text-align: center;
    	font-family: Arial, Helvetica, sans-serif;
    	padding: 3px;
    	cursor: pointer;
    }
     
    .ds_cell:hover {
    	background-color: #FFF;
    } /* This hover code won't work for IE */
     
    </style>
     
    <script type="text/javascript">
     
    /*fonction pour rajouter un nouveau champs ainsi qu'un nouveau lien*/
    var i2;
    function create_champ(i) {
    i2 = i + 1;
     
    document.getElementById('leschamps_'+i).innerHTML = '<input onclick="ds_sh(this);" name="date_'+i+'" readonly="readonly" style="cursor: text" /></span>';
     
    document.getElementById('leschamps_'+i).innerHTML += (i <= 10) ? '<br /><span id="leschamps_'+i2+'"><a href="javascript:create_champ('+i2+')">Ajouter une date</a></span><br/>' : '';
     
    }
     
    /* Pour le calendrier*/
    // if two digit year input dates after this year considered 20 century.
    var NUM_CENTYEAR = 30;
    // is time input control required by default
    var BUL_TIMECOMPONENT = false;
    // are year scrolling buttons required by default
    var BUL_YEARSCROLL = true;
     
    var calendars = [];
    var RE_NUM = /^\-?\d+$/;
     
    function calendar1(obj_target) {
     
    	// assigning methods
    	this.gen_date = cal_gen_date1;
    	this.gen_time = cal_gen_time1;
    	this.gen_tsmp = cal_gen_tsmp1;
    	this.prs_date = cal_prs_date1;
    	this.prs_time = cal_prs_time1;
    	this.prs_tsmp = cal_prs_tsmp1;
    	this.popup    = cal_popup1;
     
    	// validate input parameters
    	if (!obj_target)
    		return cal_error("Error calling the calendar: no target control specified");
    	if (obj_target.value == null)
    		return cal_error("Error calling the calendar: parameter specified is not valid target control");
    	this.target = obj_target;
    	this.time_comp = BUL_TIMECOMPONENT;
    	this.year_scroll = BUL_YEARSCROLL;
     
    	// register in global collections
    	this.id = calendars.length;
    	calendars[this.id] = this;
    }
     
    function cal_popup1 (str_datetime) {
    	if (str_datetime) {
    		this.dt_current = this.prs_tsmp(str_datetime);
    	}
    	else {
    		this.dt_current = this.prs_tsmp(this.target.value);
    		this.dt_selected = this.dt_current;
    	}
    	if (!this.dt_current) return;
     
    	var obj_calwindow = window.open(
    		'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
    		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
    		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
    	);
    	obj_calwindow.opener = window;
    	obj_calwindow.focus();
    }
     
    // timestamp generating function
    function cal_gen_tsmp1 (dt_datetime) {
    	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
    }
     
    // date generating function
    function cal_gen_date1 (dt_datetime) {
    	return (
    		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "-"
    		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
    		+ dt_datetime.getFullYear()
    	);
    }
    // time generating function
    function cal_gen_time1 (dt_datetime) {
    	return (
    		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
    		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
    		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
    	);
    }
     
    // timestamp parsing function
    function cal_prs_tsmp1 (str_datetime) {
    	// if no parameter specified return current timestamp
    	if (!str_datetime)
    		return (new Date());
     
    	// if positive integer treat as milliseconds from epoch
    	if (RE_NUM.exec(str_datetime))
    		return new Date(str_datetime);
     
    	// else treat as date in string format
    	var arr_datetime = str_datetime.split(' ');
    	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
    }
     
    // date parsing function
    function cal_prs_date1 (str_date) {
     
    	var arr_date = str_date.split('-');
     
    	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
    	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
    	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
    	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
    	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
    	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
    	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");
     
    	var dt_date = new Date();
    	dt_date.setDate(1);
     
    	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
    	dt_date.setMonth(arr_date[1]-1);
     
    	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
    	dt_date.setFullYear(arr_date[2]);
     
    	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
    	dt_date.setDate(arr_date[0]);
    	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");
     
    	return (dt_date)
    }
     
    // time parsing function
    function cal_prs_time1 (str_time, dt_date) {
     
    	if (!dt_date) return null;
    	var arr_time = String(str_time ? str_time : '').split(':');
     
    	if (!arr_time[0]) dt_date.setHours(0);
    	else if (RE_NUM.exec(arr_time[0]))
    		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
    		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
    	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
     
    	if (!arr_time[1]) dt_date.setMinutes(0);
    	else if (RE_NUM.exec(arr_time[1]))
    		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
    		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
    	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");
     
    	if (!arr_time[2]) dt_date.setSeconds(0);
    	else if (RE_NUM.exec(arr_time[2]))
    		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
    		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
    	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");
     
    	dt_date.setMilliseconds(0);
    	return dt_date;
    }
     
    function cal_error (str_message) {
    	alert (str_message);
    	return null;
    }
     
     
    </script>
     
    </head>
     
    <body>
     
    <form method ="post" name="formulaire" action="veriform.php" enctype="multipart/form-data" > 
    <!--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-->
     
     
    <!--Tableau formant le calendrier-->
     
    <table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
    <tr><td id="ds_calclass">
    </td></tr>
    </table>
     
    <script type="text/javascript">
    // <!-- <![CDATA[
     
    // Project: Dynamic Date Selector (DtTvB) - 2006-03-16
    // Script featured on JavaScript Kit- <a href="http://www.javascriptkit.com" target="_blank">http://www.javascriptkit.com</a>
    // Code begin...
    // Set the initial date.
     
    //tous scripts concernant le calendrier
     
    var ds_i_date = new Date();
    ds_c_month = ds_i_date.getMonth() + 1;
    ds_c_year = ds_i_date.getFullYear();
     
    // Get Element By Id
    function ds_getel(id) {
    	return document.getElementById(id);
    }
     
    // Get the left and the top of the element.
    function ds_getleft(el) {
    	var tmp = el.offsetLeft;
    	el = el.offsetParent
    	while(el) {
    		tmp += el.offsetLeft;
    		el = el.offsetParent;
    	}
    	return tmp;
    }
    function ds_gettop(el) {
    	var tmp = el.offsetTop;
    	el = el.offsetParent
    	while(el) {
    		tmp += el.offsetTop;
    		el = el.offsetParent;
    	}
    	return tmp;
    }
     
    // Output Element
    var ds_oe = ds_getel('ds_calclass');
    // Container
    var ds_ce = ds_getel('ds_conclass');
     
    // Output Buffering
    var ds_ob = ''; 
    function ds_ob_clean() {
    	ds_ob = '';
    }
    function ds_ob_flush() {
    	ds_oe.innerHTML = ds_ob;
    	ds_ob_clean();
    }
    function ds_echo(t) {
    	ds_ob += t;
    }
     
    var ds_element; // Text Element...
     
    var ds_monthnames = [
    'Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin',
    'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre'
    ]; // You can translate it for your language.
     
    var ds_daynames = [
    'Dim', 'Lun', 'Mar', 'Me', 'Jeu', 'Ven', 'Sam'
    ]; // You can translate it for your language.
     
    // Calendar template
    function ds_template_main_above(t) {
    	return '<table cellpadding="3" cellspacing="1" class="ds_tbl">'
    	     + '<tr>'
    		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_py();">&lt;&lt;</td>'
    		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_pm();">&lt;</td>'
    		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_hi();" colspan="3">[Fermer]</td>'
    		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_nm();">&gt;</td>'
    		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_ny();">&gt;&gt;</td>'
    		 + '</tr>'
    	     + '<tr>'
    		 + '<td colspan="7" class="ds_head">' + t + '</td>'
    		 + '</tr>'
    		 + '<tr>';
    }
     
    function ds_template_day_row(t) {
    	return '<td class="ds_subhead">' + t + '</td>';
    	// Define width in CSS, XHTML 1.0 Strict doesn't have width property for it.
    }
     
    function ds_template_new_week() {
    	return '</tr><tr>';
    }
     
    function ds_template_blank_cell(colspan) {
    	return '<td colspan="' + colspan + '"></td>'
    }
     
    function ds_template_day(d, m, y) {
    	return '<td class="ds_cell" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + d + '</td>';
    	// Define width the day row.
    }
     
    function ds_template_main_below() {
    	return '</tr>'
    	     + '</table>';
    }
     
    // This one draws calendar...
    function ds_draw_calendar(m, y) {
    	// First clean the output buffer.
    	ds_ob_clean();
    	// Here we go, do the header
    	ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y));
    	for (i = 0; i < 7; i ++) {
    		ds_echo (ds_template_day_row(ds_daynames[i]));
    	}
    	// Make a date object.
    	var ds_dc_date = new Date();
    	ds_dc_date.setMonth(m - 1);
    	ds_dc_date.setFullYear(y);
    	ds_dc_date.setDate(1);
    	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
    		days = 31;
    	} else if (m == 4 || m == 6 || m == 9 || m == 11) {
    		days = 30;
    	} else {
    		days = (y % 4 == 0) ? 29 : 28;
    	}
    	var first_day = ds_dc_date.getDay();
    	var first_loop = 1;
    	// Start the first week
    	ds_echo (ds_template_new_week());
    	// If sunday is not the first day of the month, make a blank cell...
    	if (first_day != 0) {
    		ds_echo (ds_template_blank_cell(first_day));
    	}
    	var j = first_day;
    	for (i = 0; i < days; i ++) {
    		// Today is sunday, make a new week.
    		// If this sunday is the first day of the month,
    		// we've made a new row for you already.
    		if (j == 0 && !first_loop) {
    			// New week!!
    			ds_echo (ds_template_new_week());
    		}
    		// Make a row of that day!
    		ds_echo (ds_template_day(i + 1, m, y));
    		// This is not first loop anymore...
    		first_loop = 0;
    		// What is the next day?
    		j ++;
    		j %= 7;
    	}
    	// Do the footer
    	ds_echo (ds_template_main_below());
    	// And let's display..
    	ds_ob_flush();
    	// Scroll it into view.
    	ds_ce.scrollIntoView();
    }
     
    // A function to show the calendar.
    // When user click on the date, it will set the content of t.
    function ds_sh(t) {
    	// Set the element to set...
    	ds_element = t;
    	// Make a new date, and set the current month and year.
    	var ds_sh_date = new Date();
    	ds_c_month = ds_sh_date.getMonth() + 1;
    	ds_c_year = ds_sh_date.getFullYear();
    	// Draw the calendar
    	ds_draw_calendar(ds_c_month, ds_c_year);
    	// To change the position properly, we must show it first.
    	ds_ce.style.display = '';
    	// Move the calendar container!
    	the_left = ds_getleft(t);
    	the_top = ds_gettop(t) + t.offsetHeight;
    	ds_ce.style.left = the_left + 'px';
    	ds_ce.style.top = the_top + 'px';
    	// Scroll it into view.
    	ds_ce.scrollIntoView();
    }
     
    // Hide the calendar.
    function ds_hi() {
    	ds_ce.style.display = 'none';
    }
     
    // Moves to the next month...
    function ds_nm() {
    	// Increase the current month.
    	ds_c_month ++;
    	// We have passed December, let's go to the next year.
    	// Increase the current year, and set the current month to January.
    	if (ds_c_month > 12) {
    		ds_c_month = 1; 
    		ds_c_year++;
    	}
    	// Redraw the calendar.
    	ds_draw_calendar(ds_c_month, ds_c_year);
    }
     
    // Moves to the previous month...
    function ds_pm() {
    	ds_c_month = ds_c_month - 1; // Can't use dash-dash here, it will make the page invalid.
    	// We have passed January, let's go back to the previous year.
    	// Decrease the current year, and set the current month to December.
    	if (ds_c_month < 1) {
    		ds_c_month = 12; 
    		ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
    	}
    	// Redraw the calendar.
    	ds_draw_calendar(ds_c_month, ds_c_year);
    }
     
    // Moves to the next year...
    function ds_ny() {
    	// Increase the current year.
    	ds_c_year++;
    	// Redraw the calendar.
    	ds_draw_calendar(ds_c_month, ds_c_year);
    }
     
    // Moves to the previous year...
    function ds_py() {
    	// Decrease the current year.
    	ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
    	// Redraw the calendar.
    	ds_draw_calendar(ds_c_month, ds_c_year);
    }
     
    // Format the date to output.
    function ds_format_date(d, m, y) {
    	// 2 digits month.
    	m2 = '00' + m;
    	m2 = m2.substr(m2.length - 2);
    	// 2 digits day.
    	d2 = '00' + d;
    	d2 = d2.substr(d2.length - 2);
    	// YYYY-MM-DD
    	//return y +'/' + m2 + '/' + d2;
     
     
    	return d2 + '/' + m2 + '/' + y;
    }
     
    // When the user clicks the day.
    function ds_onclick(d, m, y) {
    	// Hide the calendar.
    	ds_hi();
    	// Set the value of it, if we can.
    	if (typeof(ds_element.value) != 'undefined') {
    		ds_element.value = ds_format_date(d, m, y);
    	// Maybe we want to set the HTML in it.
    	} else if (typeof(ds_element.innerHTML) != 'undefined') {
    		ds_element.innerHTML = ds_format_date(d, m, y);
    	// I don't know how should we display it, just alert it to user.
    	} else {
    		alert (ds_format_date(d, m, y));
    	}
    }
     
     
    // And here is the end.
     
    // ]]> -->
    </script>
    <table>
     
    <tr><td>Dates * </td>
     
    <td><input onclick="ds_sh(this);" name="date_0" readonly="readonly" style="cursor: text" /></td></tr>
    <tr><td></td><td><span id="leschamps_1"><a href="javascript:create_champ(1)" >Ajouter une date</a></span></td></tr>
     
     
    <br/>
    <br/>
    <tr><td></td><td><center><input type="submit" name="valider" value="valider"/></center></td></tr>
     
    </form>
    </body>
    </html>

    Et le deuxieme fichier pour reccuper combien de champs dates on était reccuper, et transformer ainsi ces dates avant de faire la requete : veriform.php



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Validation annonce</title>
    </head>
    <body>
    <?php
    //toutes les informations saisies sont mis en variables
     
    $i=0;
    while ($_POST['date_'.$i]!="")
    {
    $dt=$_POST['date_'.$i];
    $joursem = array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
    // extraction des jour, mois, an de la date
    list($jour, $mois, $annee) = explode('/', $dt);
    // calcul du timestamp
    $timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
    // affichage du jour de la semaine
    $ms= array('Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre');
     
    if ($mois== "01")$mois="Janvier";
    else if ($mois== "02")$mois="F&eacute;vrier";
    else if ($mois==  "03")$mois="Mars";
    else if ($mois==  "04")$mois="Avril";
    else if ($mois==  "05")$mois="Mai";
    else if ($mois==  "06")$mois="Juin";
    else if ($mois==  "07")$mois="Juillet";
    else if ($mois==  "08")$mois="Aout";
    else if ($mois==  "09")$mois="Septembre";
    else if ($mois==  "10")$mois="Octobre";
    else if ($mois==  "11")$mois="Novembre";
    else if ($mois==  "12")$mois="D&eacute;cembre";
     
    $dates= $dates.$joursem[date("w",$timestamp)]." ".$jour." ".$mois." ".$annee.", ";
    ++$i;
     
    }
    echo "voici les dates : ".$dates;
    }
     
    //apres il suffit d'executer votre requete
    ?>
    </body>
    </html>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [PHP-JS] Récupérer une variable Javascript en PHP
    Par Gamil dans le forum Langage
    Réponses: 3
    Dernier message: 07/12/2007, 13h40
  2. Réponses: 2
    Dernier message: 05/05/2007, 23h11
  3. [PHP-JS] Passer une variable javascript en php
    Par bibom dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 11/08/2006, 20h39
  4. [PHP-JS] recuperer une variable javascript dan php
    Par hammag dans le forum Langage
    Réponses: 2
    Dernier message: 07/08/2006, 14h00
  5. [PHP-JS] Transmettre une variable javascript vers php
    Par phpaide dans le forum Général JavaScript
    Réponses: 11
    Dernier message: 20/05/2006, 08h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo