FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Newbie: Displaying a 'message box'
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Newbie: Displaying a 'message box' [message #169788] Sun, 26 September 2010 23:13 Go to next message
Richard Holmes is currently offline  Richard Holmes
Messages: 1
Registered: September 2010
Karma: 0
Junior Member
After a user has submitted a form I would like to display a message
from a PHP function to acknowledge the input if the form is entered
correctly or an error message if the input is incorrect. I've searched
Google and the PHP manual but I haven't found an equivalent to a
'message box'. Any suggestions? TIA!

Dick
Re: Newbie: Displaying a 'message box' [message #169789 is a reply to message #169788] Sun, 26 September 2010 23:17 Go to previous messageGo to next message
Marious Barrier is currently offline  Marious Barrier
Messages: 25
Registered: September 2010
Karma: 0
Junior Member
On 09/26/2010 07:13 PM, Richard Holmes wrote:
> After a user has submitted a form I would like to display a message
> from a PHP function to acknowledge the input if the form is entered
> correctly or an error message if the input is incorrect. I've searched
> Google and the PHP manual but I haven't found an equivalent to a
> 'message box'. Any suggestions? TIA!

You must make the box in html and then display it when needed. What is
the part that is stopping you from doing this?
Re: Newbie: Displaying a 'message box' [message #169791 is a reply to message #169788] Sun, 26 September 2010 23:34 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 9/26/2010 7:13 PM, Richard Holmes wrote:
> After a user has submitted a form I would like to display a message
> from a PHP function to acknowledge the input if the form is entered
> correctly or an error message if the input is incorrect. I've searched
> Google and the PHP manual but I haven't found an equivalent to a
> 'message box'. Any suggestions? TIA!
>
> Dick

Have the top of the page do a $msg = $_GET['msg']; and have the php
doing the processing send a ?msg=whatever_the_message_is after the page
name in the header("Location:......) directive.

Then, on your page you process that value using normal HTML (for example
as a textarea with readonly properties) or as the input to an inline
javscript that will put up an alert if there is some value received and
not be invoked at all if $msg is not set.

What I do is have a message at the top of the page, no surrounding box,
which is invoked only if $msg is set:

if (isset($msg)) echo $msg;

or

if (strlen($msg) > 0) echo $msg;

Of course you can put all that inside a <span></span> where you will
define print properties such as color, size, alignment, etc.

--
Shelly
Re: Newbie: Displaying a 'message box' [message #169792 is a reply to message #169788] Mon, 27 September 2010 00:58 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 9/26/2010 7:13 PM, Richard Holmes wrote:
> After a user has submitted a form I would like to display a message
> from a PHP function to acknowledge the input if the form is entered
> correctly or an error message if the input is incorrect. I've searched
> Google and the PHP manual but I haven't found an equivalent to a
> 'message box'. Any suggestions? TIA!
>
> Dick

PHP is server side. You cannot open a message box on the client; all
you can do is send html.

The other answers here are the only way you can do it in PHP. You can
bring up a message box in javascript (which is client-side), but then
you need to determine if the data the user input is valid in javascript
- once the page is submitted to the server for PHP to process the
browser has no further access to it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Newbie: Displaying a 'message box' [message #169793 is a reply to message #169788] Mon, 27 September 2010 01:53 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 27/09/10 00:13, Richard Holmes wrote:

> After a user has submitted a form I would like to display a message
> from a PHP function to acknowledge the input if the form is entered
> correctly or an error message if the input is incorrect. I've searched
> Google and the PHP manual but I haven't found an equivalent to a
> 'message box'. Any suggestions? TIA!

Assuming you're using php to validate and process the form data, at some
point in the php code do something like this:

if ($validated) {
if ($processed) {
// validation & processing ok
echo "<p>Thanks, your submission
has been processed.</p>";
echo "<p>Please <a href='some_link'>click</a>
to return to our home page.</p>";
}
else {
// processing failed
echo "<p>Sorry, there was a server error.</p>";
echo "<p>Please <a href='some_link'>try later</a></p>";
}
}
else {
// validation failed
echo "<p>Sorry, the data you submitted was not valid.</p>";
echo "<p>Please <a href='some_link'>try again</a></p>";
}

If you're using ajax to handle the request, you probably only want to
echo back a single text string that you can then use in an alert box.
You can ember carriage returns (\n) in such a string if you wish.

Rgds

Denis McMahon
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Array variable in echo statement
Next Topic: Stats comp.lang.php (last 7 days)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 20:48:17 GMT 2024

Total time taken to generate the page: 0.02387 seconds