vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Error reporting from input field, save values (https://vborg.vbsupport.ru/showthread.php?t=130932)

error_22 11-06-2006 08:12 PM

Error reporting from input field, save values
 
Hello!

I have a question about error reporting (if thats what its called).

Lets say I have a form:
HTML Code:

<form action="save.php" method="post">
<input type="text" name="hello" />
<input type="submit" value="save" />
</form>

The value from the hello field is then sent to save.php where a script checks if that value already exists. if it does, then I want save.php to send the visitor back to the html form. i want there to be an error message (your name is already taken) and the value you put in should be displayed in the input field.

Is there an easy way to achieve this?

Thanks in advance
Niklas

error_22 11-08-2006 06:43 PM

Bump

nico_swd 11-08-2006 06:54 PM

You can store the errors in sessions if you don't post the data to the same page.

PHP Code:


session_start
();

if (
/* username exists */)
{
    
$_SESSION['errors'][] = 'Username taken';
}

// Go back to previous page and... 

if (is_array($_SESSION['errors']))
{
     echo 
'Following errors ocurred: <br />';

     foreach (
$_SESSION['errors'] AS $error)
     {
          echo 
'- '$error .'<br />'"\n";
     }



error_22 11-09-2006 09:12 AM

Excellent!

One questin, what is the best way to "Go back to previous page"?

I tried using header() but it gives me errors since a header has already been sent.

nico_swd 11-09-2006 09:48 AM

You can use header('Location: ..., you just can't output anything before sending them. Neither white spaces nor HTML.

error_22 11-09-2006 01:01 PM

and what if i do have hml before? is it impossible then? do i have to re-arrange in the document?

thanks for all the help!

nico_swd 11-09-2006 01:09 PM

You can redirect with HTML then.

Echo this instead.
Code:

<meta http-equiv="refresh" content="0;URL=http://url.com" />


All times are GMT. The time now is 07:11 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01061 seconds
  • Memory Usage 1,723KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete