d-lexy Posted September 18, 2007 Share Posted September 18, 2007 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 https://forums.phpfreaks.com/topic/69796-solved-automatically-collect-submitted-form-fields-into-array-possible/ Share on other sites More sharing options...
Jessica Posted September 18, 2007 Share Posted September 18, 2007 $arr = $_POST; Link to comment https://forums.phpfreaks.com/topic/69796-solved-automatically-collect-submitted-form-fields-into-array-possible/#findComment-350644 Share on other sites More sharing options...
BlueSkyIS Posted September 18, 2007 Share Posted September 18, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/69796-solved-automatically-collect-submitted-form-fields-into-array-possible/#findComment-350648 Share on other sites More sharing options...
Jessica Posted September 18, 2007 Share Posted September 18, 2007 Good one. Link to comment https://forums.phpfreaks.com/topic/69796-solved-automatically-collect-submitted-form-fields-into-array-possible/#findComment-350649 Share on other sites More sharing options...
d-lexy Posted September 18, 2007 Author Share Posted September 18, 2007 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 https://forums.phpfreaks.com/topic/69796-solved-automatically-collect-submitted-form-fields-into-array-possible/#findComment-350672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.