Page 1 of 2

How to make a popup confirmation when clicking submit

Posted: Sun Jul 11, 2004 10:23 pm
by Lucnet
I have developed a script for testimonials/feedback. When I or client adds a testimonial there is a message that comes up on the page itself saying, "Testimonial added". How can I make it where, if they hit submit , it will popup in like a windows looking box, saying "Testimonial added" ?

Posted: Sun Jul 11, 2004 10:28 pm
by feyd

Code: Select all

<script language="Javascript">alert('Testimonial added')</script>

Posted: Mon Jul 12, 2004 5:38 am
by Skittlewidth
Wouldn't that potentially give a false sense of security as to whether the tesimonial had successfully been submitted to the file/database/wherever its going?? If an error occured in the processing script the user would still have been told it had been successful.

Just a thought. You may have already considered this :)

Posted: Mon Jul 12, 2004 6:11 am
by furiousweebee
Maybe the wording could be "Now adding testimonial..." or something?

Posted: Mon Jul 12, 2004 6:55 am
by kettle_drum
Well this pop up can be on the page after the data has bee submitted to the database.

Posted: Mon Jul 12, 2004 7:00 am
by Skittlewidth
Yeah thats what I was trying to recommend in a rather poor way, since Lucnet did specifically say when the user clicked submit

Posted: Mon Jul 12, 2004 8:08 am
by Lucnet
You are saying with that code it will popup even if it doesn't submit it. hmm...

So how can I get it to display this after it is entered into the database?

Posted: Mon Jul 12, 2004 8:21 am
by Skittlewidth
Put the code somewhere on the page the data is submitted to for processing, after the query which submits the data to the database. :) Is there any particular reason you need it to be a windows style alert box?

Posted: Mon Jul 12, 2004 8:28 am
by Lucnet
No, it doesn't have to be a windows alert. I just mention that because I didn't know any other way to put it. I am very new at php, so thats the only way I could think to descrube what I want. If you look here http://lsscripts.com/testimonials/admin/show.php You can see the way the admin works. Click on Add Testimonial. When you fill the fields and hit submit it will popup at the top of the page saying,"You have added this to your database". I was wanting to get that out of there. I have tried to get it to show at the bottom, but I am unsure on how to do that so I thought a poup would be better.

Also here is the code the the page above:

Code: Select all

<?
$status = (!empty($_GET['status']) ? $_GET['status'] : '%');
include "../inc/config.php";
switch($action) {
	case "store":
		db();
                            $link_display=$HTTP_POST_VARS['link_display'];
		  mysql_query("INSERT INTO ls_testimonials SET link_display='$link_display', client_id='$client_id', email='$email', company='$company',  testimonials='$testimonials'");
		  db_close();
		  $pagecontent.="<HTML><BODY><b>You have just added a new testimonial to your system.</b></BODY></HTML>";
	break;
	case "code":
          $pagecontent.="<table width=44% border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC>
          <tr bordercolor=#CCCCCC> 
          <td width=49%>Implement random page</td>
          <td width=51%><textarea style=width=300; border: 1; rows=1>This will be used in the future, for generating random testimonials code. For now look in the document folder.</textarea></td>
            </tr>
          </table>";
    break;
	case "home":
          $pagecontent.="<table width=44% border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC>
          <tr bordercolor=#CCCCCC> 
          <td width=49%>Welcome to the Control Panel of LS Testimonials.</td>
            </tr>
          </table>";
    break;	
	case "add":
	db();
          $pagecontent.="<table width=60 border=0 cellspacing=0 cellpadding=0>
       <tr>
        <td align=center>
		<table width=500 border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC>
        <tr bordercolor=#CCCCCC> 
        <td width=27%><font size=2><strong>Client ID# :</strong></font></td>
        <td width=73%><form method=post><input name=client_id> (numbers only)</td>
      </tr>
        <tr bordercolor=#CCCCCC> 
        <td><font size=2><strong>Displayed Link</strong></font></td>
        <td> <input name=link_display> (displayed over website link)</td>
      </tr>
       <tr bordercolor=#CCCCCC> 
       <td><font size=2><strong>Website</strong></font></td>
       <td> <input name=company value=http://> (company website)</td>
      </tr>
       <tr bordercolor=#CCCCCC> 
       <td><font size=2><strong>Email</strong></font></td>
       <td> <input name=email> (must be a valid e-mail)</td>
      </tr>
        <tr bordercolor=#CCCCCC> 
        <td><font size=2><strong>Testimonial :</strong></font></td>
        <td> <textarea name=testimonials rows=7 cols=40></textarea></td>
      </tr>
        <tr bordercolor=#CCCCCC>
        <td>&nbsp;</td>
       <td><input type=hidden name=action value=store>
       <input type=submit value='Submit'></td>
     </tr>
       </table>
	   </td>
     </tr>
      </table>";
    break;
	case "approve":
		db();
		mysql_query("UPDATE ls_testimonials SET approved='y' WHERE id=$id");
		$pagecontent.="Item {$id} Approved<br><br>";
		db_close();
	break;
	case "hold":
		db();
		mysql_query("UPDATE ls_testimonials SET approved='h' WHERE id=$id");
		$pagecontent.="Item {$id} On Hold<br><br>";
		db_close();
	break;
	case "delete":
		db();
		mysql_query("DELETE FROM ls_testimonials WHERE id=$id");
		$pagecontent.="Item {$id} Deleted<br><br>";
		db_close();
	break;
	default:
	break;	
}
db();
$query = "SELECT * FROM ls_testimonials WHERE approved LIKE '$status'"; 
$formdata_res=mysql_query($query) or die("query failed: " . mysql_error()); 
$pagecontent.="<table width=760 border=0 cellspacing=0 cellpadding=0";
  $pagecontent.="<tr>";
    $pagecontent.="<td width=150></td>
	<td width=610>&nbsp;</td>
	</tr>
  <tr>
  <td valign=top><table width=150 border=0 cellpadding=2 cellspacing=0 background=../inc/skins/default/images/menu_bg.gif>
   <tr>
