designguru Posted May 29, 2006 Share Posted May 29, 2006 Hey guys,I'm quite a php novice so I hope someone here can help me out!I have a php form that posts info to an aspx page, which returns info to my php form.For example, one of the return fields reports errors in how the form was filled out - by typing this:[code]<?phpif ($errors) print_r('<div class=cont_err>OOPS - it looks like there were errors in your contribution submission:'); echo $_POST['errors']; print_r ('</div>') ?>[/code]into my form I got this returned:[code]OOPS - it looks like there were errors in your contribution submission:30/31/32/33/35/36/37/40/41/42/50/52[/code]Now, each of those error numbers coresponds to a particular error which I'd like to print on the screen underneath the simple message that results when there are errors.How can I seperate the list of errors and display an error message (such as 'you forgot to input your name') for each number displayed?Cheers,Qasim Quote Link to comment https://forums.phpfreaks.com/topic/10728-forum-returns/ Share on other sites More sharing options...
Ferenc Posted May 29, 2006 Share Posted May 29, 2006 [code]<?php$str = "30/31/32/33/35/36/37/40/41/42/50/52";// for you use //$str = $_POST['errors'];$errors = array();// now place the errors in the array, as many aas you need!$errors['30'] = "Forgot your name<br>";$errors['31'] = "Forgot your address<br>";$errors['32'] = "email is incorrect<br>";$errors['33'] = "Forgot something else<br>";$errors['35'] = "Blah Blah<br>";// now look at $str ... use explode to seperate them$parts = explode('/', $str);foreach($parts as $key => $value) { // look for the error key and display error if(array_key_exists($value, $errors)){ echo $errors[$value]; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10728-forum-returns/#findComment-40094 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.