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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.