<td><font size=2><b>Menu</b></font></td>
   </tr>
  <tr>
<td><font size=2><a href=show.php?action=add>Add Testimonials</a></font></td>
   </tr>
  <tr>
<td><font size=2><a href=show.php?status=n>New Testimonials</a></font></td>
    </tr>
     <tr>
<td><font size=2><a href=show.php?status=h>On Hold Testimonials</a></font></td>
    </tr>
   <tr>
<td><font size=2><a href=show.php?status=y>Active Testimonials</a></font></td>
   </tr>
    <tr>
<td><font size=2><a href=show.php?action=code>Generate Code</a></font></td>
   </tr>
</table></td>";
   $pagecontent.="<td valign=top>
<table width=99% border=1 align=center cellpadding=0 cellspacing=1 bordercolor=#FFFFFF>";
while ($formdata=mysql_fetch_object($formdata_res)) {
	$client_id=htmlentities($formdata->client_id);
	$link_display=htmlentities($formdata->link_display);
	$email=htmlentities($formdata->email);
	$company=htmlentities($formdata->company);
	$testimonials=htmlentities($formdata->testimonials);
 $pagecontent.="<td bordercolor=#999999 bgcolor=#F1F1F1><font size=2><b>Client ID#:</b></font>{$client_id}</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
  <tr bordercolor=#666666>
<td width=203 bgcolor=#F1F1F1><font size=2><b>Display:</b></font></td>
<td width=203 bgcolor=#F1F1F1><font size=2><b>Email:</b></font></td>
<td width=203 bgcolor=#F1F1F1><font size=2><b>Website:</b></font></td></tr>
  </tr>
  <tr bordercolor=#666666>
<td width=203 bgcolor=#E9EDF0><font size=2>{$link_display}</font></td>
<td width=203 bgcolor=#E9EDF0><font size=2><a href='mailto:{$email}'>{$email}</a></font></td>
<td width=203 bgcolor=#E9EDF0><font size=2><a href='{$company}' target=new>{$company}</a></font></td>
    </tr>
   <tr bordercolor=#666666>
<td colspan=2><font size=2><b>Testimonial:</b></font><textarea style=width=300; border: 1; rows=1>{$testimonials}</textarea></td>
<td><center><a href='?id={$formdata->id}&action=approve'><img src=../inc/skins/default/images/approve.gif width=17 height=17 border=0 ALT=Approve></a> 
<a href='?id={$formdata->id}&action=hold'><img src=../inc/skins/default/images/hold.gif width=17 height=17 border=0 ALT=Hold></a> 
<a href='?id={$formdata->id}&action=delete'><img src=../inc/skins/default/images/delete.gif width=17 height=17 border=0 ALT=Delete></a> </center></td>
  </tr>
  <tr> 
<td colspan=3>&nbsp;</td>
   </tr>";
}
$pagecontent.="</table></td>
  </tr>
  <tr> 
  <td>&nbsp;</td>
