Omzy Posted October 9, 2009 Share Posted October 9, 2009 I have a form which captures customer's details, such as Name, Address, Date of Birth, etc, and then displays them back to the user (and sends me an email with the details) upon submission, as follows: foreach($_POST as $key => $value) { echo "$key : $value"; } This works fine for me, but I have now split up the Date of Birth field into 3 seperate fields - Day, Month, Year. But I still want it to be output as one field (Date of Birth) at the end. Because I'm outputting $_POST this is proving to be difficult. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/ Share on other sites More sharing options...
Daniel0 Posted October 9, 2009 Share Posted October 9, 2009 Just combine them into a single index before looping and remove the other ones. For cleanliness, create a copy of $_POST for this purpose so you don't pollute it. Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/#findComment-933970 Share on other sites More sharing options...
Omzy Posted October 9, 2009 Author Share Posted October 9, 2009 Cheers Daniel0, I've tried using array_push to add the combined value to the end of the array, but it doesn't seem to work: array_push($_POST['DOB'],"".$_POST['Day']."-".$_POST['Month']."-".$_POST['Year'].""); Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/#findComment-933973 Share on other sites More sharing options...
Daniel0 Posted October 9, 2009 Share Posted October 9, 2009 Well, that's not how array_push() works. What you're looking for is: $_POST['DOB'] = $_POST['Day']."-".$_POST['Month']."-".$_POST['Year']; Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/#findComment-933992 Share on other sites More sharing options...
Omzy Posted October 9, 2009 Author Share Posted October 9, 2009 Ah wicked, that's worked! So now can you tell me how I can remove those redundant keys/values from $_POST? Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/#findComment-933994 Share on other sites More sharing options...
Daniel0 Posted October 9, 2009 Share Posted October 9, 2009 unset Quote Link to comment https://forums.phpfreaks.com/topic/177131-solved-outputting-from-_post/#findComment-933995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.