LoginSignup
0
1

More than 5 years have passed since last update.

PHP formを使ってページの更新 備忘録

Posted at

やりたいこと

Fromを用いて、データを送信しページを更新

Viewの設定

home.php
<form action="<?php echo base_url() ?>クラス名/関数名"  class="float-right" method="POST">
    <select name="period">
        <option value="30m" >30分後</option>
        <option value="1h" selected>1時間後</option>
        <option value="tomorrow">明日</option>
    </select>
    <input type = "submit" value ="更新">
</form>

controllerの設定

今回は、部分更新をするのでデータの更新を行ったら、元のページに戻りため、controllerのindex関数を呼びます。
後々こっちのほうが便利かもしれない。

Home.php

public function 関数名(){
    $selected = $_POST['period'];
    if ($selected == '30m') {
            $period = '30分後';
    }elseif ($selected == '1h') {
          $period = '1時間後';
    }elseif ($selected == 'tomorrow') {
          $period = '明日';
    }
    $this ->index($period);
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1