Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help creating a PM system

    Hey guys,

    I'm trying to make a pm system and below is what I have so far. I'm not very knowledgeable in javascript and I'm struggling to find why my error messages are not returning if the submit button is executed.

    Any help would be greatly appreciated.

    Thanks!

    Code:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    session_start();
    $userid = $_SESSION['userid'];
    $username = $_SESSION['username'];
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    		<title>Title</title>
    		<link href="./style.css" rel="stylesheet" type="text/css" />
    
    
    	<script type="text/javascript">
    	
    	//START PRIVATE MESSAGING STUFF
    	$('$pmForm').submit(function(){$('input[type=submit]',this).attr('disabled', 'disabled');});
    	function sendPm () {
    		var pmSubject = $("#pmSubject");
    		var pmTextArea = $("#pmTextArea");
    		var sendername = $("#sendername");
    		var senderid = $("#senderid");
    		var recName = $("#recName");
    		var recID = $("#recID");
    		var pm_wipit = $("#pm_wipit");
    		var url = $("#scripts_for_profile/private_msg_parse.php");
    		if (pmSubject.val() == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);
    		};
    		else if (pmTextArea.val() == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);
    		};
    		else {
    			// Access jQuery's Ajax mechanisms here for sending and receiving data without page refresh.
    		}
    	}
    	</script>
    
    
    
    	</head>
    <body>
    	<?php
    
    	if ($username && $userid) { ?>
    
    		<!-- START DIV that contains the PRIVATE MESSAGE form -->
    		<div class="interactContainers" id="private_messages">
    			
    			<form action="javascript:sendPM();" name="pmForm" id="pmForm" method="post">
    				<font size="+1">Sending Private Messages to <strong><em><?php echo "$username"; ?></em></strong></font></br></br>
    				Subject:
    				<input name="pmSubject" id="pmSubject" type="text" maxlength="64" style="width:98%;"/>
    				Message:
    				<textarea name="pmTextArea" id="pmTextArea" rows="8" style="width:98%;"></textarea>
    				
    				<input name="pm_sender_id" id="pm_sender_id" type="hidden" value="<?php echo $_SESSION['userid'];; ?>" />
    				<input name="pm_sender_name" id="pm_sender_name" type="hidden" value="<?php echo $_SESSION['username'];; ?>" />
    			
    				<input name="pm_rec_id" id="pm_rec_id" type="hidden" value="<?php echo $userid; ?>" />
    				<input name="pm_rec_name" id="pm_rec_name" type="hidden" value="<?php echo $username; ?>" />
    				<input name="pmWipit" id="pmWipit" type="hidden" value="<?php echo $thisRandNum; ?>" />
    				<span id="PMStatus" style="color:#F00;"></span>
    				<br /><input name="pmSubmit" type="submit" value="Submit" /> or <a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('private_message');">Close</a>
    			</form>
    		</div>
    		<!-- END DIV that contains the Private Message form -->
    
    	<?php }		
    	else
    		echo "Please login to access this page. <a href='http://aerithea.com/login/login.php'>Login here</a>";
    	?>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    Remove the form action and method, to use a simple button (type='button' instead of 'submit'). There is no need to submit the form with Ajax. Attach an event to call the function SendPm with an onclick on this button.

    For Ajax call, see (for example) w3schools.com jQuery Ajax introduction and jQuery Ajax get() and post() Methods...
    Last edited by 007julien; 08-16-2013 at 06:56 PM.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,444
    Thanks
    11
    Thanked 598 Times in 578 Posts
    Code:
    var url = $("#scripts_for_profile/private_msg_parse.php");
    that doesn't look right...
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The semicolon in the if-blocks is also wrong.
    Code:
    		if (pmSubject.val() == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);
    		};
    		else if (pmTextArea.val() == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);
    		};
    		else {
    			// Access jQuery's Ajax mechanisms here for sending and receiving data without page refresh.
    		}
    And I don't see the jQuery file included on the page.

    Quote Originally Posted by 007julien View Post
    Remove the form action and method, to use a simple button (type='button' instead of 'submit'). There is no need to submit the form with Ajax. Attach an event to call the function SendPm with an onclick on this button.
    That is not a good advice. Whenever practical, the form should work even without javascript.

    Here's I would solve it:
    Code:
    $(document).ready(function() { 
    	$('#pmForm').on('submit', sendPm);
    
    	function sendPm (e) {
    		e.preventDefault(); //prevent the form from being submitted
    		var pmSubject = $("#pmSubject");
    		var pmTextArea = $("#pmTextArea");
    		var sendername = $("#sendername");
    		var senderid = $("#senderid");
    		var recName = $("#recName");
    		var recID = $("#recID");
    		var pm_wipit = $("#pm_wipit");
    		var url = this.action;
    		if ($.trim(pmSubject.val()) == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);			
    		}
    		else if ($.trim(pmTextArea.val()) == "") {
    			$("#interactionResults").html('<img src="images/round_error.jpg" alt="Error" width="31" height="30" /> $nbsp; Please type a subject.').show().fadeOut(6000);			
    		}
    		else {
    			// Access jQuery's Ajax mechanisms here for sending and receiving data without page refresh.
    		}
    	}
    });
    Code:
    <form action="scripts_for_profile/private_msg_parse.php" name="pmForm" id="pmForm" method="post">
       ...
       <input name="pmSubmit" type="submit" value="Submit" />
     </form>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •