Jump to content


Photo

forum returns...


  • Please log in to reply
1 reply to this topic

#1 designguru

designguru
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 29 May 2006 - 08:20 PM


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:

<?php
if ($errors) print_r('<div class=cont_err>OOPS - it looks like there were errors in your contribution submission:');
     echo $_POST['errors'];
 print_r ('</div>')
 ?>

into my form I got this returned:
OOPS - it looks like there were errors in your contribution submission:30/31/32/33/35/36/37/40/41/42/50/52

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

#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 29 May 2006 - 10:26 PM

<?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];
    }

}
?>

Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users