0

I have a simple form with 2 fields and I want to read the data from it and use it with $_POST.

This is the output when I debug the $_POST function:

file_put_contents( 'debug' . time() . '.log', var_export( $_POST, true));

OUTPUT:

array (
    'form' => 
            array (
                'id' => '36e3113',
                'name' => 'New Form',
            ),
    'fields' => 
                array (
                    0 => 
                        array (
                            'id' => '0',
                            'type' => 'text',
                            'title' => 'Your name',
                            'value' => 'John',
                            'raw_value' => 'John',
                            'required' => '1',
                        ),
                    1 => 
                        array (
                            'id' => '1',
                            'type' => 'tel',
                            'title' => 'Phone number',
                            'value' => '12345',
                            'raw_value' => '12345',
                            'required' => '1',
                        ),
                ),
)

I want to use $POST to only assign values of Your name to $name and Phone number to $number variable.

3
  • $name = $_POST["form"]["name"] Commented Jan 3, 2019 at 8:58
  • You should really read the manual: php.net/manual/en/language.types.array.php Commented Jan 3, 2019 at 9:00
  • $fields = array_column($_POST["fields"], "value", "title"); Commented Jan 3, 2019 at 9:00

1 Answer 1

2

You can get it like.

$name = $_POST['fields'][0]['value'];
$number = $_POST['fields'][1]['value'];
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.