Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop up window

Status
Not open for further replies.

zxcdf5je

Programmer
Apr 1, 2005
86
US
hi there,
i have a form where the user has to fill name and address..but if he forgets filling address he shud be reminded of it by having a popup window telling him that he has forgotten to fill out the address and needs to that before submitting the form...
How shud i get a pop up scress for this form in php?

-Smiley
 
You should actually use Javascript

html code:
Code:
<form name="address" action"process.php" method="post" onSubmit="return CheckForm(this);">
<textarea name="address" cols="27" rows="3" wrap="PHYSICAL"></textarea>
<input type="submit" name="Submit" value="Submit">
</form>

Javascript code:
Code:
function CheckForm(aform) {
  var errorString = "The following problems occurred: \r\r";
  var validHandle = true;
  if ( aform.address.value.length <= 0 ) {
    errorString += "Address not supplied. \r";
    validHandle = false;
  }
  if (validHandle == false) {
    errorString += "\r";
    alert(errorString+'\nPlease make changes and submit the form again.');
  }
}

[cheers]
Cheers!
Laura
 
Thanks laura,
iwill try this and let u know how it goes on...

Thanks once again,
-Smiley
 
hey i tried the stuff you gave on my page..but it just goes blank:
this is my code :

<?
include("../common.php");

if (isset($ordered)) {

$error1=0;
$error2=0;
$error_str1="";
$error_str2="";
for ($i=0;$i<=$num_rows;$i++)
{

if ($quantity[$i]>150)
{
$error1=1;
$error_str1="<font color=\"#ff0000\">For Quanities greater than 120, please contact a Customer Service Representative.</font>";
$sent=0;
}
}
if (($company=="") or ($name=="") or ($address=="") or ($city=="") or ($state=="") or ($zip=="") or ($phone=="") or ($email=="")or($dealer_no==""))
{
$error2=1;
$error_str2="<font color=\"#ff0000\">Please fill in all required fields.</font>";
$sent=0;
}
If (($error1==0) && ($error2==0))
{

$link=mysql_connect($DBhost, $DBuser, $DBpass);
$r=mysql_select_db($DBname,$link);

mysql_query("INSERT INTO orders (name, address, address2, city, state, zip,phone, email,comments,company,dealer_no,dated) VALUES ('$name','$address','$address2','$city','$state','$zip','$phone','$email','" . mysql_escape_string($comments) . "','$company','$dealer_no',now())") or die("Invalid query: " . mysql_error());

$ord_id=mysql_insert_id();

for ($i=0;$i<=$num_rows;$i++)
{

if ($quantity[$i]>=1){
mysql_query("INSERT INTO order_products (order_id, item_id, quantity) values ('$ord_id','$item[$i]','$quantity[$i]')") or die("Invalid query: " . mysql_error());
}
}




mysql_close($link);


$to = "AWS Order <sjensen@amweatherseal.com>" . ", " ; // note the comma
$to .= "Monette Richards <mrichards@merrickgraphics.com>, ";
$to .= "Merrick Graphics <fulfillment@merrickgraphics.com>, ";
$to .= "Steve Merrick <smerrick@merrickgraphics.com>";

$subject = "AWS Dealer Request!";

$message = "<html>
<head><body>
At " . date("j/n/Y G:i:s") . " a request was placed by<br>" .
$name . "<br>" .
$company . "<br>" .
$address . "<br>" .
$address2 . "<br>" .
$city . ", " . $state . " " . $zip . "<br>" .
$phone . "<br>" .
$email . "<br>".
"AWS Dealer#:" . $dealer_no . "<br>".
"for <br>\n";
for ($i=0;$i<=$num_rows;$i++)
{

if ($quantity[$i]>=1){
$message .= $item[$i] . " : " . $quantity[$i] . " <br>\n";
}
}

$message .="<br>" . $comments .
"<br><br><br>Merrick Graphics. Service with a smile.\n" .
"</body>
</html>";

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";

/* additional headers */
$headers .= "From: Merrick Graphics Fullfilment Center <webmaster@merrickgraphics.com> \n";


/* and now mail it */
mail($to, $subject, $message, $headers);


$sent=1;

}




}

function CheckForm(aform) {
var errorString = "The following problems occurred: \r\r";
var validHandle = true;
if ( aform.address.value.length <= 0 ) {
errorString += "Address not supplied. \r";
validHandle = false;
}
if (validHandle == false) {
errorString += "\r";
alert(errorString+'\nPlease make changes and submit the form again.');
}
}

?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="AWSStyles.css" rel="stylesheet" type="text/css">


</head>

<body leftmargin="0" topmargin="00" marginwidth="0" marginheight="0">
<table width="768" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../SiteArt/AWS-Header.gif" width="768" height="152"></td>
</tr>
</table>
<table width="768" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr align="center">
<td width="10" height="20">&nbsp;</td>
<td width="1" bgcolor="#FFFFFF"><img src="../SiteArt/t_blank.gif" width="1" height="1"></td>
<td width="70"><a href=" class="MenuCopyText">Home</a></td>
<td width="1" bgcolor="#FFFFFF"><img src="../SiteArt/t_blank.gif" width="1" height="1"></td>
<td width="102"></td>
<td width="185"></td>
<td width="160"></td>
<td width="90"></td>
<td width="60"></td>
<td width="90"></td>
</tr>
</table>

<? if ($sent==1)
{

echo "<center>Your request has been delivered. Thank you.</center><br><br>\n";


}
else
{
?>
<form method="post" onSubmit="return CheckForm(this);">
<table border="0"><tr><td>
<table border="1"><tr><td>
<?

$link=mysql_connect($DBhost, $DBuser, $DBpass);
$r=mysql_select_db($DBname,$link);
$i=1;
$result=mysql_query("SELECT * from items where site LIKE '%%aw%%' or site LIKE '%%ad%%'") or die("Invalid query: " . mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<tr><td><font face=\"Arial, Helvetica, sans-serif\" color=\"#004D3D\">" . $row['name'] . "</font><br><a href=\"../images/large/" . $row['img'] . "\" target=\"window3\" onclick=\"javascript:window.open('', 'window3', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400, height=390')\"><img src=\"../images/" . $row['img'] . "\" border=\"0\" width=\"120\" height=\"83\"></a><br>" . stripslashes($row['id_code']) . "<br></td><td><input type=\"hidden\" name=\"item[" . $i . "]\" value=\"" . $row['id_code'] . "\"><input type=\"text\" name=\"quantity[" . $i. "]\" size=\"2\" value=\"" . $quantity[$i] . "\"> <font face=\"Arial, Helvetica, sans-serif\">Quantity</td></tr>\n";
$i++;
}
$num_rows = mysql_num_rows($result);
mysql_free_result($result);
mysql_close($link);
$i++;


?>

</td></tr></table>

</td><td valign="top">
<table border="0">
<tr><td colspan="2"><? echo $error_str1;?></td></tr>
<tr><td colspan="2"><? echo $error_str2;?></td></tr>
<tr><td><font color="#ff0000">*</font>Company: </td><td><input type="text" name="company" size="25" value="<?echo $company;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>Name: </td><td><input type="text" name="name" size="25" value="<?echo $name;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>Address: </td><td><input type="text" name="address" size="25" wrap="PHYSICAL" value="<?echo $address;?>"></td></tr>
<tr><td>Address: </td><td><input type="text" name="address2" size="25" wrap="PHYSICAL" value="<?echo $address2;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>City: </td><td><input type="text" name="city" size="25" value="<?echo $city;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>State: </td><td><input type="text" name="state" size="2" value="<?echo $state;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>Zip: </td><td><input type="text" name="zip" size="11" value="<?echo $zip;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>Phone: </td><td><input type="text" name="phone" size="25" value="<?echo $phone;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>Email: </td><td><input type="text" name="email" size="25" value="<?echo $email;?>"></td></tr>
<tr><td><font color="#ff0000">*</font>AWS Dealer#: </td><td><input type="text" name="dealer_no" size="25" value="<?echo $dealer_no;?>"></td></tr>
<tr><td>Comments: </td><td><textarea name="comments" cols="25" rows="5"><?echo $comments;?></textarea></td></tr>
<tr><td></td><td><input type="hidden" name="ordered" value="1"><input type="hidden" name="num_rows" value="<?echo $num_rows;?>"><input type="submit" value="sumbmit" name="Order"></td></tr>
</table>
</td></tr></table>





</form>
<?
}
?>
</body>
</html>
 
I gave JAVASCRIPT code, you're trying to use it as PHP which doesn't work.

So your page should be more like the following:

Code:
<?
include("../common.php");

