Jump to content
php.lv forumi

Atvērt popup p\ec formas funkcijas


ziedinjsh

Recommended Posts

Saistībā ar citu jautājumu man radās šāds: Kā var atvēr popup kurā parādās pievienošanas rezūltāts?

 

<?php
$data = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE user_email='".$_SESSION['user_email']."' LIMIT 1"));
$users = mysql_query("SELECT * FROM users");

if(isset($_POST['send_msg'])){

$msg_to = $_POST['msg_to'];
$msg_from = $data['user_id'];
$msg_title = mysql_real_escape_string($_POST['msg_title']);
$msg_text = mysql_real_escape_string($_POST['msg_text']);
$msg_date = date("Y-m-d H:i:s");
$msg_status = "0";

$sql = ("INSERT INTO messages (msg_to, msg_from, msg_title, msg_text, msg_date, msg_status) VALUES ('$msg_to', '$msg_from', '$msg_title', '$msg_text', '$msg_date', '$msg_status')");
$result = mysql_query($sql);

if($result){
// šeit atveras popup document.getElementById('succsess').style.display='block';document.getElementById('fade').style.display='block'
}else{
// šeit atveras popup document.getElementById('error').style.display='block';document.getElementById('fade').style.display='block'
}

}
echo "<div id='new-msg'>";
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<p>Kam</p><p><select name='msg_to' class='msgselect'>";
while ($data = mysql_fetch_array( $users )) {
echo "<option value='".$data['user_id']."'>".$data['user_name']."</option>";
}
echo "</select></p>";	

		echo "<p>Tēma</p> <p><input type='text' name='msg_title' class='msgtitle'></p>";
			echo "<p>Saturs</p> <p><textarea name='msg_text' class='msgtext'></textarea></p>";
				echo "<p><input type='submit' name='send_msg' value='Sūtīt vēstuli' class='msgbutton'></p>";
echo "</form>";				
echo "</div>";


openpopup("succsess");
echo "Vēstule veiksmīgi nosūtīta!";
closepopup();
openpopup("error");
echo "Vēstule nav nosūtīta...";
closepopup();
?>

 

Kā tas ir panākāms!?

Edited by ziedinjsh
Link to comment
Share on other sites

neiet vienalga.. vai arī es nepareizi daru kaut ko!

<?php
$data = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE user_email='".$_SESSION['user_email']."' LIMIT 1"));
$users = mysql_query("SELECT * FROM users");

if(isset($_POST['send_msg'])){

$msg_to = $_POST['msg_to'];
$msg_from = $data['user_name'];
$msg_title = mysql_real_escape_string($_POST['msg_title']);
$msg_text = mysql_real_escape_string($_POST['msg_text']);
$msg_date = date("Y-m-d H:i:s");
$msg_status = "0";

$sql = ("INSERT INTO messages (msg_to, msg_from, msg_title, msg_text, msg_date, msg_status) VALUES ('$msg_to', '$msg_from', '$msg_title', '$msg_text', '$msg_date', '$msg_status')");
$result = mysql_query($sql);

if($result){
?>
<script language="javascript" type="text/javascript">
document.getElementById('succsess').style.display='block';document.getElementById('fade').style.display='block';
</script>
<?php
}else{
?>
<script language="javascript" type="text/javascript">
document.getElementById('error').style.display='block';document.getElementById('fade').style.display='block';
</script>
<?php
}

}
echo "<div id='new-msg'>";
echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "<p>Kam</p><p><select name='msg_to' class='msgselect'>";
while ($data = mysql_fetch_array( $users )) {
echo "<option value='".$data['user_name']."'>".$data['user_name']."</option>";
}
echo "</select></p>";	

		echo "<p>Tēma</p> <p><input type='text' name='msg_title' class='msgtitle'></p>";
			echo "<p>Saturs</p> <p><textarea name='msg_text' class='msgtext'></textarea></p>";
				echo "<p><input type='submit' name='send_msg' value='Sūtīt vēstuli' class='msgbutton'></p>";
echo "</form>";				
echo "</div>";


openpopup("succsess");
echo "Vēstule veiksmīgi nosūtīta!";
closepopup();
openpopup("error");
echo "Vēstule nav nosūtīta...";
closepopup();
?>

 

popup:

function openpopup($title){
echo "<div id='$title' class='wstyle'>";
echo "<div class='popup'>";
	echo "<div class='content'>";
		echo "<a href = \"javascript:void(0)\" onclick = \"document.getElementById('$title').style.display='none';document.getElementById('fade').style.display='none'\"><img class='close' src='img/close.png'></a>";
}
function closepopup(){
	echo "</div>";
echo "</div>";
echo "</div>";
}

Link to comment
Share on other sites

<script type="text/javascript">
<!--
YOUR SCRIPT HERE
-->
</script>

Šitā nav īsti labi.

Būtu jābāt:

 

<!-- priekš HTML5 -->
<script src="/path/tp/your.js"></script>

<!-- priekš XHTML 1.0 Strict -->
<script src="/path/tp/your.js" type="text/javascript"></script>

 

 

Un pilnīgi noteikti NE ŠITĀ

 echo "<a href = \"javascript:void(0)\" onclick = \"document.getElementById('$title').style.display='none';document.getElementById('fade').style.display='none'\">
<img class='close' src='img/close.png'></a>";

 

Ziediņš, varbūt ir pienācis laiks beidzot iemācīties javascript : http://eloquentjavascript.net/index.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...