In my html page, I have a php iframe that gets its variables from the form using post method. This works fine.
My problem is this: I would like the php iframe to auto-refresh (which it does), but , understandably, I get undefined index errors from php the first time the iframe auto-refreshes.
Is there some way (preferably using only php/html) to allow the iframe to hold on to the variables from the html form after the first load of the php iframe? Isset doesn't seem to be the answer to my problem
Here's a very simple way of accomplishing what you're after:
<?php
// Starts a session
session_start();
// Gets a variable via $_POST if present and caches it in $_SESSION
// If it doesn't exist in $_POST or $_SESSION, return null
function get_variable( $name )
{
if( isset( $_POST[$name] ) )
{
$_SESSION['cache_'.$name] = $_POST[$name];
}
return ( isset( $_SESSION['cache_'.$name] ) ? $_SESSION['cache_'.$name] : null );
}
// Get these values from the form on the cache
$value_a = get_variable('field_name_a');
$value_b = get_variable('field_name_b');
$value_c = get_variable('field_name_c');
// One the values is missing
if( is_null( $value_a ) || is_null( $value_b ) || is_null( $value_c ) )
{
// Display an error message or whatever else
}
// All values are present
else
{
// Use the variables however you were before
}
?>