Member Avatar for dartiss

Hi,

I have an urgent issue.

I have a screen that allows the user to select something from a drop-down and then submit it. The form directs to the same page where, if data has been supplied, processing occurs based upon their drop-down selection.

What I want to do is, if they press refresh on their browser, not process the data again. However, if they select the same item from the drop-down and submit it again then this should work. Is there a way to do this?

Ideally I wanted to be able to clear out the contents of the form submission after processing it but this doesn't appear to work (I was putting $_POST=array()).

Does anybody have any thoughts on how I might go about this without resorting to Javascript or diverting to another page on submission?

Thanks,
David.

What I want to do is, if they press refresh on their browser, not process the data again. However, if they select the same item from the drop-down and submit it again then this should work. Is there a way to do this?

For that you can use some part of the process that is ran and log it temporarily such as a cookie or see if the update has already occured and not process it eg. set name = 'bob' see if 'name' already equals bob and if it does ignore it

a function to make token

function randStr($len = 6){
    if(is_int($len) && $len > 0){
        $string = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',$len)),0,$len);
    }else{
        $string = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',6)),0,6);
    }
    return $string;
}

Into the form

<input type='hidden' name='token' value='<?php echo randStr(15);?>'/>

Into the process section(after cookie check)

setcookie("token", $token, $expire, "/");

Add before process to check if form already processed

if($_COOKIE['token'] == $_POST['token']){
    //ignore
}else{
    //process
}

Ideally I wanted to be able to clear out the contents of the form submission after processing it but this doesn't appear to work (I was putting $_POST=array()).

That should work, you could try a more forceful approach and loop through it setting them all empty

foreach($_POST as $k=>$v){
    unset($_POST[$k]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.