if (isset($ordered)) {

$error1=0;
$error2=0;
$error_str1="";
$error_str2="";
    for ($i=0;$i<=$num_rows;$i++)
    {

        if ($quantity[$i]>150)
            {
            $error1=1;
            $error_str1="<font color=\"#ff0000\">For Quanities greater than 120, please contact a Customer Service Representative.</font>";
            $sent=0;
            }
    }
        if (($company=="") or ($name=="") or ($address=="") or ($city=="") or ($state=="") or ($zip=="") or ($phone=="") or ($email=="")or($dealer_no==""))
        {
        $error2=1;
        $error_str2="<font color=\"#ff0000\">Please fill in all required fields.</font>";
        $sent=0;
        }
If (($error1==0) && ($error2==0))
{

            $link=mysql_connect($DBhost, $DBuser, $DBpass);
            $r=mysql_select_db($DBname,$link);

            mysql_query("INSERT INTO orders (name, address, address2, city, state, zip,phone, email,comments,company,dealer_no,dated) VALUES ('$name','$address','$address2','$city','$state','$zip','$phone','$email','" . mysql_escape_string($comments) . "','$company','$dealer_no',now())")  or die("Invalid query: " . mysql_error());

            $ord_id=mysql_insert_id();

            for ($i=0;$i<=$num_rows;$i++)
            {

                if ($quantity[$i]>=1){
                mysql_query("INSERT INTO order_products (order_id, item_id, quantity) values ('$ord_id','$item[$i]','$quantity[$i]')") or die("Invalid query: " . mysql_error());
                }
            }




            mysql_close($link);


            $to  = "AWS Order <sjensen@amweatherseal.com>" . ", " ; // note the comma
            $to .= "Monette Richards <mrichards@merrickgraphics.com>, ";
            $to .= "Merrick Graphics <fulfillment@merrickgraphics.com>, ";
            $to .= "Steve Merrick <smerrick@merrickgraphics.com>";

             $subject = "AWS Dealer Request!";

             $message = "<html>
                  <head><body>
                   At " . date("j/n/Y G:i:s") . " a request was placed by<br>" .
                   $name .  "<br>" .
                   $company . "<br>" .
                   $address . "<br>" .
                   $address2 . "<br>" .
                   $city . ", " . $state . " " . $zip . "<br>" .
                   $phone . "<br>" .
                   $email . "<br>".
                     "AWS Dealer#:" . $dealer_no . "<br>".
                    "for <br>\n";
                   for ($i=0;$i<=$num_rows;$i++)
                         {

                        if ($quantity[$i]>=1){
                               $message .=    $item[$i] . " : " . $quantity[$i] . " <br>\n";
                           }
                    }

                    $message .="<br>" . $comments .
                     "<br><br><br>Merrick Graphics. Service with a smile.\n"  .
                    "</body>
                  </html>";

                  /* To send HTML mail, you can set the Content-type header. */
                  $headers  = "MIME-Version: 1.0\r\n";
                  $headers .= "Content-type: text/html; charset=iso-8859-1\n";

                  /* additional headers */
                  $headers .= "From: Merrick Graphics Fullfilment Center <webmaster@merrickgraphics.com> \n";


                  /* and now mail it */
              mail($to, $subject, $message, $headers);


    $sent=1;

        }




    }



?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="AWSStyles.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
function CheckForm(aform) {
  var errorString = "The following problems occurred: \r\r";
  var validHandle = true;
  if ( aform.address.value.length <= 0 ) {
    errorString += "Address not supplied. \r";
    validHandle = false;
  }
  if (validHandle == false) {
    errorString += "\r";
    alert(errorString+'\nPlease make changes and submit the form again.');
  }
}
</script>

</head>

<body leftmargin="0" topmargin="00" marginwidth="0" marginheight="0">
<table width="768" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../SiteArt/AWS-Header.gif" width="768" height="152"></td>
  </tr>
</table>
<table width="768" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
  <tr align="center">
    <td width="10" height="20">&nbsp;</td>
    <td width="1" bgcolor="#FFFFFF"><img src="../SiteArt/t_blank.gif" width="1" height="1"></td>
    <td width="70"><a href="[URL unfurl="true"]http://www.americanweatherseal.com/AboutUs-OurMission.htm"[/URL] class="MenuCopyText">Home</a></td>
    <td width="1" bgcolor="#FFFFFF"><img src="../SiteArt/t_blank.gif" width="1" height="1"></td>
    <td width="102"></td>
    <td width="185"></td>
    <td width="160"></td>
    <td width="90"></td>
    <td width="60"></td>
    <td width="90"></td>
  </tr>
