The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 5 of 5

Thread: PHP echo to display javascript alert

  1. #1

    PHP echo to display javascript alert

    Hi people, I'm very new to PHP and I want to put a javascript alert within a php thingo. The code I have looks like this:

    PHP Code:
    $the_email false;    
    eregi("^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"$_POST['email'])) {
    $the_email true;
    } else {
    "<script language=javascript>  alert('Please enter a valid email address, or I will kill you); </script>"
    $the_email false;
    $the_email || !isset($_POST['name']) || !isset($_POST['message'])) {
    "<script language=javascript>  alert('Please enter your '+fName); </script>"

    Can anyone see anything wrong with this? Any feedback would be appreciated.

  2. #2
    I've kind of got it to work, but instead of the browser staying put while the alert opens, the browser goes to another page (the php that its supposed to validate the form). Anyone know of a way around this?


  3. #3
    using php to go to a new page defeats the purpose of the js alert box. use just js validation if you're going to use the alert box. or i suppose you could go the AJAX route to send the data through, validate with PHP, return. either way, you should ultimately test in PHP before anything gets submitted to your DB or mail.

  4. #4
    Yeah the thing is, I don't want it to redirect. JS alerts, all the way baby.


  5. #5
    right. you should JS alert (using just JS validation upfront or AJAX). then when it validates step 1, pass it to validation 2 (PHP).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012