Comparaison de deux dates puis validation.

More
12 years 11 months ago #36298 by seabird
Bonjour,

J'ai un article avec deux champs dates (date_debut et date_fin).
J'ai fait un plugin onAfterSaveItem afin que date_debut et date_fin paramètrent le début de publication et la fin de publication de l'article.

Avant d'enregistrer l'article, je compare également mes deux dates (en utilisant onBeforeSaveItem) pour être sur que date_debut soit inférieur à date_fin, sinon on reste sur le formulaire .
Jusque là pas de problème cela fonctionne.

J'ai juste un petit souci. Comment rester sur le formulaire si date_debut > date_fin. J'avais pensé à header('location:url formulaire');
Mais il y a peut-être une autre solution ?

Merci .

Eric

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36300 by ggppdk
No, you should use:
Code:
if( $date_debut > $date_fin ) { echo "<script>alert ('Please enter correct dates , bla bla bla ...');"; echo "window.history.back();"; echo "</script>"; jexit(); }
This way the user -NEWLY- entered data will not be lost , and user will not have to retype them

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36320 by seabird
Thanks the plugin works correctly.

Eric

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36325 by micker
pense à partager cela pourrait être intéressant pour la communauté
Merci

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36326 by seabird
Oui oui c'est prévu. Je fais un peu le ménage dans le plugin. J'envois ca cet aprem

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36328 by micker
cool merci

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36351 by seabird
Mince je viens de remarquer un problème que je n'avais pas vu ce matin.
Si date_debut < date_fin j'ai bien redirection vers le formulaire apres le message d'alerte.
Code:
if( $date_debut > $date_fin ) { echo "<script>alert ('Please enter correct dates , bla bla bla ...');"; echo "window.history.back();"; echo "</script>"; jexit(); }

Tout se passe bien du coté backend par contre du coté frontend avant la redirection j'ai une erreur qui s'affiche:
Warning: Invalid argument supplied for foreach() in C:\wamp\www\loisirs-joomla-test\libraries\joomla\form\form.php on line 1178

Eric

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36352 by ggppdk
Hello the code that i gave you is not related to this error,

please check what code you are calling in your plugin


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36353 by seabird
Voilà le code
Code:
public function onBeforeSaveItem( & $item, $isnew ) { $post = JRequest::get('post'); // echo "<pre>"; print_r($post);; echo "</pre>"; exit; $erreur_ordre_date=0; // VERIFICATION FORMAT DATE // découpage date début $jour1 = substr($post['custom']['date_debut'][0], 0, 2); $mois1 = substr($post['custom']['date_debut'][0], 3, 2); $annee1 = substr($post['custom']['date_debut'][0], 6, 4); $date_debut=$annee1.'-'.$mois1.'-'.$jour1; // découpage date fin $jour2 = substr($post['custom']['date_fin'][0], 0, 2); $mois2 = substr($post['custom']['date_fin'][0], 3, 2); $annee2 = substr($post['custom']['date_fin'][0], 6, 4); $date_fin=$annee2.'-'.$mois2.'-'.$jour2; //echo $date_debut;echo"<br>"; //echo $date_fin;echo"<br>"; // vérification si date_debut < date_fin if ((mktime(0 , 0 , 0 , $mois2 , $jour2 , $annee2) - mktime(0 , 0 , 0 , $mois1 , $jour1 , $annee1)) < 0) {$erreur_ordre_date=1; } if ( $erreur_ordre_date==0) { return true; } else { echo "<script>alert ('Erreur la date de début est supérieur à la date de fin, veuillez corriger');"; echo "window.history.back();"; echo "</script>"; jexit(); } }

Je ne vois pas trop ce qui gène

Eric

Please Log in or Create an account to join the conversation.

More
12 years 11 months ago #36356 by ggppdk
Temporarily edit:
C:\wamp\www\loisirs-joomla-test\libraries\joomla\form\form.php

and add before the error-giving line:
Code:
if ( !is_array($ids) ) { debug_print_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS); exit; }

This should tell you which function tree called it


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star review. Thanks!

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save