Jump to content

[SOLVED] Automatically collect submitted form fields into array (Possible?)


d-lexy

Recommended Posts

Hi All

 

I have a big form with many fields. The form submits to a PHP file that updates a MySQL DB and also sends an email with some of the fields' values.

Right now the PHP file that processes the data has a whole bunch of:

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
etc... etc...

I'm wondering if there is a way to replace these with some kind of array what would collect all those fields?

 

Thanks in advance!

-Alex

if you would prefer to create a new variable with the same name as each form element, you could use this:

 

foreach($_POST AS $key=>$value) {
${$key} = $value;
}

Yep, that one is much easier for me to understand than arrays :)

 

Thanks to both of you!

 

-Alex

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.