I have a simple form using post
<form id="quote_form" name="n_quote_form" method="post" action="quote">
(the action here is an url parameter (sort of) which a page-loading script uses to direct the user back to this page in_quote.php
)
switch ($urlParam) {
case 'quote':
$incPage = "in_quote.php";
break;
case 'contact':
$incPage = "in_contact.php";
break;
case 'links':
$incPage = "in_links.php";
break;
default:
$incPage = "in_home.php";
break;
}
so when I fill in the form with this data
this data is passed to this script:
function submit_quote_form(){
if (validate_form($_POST)){
which in turn calls on this script: (I have not implemented validation until I can extract the form data from $_POST
using extract()
as I don't want to manually type in the keys every time the form changes or if I want to reuse my validate script (with less modification) elsewhere)
this script dumps the $form_data var correctly ($_POST
in essence so I think we can assume that it's not a passing parameters issue) but then the extract variable $var
seems to be converted to an int of size 11???
function validate_form($form_data) {
var_dump($form_data);
$var = extract( $form_data, EXTR_OVERWRITE, "form_" );
var_dump($var);
echo "THIS IS MY POST VAR ==>";
var_dump($_POST); // included for comparison
}
the results are strange when I var_dump $form_data
(compared $form_data
to $_POST
to make sure it's not a parameter passing issue)
output:
array(11) { ["n_name"]=> string(3) "bob" ["n_email"]=> string(12) "bob@bobs.com" ["n_email2"]=> string(12) "bob@bobs.com" ["n_day_from"]=> string(1) "8" ["n_month_from"]=> string(8) "December" ["n_year_from"]=> string(4) "2015" ["n_day_to"]=> string(1) "9" ["n_month_to"]=> string(8) "December" ["n_year_to"]=> string(4) "2015" ["n_bike_reqs"]=> string(14) "5 bikes please" ["submit_but"]=> string(13) "get my quotes" } int(11) THIS IS MY POST VAR ==>array(11) { ["n_name"]=> string(3) "bob" ["n_email"]=> string(12) "bob@bobs.com" ["n_email2"]=> string(12) "bob@bobs.com" ["n_day_from"]=> string(1) "8" ["n_month_from"]=> string(8) "December" ["n_year_from"]=> string(4) "2015" ["n_day_to"]=> string(1) "9" ["n_month_to"]=> string(8) "December" ["n_year_to"]=> string(4) "2015" ["n_bike_reqs"]=> string(14) "5 bikes please" ["submit_but"]=> string(13) "get my quotes" }
I did try to cast the extraction to an array using:
$var = (array) extract( $_POST, EXTR_OVERWRITE, "form_" );
but that gave me this:
array(1) { [0]=> int(11) }
in
var_dump($var);
so only casted the int into an array of ints of length 1! I COULD use the individual keys as other posts here have suggested but I'd rather not particularly when other posts here had accepted answers using the extract method - it's just NOT WORKING for me!
Q. Why is extract() not working as I/WE think it should???
Help is appreciated!