<td>&nbsp;</td>";
//<!-- DO NOT REMOVE THIS CODE BELOW -->
$pagecontent.="</tr>
<tr>
    <td>&nbsp;</td>
    <td><div align=center>
        <p>&nbsp;</p>
        <p><font size=2>Powered by: <a href=http://www.lsscripts.com>LS Testimonials</a></font> 
          <br>
          <font size=2>Ver. 1.0</font> </p>
      </div></td>
  </tr>";
//<!-- COPYRIGHT CODES END -->
$pagecontent.="</table>";
db_close();

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Approval Page</title>
</head>
<body>
</body>
<?=$pagecontent;?>
</html>

Posted: Mon Jul 12, 2004 8:53 am
by Skittlewidth
Right ok. So you don't need this alert box at all. You'll only end up with an unnecesary bit of javascript.

I see this script puts absolutely everything into one variable called $pagecontent. This has its advantages and disadvantages, and as you are a newcomer to php I probably wouldn't think this was the best way of doing things. I will presume that you know HTML.

In a nutshell all you need to do is move the words

Code: Select all

<b>You have just added a new testimonial to your system</b>
down to the bottom of the script just above where it says <DO NOT REMOVE THIS CODE BELOW>.
so that instead of

Code: Select all

$pagecontent.="</table></td> 
  </tr> 
  <tr> 
  <td> </td> 
<td> </td>";
it says

Code: Select all

$pagecontent.="</table></td> 
  </tr> 
  <tr> 
  <td>b>You have just added a new testimonial to your system</b> </td> 
<td> </td>";
You'll probably need to experiment with the layout of your table to get it right where you want it, but basically I've just moved it to an empty cell at the bottom of the layout table.

Personally I find it easier to code my empty html pages and tables how I want them as I would for a plain html site and then use opening and closing <?php tags to get the infomation where I want it rather than trying to put it all into one variable. It might look neat at the end of the script but its a pain to write and an unnecessary complication.

Let me know if you don't understand what I said above and I'll break it down some more. :D

Posted: Mon Jul 12, 2004 8:57 am
by Lucnet
Well by doing that, it just shows the text everytime. I left it in there so you can see what I mean.

Posted: Mon Jul 12, 2004 9:14 am
by Skittlewidth
Ah! Sorry, I didn't notice that the page was submiting to itself. Let me have another look and I'll get back to you in a sec! Whoops! :oops:

Posted: Mon Jul 12, 2004 9:34 am
by Skittlewidth
First of all look at the bottom of you script where its says:

Code: Select all

<?php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<title>Approval Page</title> 
</head> 
<body> 
</body> 
<?=$pagecontent;?> 
</html> 
?>
and move <? =$pagecontent;?> between the opening and closing <body> tag.

Code: Select all

