Page 1 of 1

How to remember submitted value after page reload

Posted: Tue May 19, 2009 5:20 am
by Ludus
Hi, I made a script that reads messages from MySQL table. As some user could have plenty of messages I added also some kind of pagination. Of course, user could have new and old messages, so I added small form with radio-buttons and submit button where user is able to make choice which message he want to see, old or new (never opened). PHP code reload page thanks to PHP_SELF in form action and make proper setup for 1 page, with good data based on SQL. But when I click on Next link of pagination state of radio-buttons disappears and SQL then don't know what was user's last choice. Form use POST method. :? I tried to find out solution by adding value of last picked radio-button into link, after info that use pagination but ... won't work. :banghead: Also tried with $_SESSION variable but same result. Is there some kind of smart and efficient solution for this purpose?
I didn't post code as it's pretty long. Thanks for advice.

Re: How to remember submitted value after page reload

Posted: Tue May 19, 2009 5:36 am
by nmreddy
At page starting give like this

if($_POST['radio_buttonvalue']!='')
radio_buttonvalue = $_POST['radio_buttonvalue'];
else
radio_buttonvalue = $_GET['radio_buttonvalue'];

Next Give the pagination like this

<a href='test.php?radio_buttonvalue=$radio_buttonvalue>next</a>

Re: How to remember submitted value after page reload

Posted: Wed May 20, 2009 8:27 am
by Ludus
nmreddy wrote:At page starting give like this

if($_POST['radio_buttonvalue']!='')
radio_buttonvalue = $_POST['radio_buttonvalue'];
else
radio_buttonvalue = $_GET['radio_buttonvalue'];

Next Give the pagination like this

<a href='test.php?radio_buttonvalue=$radio_buttonvalue>next</a>
Hi dude, thanks for suggestion, I tried it but script "sticked" always on first button. After some tries I made some solution that works less-more okey. If you or someone other have better advice, I'm ready to obey.

Code: Select all

 
<?php
session_start();
 
if($_POST['btn_submit'])
{
$_SESSION['b']=$_POST['radio_button'];
$rb=$_SESSION['b'];
if ($rb==1)
    {
    $t1='checked="checked"';
    $t2='';
    }
else
    {
    $t2='checked="checked"';
    $t1='';
    }
}
else
{
$rb=$_GET['rb'];
if ($rb==1)
    {
    $t1='checked="checked"';
    $t2='';
    }
else
    {
    $t2='checked="checked"';
    $t1='';
    }
}
echo $rb;
?>
<form name="ime" id="ime" action=<?="noname2.php?rb=$rb" ?> method="post" enctype="application/x-www-form-urlencoded" target="_self" title="naslov">
<input type="radio" name="radio_button" id="radio_button" value="1" align="left"   title="first" <?=$t1 ?> >OLD
<br/>
<input type="radio" name="radio_button" id="radio_button" value="2" align="left"   title="second" <?=$t2 ?> >NEW
<input type="submit" name="btn_submit" id="btn_submit" value="okey">
</form>
 
<a href="noname2.php?rb=<?=$rb ?>">next page</a>
 
 
:|