I’m totally new to php. I’m trying to echo the value of an input field into a an array but it doesn’t seem to work.e.g echo the value of hidden-input as the value for origin in the array. How can I achieve this.
As Anthnee said, that makes $_POST[‘from’] an array. In your case, it will be array with one element (as you have one input). So, to get value from that array you should specify an element index:
Yes I want $params['origin'] to contain value from single input. I inserted the input value with jQ and I want the users to see the distance from them to the users calculated automatically. It works if I add the value automatically.
Accordingly, no need to specify additional array index for $_POST[‘from’] as well:
'origin' => $_POST['from'],
Brackets in input names are used only when it is necessary to have two or more inputs with the same name but different values (see example in post #2).
Are you ever actually posting the data? If there’s no submit then it will never show up:
<form action="post">
<input type="hidden" name="from" value="Foo">
<input type="submit" value="Post data">
</form>
<?php
if (isset($_POST['from'])) {
var_dump($_POST['from']);
} else {
echo "You need to submit the form to see the POST data";
}