<?php
$displaymessage = 0;
switch($action) { 
case "store": 
      db(); 
        $link_display=$HTTP_POST_VARS['link_display']; 
        mysql_query("INSERT INTO ls_testimonials SET link_display='$link_display', client_id='$client_id', email='$email', company='$company',  testimonials='$testimonials'"); 
        db_close(); 
        $pagecontent.="<HTML><BODY><b>You have just added a new testimonial to your system.</b></BODY></HTML>"; 
$displaymessage = 1;
   break;
case "code": 
          $displaymessage =0;
          $pagecontent.="<table width=44% border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC> 
          <tr bordercolor=#CCCCCC> 
          <td width=49%>Implement random page</td> 
          <td width=51%><textarea style=width=300; border: 1; rows=1>This will be used in the future, for generating random testimonials code. For now look in the document folder.</textarea></td> 
            </tr> 
          </table>"; 
    break; 
   case "home": 
          $displaymessage =0;
          $pagecontent.="<table width=44% border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC> 
          <tr bordercolor=#CCCCCC> 
          <td width=49%>Welcome to the Control Panel of LS Testimonials.</td> 
            </tr> 
          </table>"; 
    break;    
   case "add": 
         $displaymessage = 0;
   db(); 
          $pagecontent.="<table width=60 border=0 cellspacing=0 cellpadding=0> 
       <tr> 
        <td align=center> 
      <table width=500 border=1 cellpadding=2 cellspacing=3 bordercolor=#000000 bgcolor=#CCCCCC> 
        <tr bordercolor=#CCCCCC> 
        <td width=27%><font size=2><strong>Client ID# :</strong></font></td> 
        <td width=73%><form method=post><input name=client_id> (numbers only)</td> 
      </tr> 
        <tr bordercolor=#CCCCCC> 
        <td><font size=2><strong>Displayed Link</strong></font></td> 
        <td> <input name=link_display> (displayed over website link)</td> 
      </tr> 
       <tr bordercolor=#CCCCCC> 
       <td><font size=2><strong>Website</strong></font></td> 
       <td> <input name=company value=http://> (company website)</td> 
      </tr> 
       <tr bordercolor=#CCCCCC> 
       <td><font size=2><strong>Email</strong></font></td> 
       <td> <input name=email> (must be a valid e-mail)</td> 
      </tr> 
        <tr bordercolor=#CCCCCC> 
        <td><font size=2><strong>Testimonial :</strong></font></td> 
        <td> <textarea name=testimonials rows=7 cols=40></textarea></td> 
      </tr> 
        <tr bordercolor=#CCCCCC> 
        <td> </td> 
       <td><input type=hidden name=action value=store> 
       <input type=submit value='Submit'></td> 
     </tr> 
       </table> 
      </td> 
     </tr> 
      </table>"; 
    break; 
   case "approve": 
      $displaymessage = 0;
      db(); 
      mysql_query("UPDATE ls_testimonials SET approved='y' WHERE id=$id"); 
      $pagecontent.="Item {$id} Approved<br><br>"; 
      db_close(); 
   break; 
   case "hold": 
      $displaymessage = 0;
      db(); 
      mysql_query("UPDATE ls_testimonials SET approved='h' WHERE id=$id"); 
      $pagecontent.="Item {$id} On Hold<br><br>"; 
      db_close(); 
   break; 
   case "delete": 
      $displaymessage = 0;
      db(); 
      mysql_query("DELETE FROM ls_testimonials WHERE id=$id"); 
      $pagecontent.="Item {$id} Deleted<br><br>"; 
      db_close(); 
   break; 
   default: 
   break;    
} 

?>
Then down at the bottom of the script....

Code: Select all

<?php
if ($displaymessage == 1){
$pagecontent.="</table></td> 
  </tr> 
  <tr> 
  <td> You have just added a new testimonial to your system</td> 
<td> </td>"; 
}
else if ($displaymessage ==0)
{
$pagecontent.="</table></td>
</tr>
<tr>
<td></td>
<td></td>";
}
}
//<!-- DO NOT REMOVE THIS CODE BELOW --> 
$pagecontent.="</tr> 
<tr> 
    <td> </td> 
    <td><div align=center> 
        <p> </p> 
        <p><font size=2>Powered by: <a href=http://www.lsscripts.com>LS Testimonials</a></font> 
          <br> 
          <font size=2>Ver. 1.0</font> </p> 
      </div></td> 
  </tr>"; 
//<!-- COPYRIGHT CODES END --> 


?>
Obviously I haven't been able to test it, but try adding that bit into the relevant places in your script! Off for a break...brb! ;)

Posted: Mon Jul 12, 2004 10:46 am
by Lucnet
Well it is a step closer, whats happening now is when I add a testimonial by hitting submit the form for adding testimonials will disappear and just show the "added to database info." But the info is still in the same spot.

Posted: Mon Jul 12, 2004 10:50 am
by Skittlewidth
It is only showing up when you have submitted info though isn't it? Let me know if I got it wrong.

You'll have to mess around with your table layouts to make it appear exactly where you want it, I'm just trying to show you how it could be done.
You weren't supposed to get rid of the rest of the script, just substitute the bits I wrote in the relevant places. It was such a long script I thought that if I pasted the whole thing you wouldn't see what my changes were. Keep working on it and eventually you will get what you want :). The idea was just to use a variable to activate the message to display at the later point in the script if desired.

As for me its home time! Back tomorrow!