</table>

<? if ($sent==1)
 {

echo "<center>Your request has been delivered. Thank you.</center><br><br>\n";


 }
 else
 {
 ?>
 <form method="post" onSubmit="return CheckForm(this);">
  <table border="0"><tr><td>
    <table border="1"><tr><td>
         <?

                          $link=mysql_connect($DBhost, $DBuser, $DBpass);
                        $r=mysql_select_db($DBname,$link);
                        $i=1;
                        $result=mysql_query("SELECT * from items where site LIKE '%%aw%%' or site LIKE '%%ad%%'")  or die("Invalid query: " . mysql_error());
                          while($row = mysql_fetch_array($result))
                          {
                            echo "<tr><td><font face=\"Arial, Helvetica, sans-serif\" color=\"#004D3D\">" . $row['name'] . "</font><br><a href=\"../images/large/" .  $row['img'] . "\" target=\"window3\" onclick=\"javascript:window.open('', 'window3', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400, height=390')\"><img src=\"../images/" . $row['img'] . "\" border=\"0\" width=\"120\" height=\"83\"></a><br>" . stripslashes($row['id_code']) . "<br></td><td><input type=\"hidden\" name=\"item[" . $i . "]\" value=\"" . $row['id_code'] . "\"><input type=\"text\" name=\"quantity[" . $i. "]\" size=\"2\" value=\"" . $quantity[$i] . "\"> <font face=\"Arial, Helvetica, sans-serif\">Quantity</td></tr>\n";
                            $i++;
                        }
                        $num_rows = mysql_num_rows($result);
                        mysql_free_result($result);
                        mysql_close($link);
                        $i++;


                      ?>

    </td></tr></table>

    </td><td valign="top">
    <table border="0">
    <tr><td colspan="2"><? echo $error_str1;?></td></tr>
    <tr><td colspan="2"><? echo $error_str2;?></td></tr>
    <tr><td><font color="#ff0000">*</font>Company: </td><td><input type="text" name="company" size="25" value="<?echo $company;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>Name: </td><td><input type="text" name="name" size="25" value="<?echo $name;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>Address: </td><td><input type="text" name="address" size="25" wrap="PHYSICAL" value="<?echo $address;?>"></td></tr>
    <tr><td>Address: </td><td><input type="text" name="address2" size="25" wrap="PHYSICAL" value="<?echo $address2;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>City: </td><td><input type="text" name="city" size="25" value="<?echo $city;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>State: </td><td><input type="text" name="state" size="2" value="<?echo $state;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>Zip: </td><td><input type="text" name="zip" size="11" value="<?echo $zip;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>Phone: </td><td><input type="text" name="phone" size="25" value="<?echo $phone;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>Email: </td><td><input type="text" name="email" size="25" value="<?echo $email;?>"></td></tr>
    <tr><td><font color="#ff0000">*</font>AWS Dealer#: </td><td><input type="text" name="dealer_no" size="25" value="<?echo $dealer_no;?>"></td></tr>
    <tr><td>Comments: </td><td><textarea name="comments" cols="25" rows="5"><?echo $comments;?></textarea></td></tr>
    <tr><td></td><td><input type="hidden" name="ordered" value="1"><input type="hidden" name="num_rows" value="<?echo $num_rows;?>"><input type="submit" value="sumbmit" name="Order"></td></tr>
    </table>
    </td></tr></table>





</form>
<?
}
?>
</body>
</html>


[cheers]
Cheers!
Laura
 
sleipnir214

I agree, but the poster was looking for an answer. Instead of giving the run-around, I thought I'd just post my response. I did indicate in my original response that the poster was looking for javascript, not php.

[cheers]
Cheers!
Laura
 
Sorry guys...i dint specify..dont be so upset and discuss about my mistake so much...
 
LTeeple:
I understand your wish to help a fellow member. But the site was divided into subject-specific fora for a reason.

I find it reasonable that a person who might have experience with neither JavaScript nor PHP might not understand your off-forum advice.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
zxcdf5je,
No one's upset, dont worry.

Some people wouldn't have answered your question, would've just told you to post elsewhere. I didn't see the immediate benefit in doing that, so I posted a response - indicating what language would be most appropriate for your problem. I stand by my action.

[cheers]
Cheers!
Laura
 
thanks so much for the help..but henceforth i wil definately keep in mind to read which section my problem should go to:)
really appreciate your help laura!!!

-Smiley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top