如何保存在PHP CodeIgniter中的文本框中输入的数据

时间:2017-12-29 05:55:56

标签: php jquery session jquery-plugins session-variables

在PHP CodeIgniter应用程序中,有几个页面包含输入文本框和文本区域。

如何在php中实现会话保存,即每当用户关闭标签时

输入的数据应保持保存,直到用户退出应用程序。 或者是否有任何插件可以实现相同的目标?

我的相同代码: -

<form accept-charset="UTF-8" method="post" id="myform" action="/saveform">
    Name: <input name="name" type="text" value="" /><br />
    Address: <textarea name="address"></textarea><br />
    Gender: <select name="gender">
    <option value="M">Male</option>
    <option value="F">Female</option>
    </select><br />
    Interests:<br />
    1: <input name="interests[]" type="text" value="" /><br />
    2: <input name="interests[]" type="text" value="" /><br />
    3: <input name="interests[]" type="text" value="" /><br />
    4: <input name="interests[]" type="text" value="" /><br />
    5: <input name="interests[]" type="text" value="" /><br />
    Sign up for our newsletter: <input name="signup" type="checkbox" value="1" /><br />
    <input name="submit" type="submit" value="Submit" />
</form>

1 个答案:

答案 0 :(得分:0)

您可以在关闭选项卡或页面时保存表单数据,使用AJAX可以保存会话中的所有数据,然后在表单中添加如下修改:

<form accept-charset="UTF-8" method="post" id="myform" action="/saveform">
    Name: <input name="name" type="text" value="<?php echo isset($_SESSION['user']['name']) ? $_SESSION['user']['name'] :"";?>" /><br />
    Address: <textarea name="address"><?php echo isset($_SESSION['user']['address']) ? $_SESSION['user']['address'] :"";?></textarea><br />
    Gender: <select name="gender">
    <option value="M" <?php echo $_SESSION['user']['gender']=='M' ? "selected" :"";?>>Male</option>
    <option value="F" <?php echo $_SESSION['user']['gender']=='F' ? "selected" :"";?>>Female</option>
    </select><br />
    Interests:<br />
    1: <input name="interests[]" type="text" value="<?php echo isset($_SESSION['user']['interests_0']) ? $_SESSION['user']['interests_0'] :"";?>" /><br />
    2: <input name="interests[]" type="text" value="<?php echo isset($_SESSION['user']['interests_1']) ? $_SESSION['user']['interests_1'] :"";?>" /><br />
    3: <input name="interests[]" type="text" value="<?php echo isset($_SESSION['user']['interests_2']) ? $_SESSION['user']['interests_2'] :"";?>" /><br />
    4: <input name="interests[]" type="text" value="<?php echo isset($_SESSION['user']['interests_3']) ? $_SESSION['user']['interests_3'] :"";?>" /><br />
    5: <input name="interests[]" type="text" value="<?php echo isset($_SESSION['user']['interests_4']) ? $_SESSION['user']['interests_4'] :"";?>" /><br />
    Sign up for our newsletter: <input name="signup" type="checkbox" value="1" <?php echo $_SESSION['user']['signup']=='1' ? "checked" :"";?> /><br />
    <input name="submit" type="submit" value="Submit" />
</form>

希望这会有所帮助!!