【问题标题】:Keep the button Active after reloading the page (using PHP and HTML)重新加载页面后保持按钮处于活动状态(使用 PHP 和 HTML)
【发布时间】:2022-01-23 19:48:12
【问题描述】:

有什么方法可以让我在重新加载页面后保持按钮处于活动状态? (我没有使用任何自定义 CSS,只有 Bootstrap) php。在 if 条件下,我将按钮用作打开或关闭的开关。

HTML

<div style="margin-top: 20px; margin-left: 40px;"><p> Show All Conferences </p>
            
<form method="POST">
    <div class="tab-content">
    <button style="margin-left: 35px;" type="submit" name="submitBtn" class="btn btn-primary" data-toggle="button"> On </button>
    <button style="margin-left: -8px;" type="submit" name="submitBtn2" class="btn btn-secondary" data-toggle="button"> Off </button>
</form></div>

</div>



function switch_on_off() 
{
  $dateConf = date('Ymd');
  if(isset($_POST['submitBtn'])) {         
    $dateConf = date("Y-m-d", strtotime('2017-02-02 17:02:03'));
  }
  if(isset($_POST['submitBtn2'])) { 
    $dateConf = date('Ymd');
  }
  return $dateConf;
}

function get_future_conferences() 
{ 
  $dateConf2 = switch_on_off();
  $args = array(
    'numberposts' => -1,
    'post_type'   => 'conference',
    'post_status' => 'publish',
    'meta_key'    => 'conference_start_date',
    'orderby'     => 'meta_value',
    'order'       => 'ASC',
    'meta_query'  => array(
        'key'     => 'conference_start_date',
        'value'   => $dateConf2,
        'compare' => '>=',
    ),
  );
  $conferences = get_posts( $args );
  return $conferences;
{

【问题讨论】:

    标签: php html wordpress button bootstrap-4


    【解决方案1】:

    如果您不想使用 javascript,您可以使用 session 来执行此操作。单击开/关按钮后,您可以在 PHP 会话中保存值(日期时间等),然后在重新加载页面时检查设置的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 2012-05-18
      • 2013-05-24
      • 2021-12-08
      • 1970-01-01
      • 2015-07-29
      相关资源
      最近更新 更多