Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


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 kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012