Unusually, I seem to be working on a similar one, and used the following data so that the form data is available after the form is submitted. It uses a session variable to store the POST results and is used as the value in the form field.
if( $_SERVER['REQUEST_METHOD']=='POST' ){ foreach( $_POST as $field => $value ) $_SESSION[ 'formfields' ][ $field ]=$value; } function fieldvalue( $field=false ){ return ( $field && !empty( $field ) && isset( $_SESSION[ 'formfields' ] ) && array_key_exists( $field, $_SESSION[ 'formfields' ] ) ) ? $_SESSION[ 'formfields' ][ $field ] : ''; } echo "<input type='text' id='username' name='username' value='".fieldvalue('username')."' />";
source share