Hi:

I have a php script that runing to check some form input. after I got some error input found, the script(php) should prompt a error message just like the java script alert. this php script should not produce any html file.

How can I do that ?

thanks a lot !!!

    I think you need to do some reading about the diff between client side (javascript) and serverside (php, asp, java) processing.

    When you submit a form to php the whole form goes and you will be left with a blank screen if you don't output something.

    You have choices, basically output the whole form again with a error message in the html or at the very end have

    if (isset($errormsg))
      echo "<script language='javascript'>\n alert('$errormsg');\n </script>";
    

      Use JavaScript 🙂

      <script language="javascript">
      <!--
      function check(theform) {
      if (theform.user.value=="") {
      alert("Enter Username!");
      return false; }
      if (theform.pwd.value=="") {
      alert("Enter a password!");
      return false; }
      else { return true; }
      }
      //-->
      </script>

      <TABLE CLASS=border WIDTH="100%" ALIGN="CENTER" BORDER="0" cellpadding=3 cellspacing=3>
      <tr><Th ALIGN="CENTER"><font size=3><b><?=MSG_TI_LOGIN?></b></th></TR>
      <TR><TD CLASS=back ALIGN="CENTER"><br>
      <form action="index.php" method="post" name='login' onsubmit="return check(this);">
      Username:</br><input type="text" name="user" size="11"><br>
      <br>
      PASSWORD:</br><input type="password" name="pwd" size="11"><br>
      <br>
      </td></td>
      <tr><td align=center>
      <input type="hidden" name="login" value="LOGIN"><br>
      <input type="submit" value="<?=MSG_BT_LOGIN?>">
      </form>
      <!set the focus to the field "username">
      <script type="text/javascript">document.login.user.focus()</script>

        A function would be a good idea...

        function alert($msg = '')
        {
             if(!$msg) $msg = 'Go sit in a corner' . "\n";
             echo '<script language="JavaScript">' . "\n" . 'alert("$msg");' . "\n" . '</script>';
        }
        

        Then you call it with e.g. alert(); or alert('Alert message here');

          if ((!$newpassword)&&(!newpassconfim)){
          //update all other info - leave old password alone
          }elseif ($newpassword!=$newpassconfim){
          //error check to see if passwords match- if they don't send error
          //message and the user back to the form. note that passwords
          //do not persist in the browser forms...you may want to code
          //to remember all the other values (if any) to allow for best
          //user interface and least aggravation.

          //this script creates a pop up warning box and when clicked
          //will take the user back one page. or you can handle it
          //another way, it's all good.

          echo "html><script language=\"javascript\">
          function errors(){
          alert("The new passwords do not match!");
          history.go(-1);
          }
          </script></html>";
          }elseif ($newpassword==$newpassconfim){
          //update the data changes including the password
          }

            Write a Reply...