Hello Everyone 🙂
I am having a HECK of a time trying to understand how to collect information from a form.
I am creating an online job application where you tell me how many jobs you have done in the last year. I am using arrays to hold the information.
HOWEVER, the end result for all my information comes out as Array instead of what the user submitted!!
Result:
<input name="job_company" type="hidden" value="Array">
<input name="job_phone" type="hidden" value="Array">
<input name="job_address" type="hidden" value="Array">
PLEASE help, I am sooo lost 🙁 I have alot of information to collect so I want to use the foreach function...
<?php
function convert_vars(){ //collect form variables, convert to hidden fields
global $HTTP_POST_VARS;
foreach($HTTP_POST_VARS as $var_name => $var_value){
if($var_value != "" && $var_value != "submit"){
echo("<input name=\"$var_name\" type=\"hidden\" value=\"$var_value\">\r\n");
}
}
}
if($how_many_jobs){
convert_vars();
}
else{
$how_many_jobs = 2;
?>
<form action="temp.php" method="post">
<?php
for($i = 1; $i <= $how_many_jobs; $i++){
?>
JOB#<?php echo($i); ?><br>
<input type="text" name="job_company[<?php echo($i); ?>]"><br>
<input type="text" name="job_phone[<?php echo($i); ?>]"><br>
<input type="text" name="job_address[<?php echo($i); ?>]"><br>
<?php } ?>
<input type="hidden" name="how_many_jobs" value="2">
<input type="submit" name="submit" value="submit">
</form>
<?php } ?>
</body>
</html>