Disable Form or button for periods

1

Good day, I have a form which should only be available for example one day a week from 9 am to 1 pm, I am looking for an option to carry out this, I do not know if this is possible, they could guide me please.

    
asked by Xavi 14.12.2018 в 17:27
source

1 answer

0
<?php
//Sacas la hora (Recuerda que es la hora del servidor)
$hora = date('H');

//Haces un simple comparativo entre los rangos que quieres que este disponible
if( $hora >= 9 && $hora < 13 ){
    echo '<button type="button">Enviar</button>';
}else{
    echo '<button type="button" disabled>Enviar</button>';
}
?>

I left you the commented code, this can be done in a line with a ternary if it would confuse you more taking into account that you are a novice.

ANNEX SOLUTION

How it comments Shaz , the ideal would be not to show the button, so the else is over.

<?php
//Sacas la hora (Recuerda que es la hora del servidor)
$hora = date('H');

//Haces un simple comparativo entre los rangos que quieres que este disponible
if( $hora >= 9 && $hora < 13 ){
    echo '<button type="button">Enviar</button>';
}
?>

I hope it serves you.

    
answered by 14.12.2018 / 17:41
source