Jump to content

forum returns...


designguru

Recommended Posts


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]
<?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>')
?>
[/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
Link to comment
Share on other sites

[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]
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.