hello friends,
I have a little big problem with a form that I made. I made a form where a user can input some data, and some buttons. some of them require the script to be reloaded passing some data, which means the form action is $PHP_SELF , and I have one that shows a preview of the input data in a different layout and a blank window, which requires the form action to be action='new_script.php' target='blank' .
First I just set a variable at the action, that is set to $PHP_self by default, but changed to "'new_script.php' target='blank'" when the user presses the last needed button before he can press the "preview"-button, but this hasn't been exactly the solution I was looking for because if the user wants to make some changes, then pressing one of the other buttons, it always will display the form in a new window.
Then I had the idea of putting that "preview"-button into a new form, but as everybody knows, this will not pass the $POST variables from the other form to the new script.
So I inserted a hidden input in the form containing the "preview"-button, with an array that holds all the values. The array is filled when the user presses th last button before being able to press "preview". This doesn't work either.
Well, now I thoght I could pass two variables, one filled with the variable names, the other one filled with the values, but because the $POST-array contains some other arrays I had to make a loop to perform that task. The problem is now that some variables and values are passed, some others are not. The result is that some values can not be assigned to the right values, even some are missing.
This is the relevant part of the script:
//this part is in the main form (input)
<?
//some other code
if(isset($one_btn))
{
foreach($_POST as $key => $form_value)
{
if ( is_array(${$key}))
{ $k = 0;
foreach(${$key} as $arr => $value)
{ $k++;
if ( is_array(${$arr}))
{
$l = 0;
foreach(${$arr} as $subarr => $val)
{ $l++;
$temp_keys[$arr[$subarr]] = $arr."[".$l."][".$k."]";
$temp_form_values[$arr[$subarr]] = $val;
}
}
else{
$temp_keys[$key[$arr]] = $key."[".$k."]";
$temp_form_values[$key[$arr]] = $value;
}
}
}
else
{
$temp_keys[$key] = $key;
$temp_form_values[$key] = $form_value;
}
}
$pass_var_names = implode(":", $temp_keys);
$pass_values = implode(":", $temp_form_values);
}
//Now the form
<form name='form1' method='POST' action='".$PHP_SELF."'>
// Input fields go here +
<input type='submit' name='one_btn'>
</form>
<form name='form2' method='POST' action='new_script.php' target='_blank'>
<inptut type='hidden' name='pass_var_names' value='".$pass_var_names."'>
<inptut type='hidden' name='pass_values' value='".$pass_values."'>
<input type='submit' name='gotonewwnd' value='Preview'>
</form>
?>
Please don't mind about the missing echoes, they are set to the right place in the original script.
In the second script (new_script.php) $POST is extracted and the two string-chains are exploded.
OK, as you can see, I have variables in two array levels inside $POST, don't care about the complexity, this was just for testing before trying to write a recursion that might look simpler (if recursion works in this case, just didn't think about yet).
Can somebody help me with this? Or does somebody have a simpler idea that could work, but without JavaScript?
Thanks in advance.
Best regards
Gaucho