Help with Forms: Passing a list of values
Posted: Wed Aug 15, 2012 6:04 am
Assume i I have a function called calculate-answer() that takes unlimited number of arguments and then does some calculations.
The parameters must come through a user submitted html form - where the user submits all arguments ONLY from a single text field - all values separated by comma.
How to get this through the form and pass it to the function.
I am trying the below code but the function is not giving the correct answers.
When i pass the same arguments directly to the function - its returning the correct answer - so the function is correct
My question:
a) How do i pass a list of comma separated list of numbers from a form to my function ?
b) Why is my above code not passing the correct arguments to my function ?
Thanks for your answer.
The parameters must come through a user submitted html form - where the user submits all arguments ONLY from a single text field - all values separated by comma.
How to get this through the form and pass it to the function.
I am trying the below code but the function is not giving the correct answers.
When i pass the same arguments directly to the function - its returning the correct answer - so the function is correct
Code: Select all
$answer = "0";
if(isset($_POST['submit'])) {
include ('calculateanswer.php');
$numbers = $_POST['numbers'];
$answers = calclulate-answers($numbers);
echo 'Answer:'. $answer;
}
else { ?>
<form action="" method="post">
<input type="text" id="numbers" name="numbers">
<input type="submit" name="submit" value="Calculate Answer">
</form>
}
a) How do i pass a list of comma separated list of numbers from a form to my function ?
b) Why is my above code not passing the correct arguments to my function ?
Thanks for your answer.