Jump to content

Recommended Posts

Hi all,

 

I am ving a few problem with a shoutbox for Joomla 1.5. I have a file called helper.php which is used for the functions and a file called default.php which shows the form and shouts made and so on.

 

The function for adding a shout from the helper.php file is

 

function addShout($name, $message, $ip) {
	global $mainframe;
	$timesql = date( 'Y-m-d H:i:s', time()+(5*60*60));
	$data->id = NULL;
	$data->name = $name;
	$data->when = $timesql;
	$data->ip = $ip;
	$data->msg = $message;
	$db = JFactory::getDBO();
	$db->insertObject('#__shoutbox', $data, id);
}

 

however I want to make the adding of shouts jquery based so that the page doesnt refresh once someone has submitted a shout. This way it will just inset into the shoutbox.

 

The code I am using for this is

 

$(document).ready(function(){
//global vars
var inputUser = $("#name");
var inputMessage = $("#message");
var loading = $("#loading");
var messageList = $(".content > ul");

//functions
function updateShoutbox(){
	//just for the fade effect
	messageList.hide();
	loading.fadeIn();
	//send the post to shoutbox.php
	$.ajax({
		type: "POST", url: "JPATH_SITE.DS.'modules'.DS.'mod_shoutbox'.DS.'helper.php'", data: "action=update",
		complete: function(data){
			loading.fadeOut();
			messageList.html(data.responseText);
			messageList.fadeIn(2000);
		}
	});
}
//check if all fields are filled
function checkForm(){
	if(inputUser.attr("value") && inputMessage.attr("value"))
		return true;
	else
		return false;
}

//Load for the first time the shoutbox data
updateShoutbox();

//on submit event
$("#form").submit(function(){
	if(checkForm()){
		var name = inputUser.attr("value");
		var message = inputMessage.attr("value");
		//we deactivate submit button while sending
		$("#submit").attr({ disabled:true, value:"Sending..." });
		$("#submit").blur();
		//send the post to shoutbox.php
		$.ajax({
			type: "POST", url: "JPATH_SITE.DS.'modules'.DS.'mod_shoutbox'.DS.'helper.php'", data: "action=insert&name=" + name + "&message=" + message,
			complete: function(data){
				messageList.html(data.responseText);
				updateShoutbox();
				//reactivate the send button
				$("#submit").attr({ disabled:false, value:"Shout it!" });
			}
		 });
	}
	else alert("Please fill all fields!");
	//we prevent the refresh of the page after submitting the form
	return false;
});
});
</script>

 

However when I click the subit button, the shout doesnt get send cause I cant seem to retrieve the function from the helper.php.

 

This line which you will find in the code above

type: "POST", url: "JPATH_SITE.DS.'modules'.DS.'mod_shoutbox'.DS.'helper.php'", data: "action=insert&name=" + name + "&message=" + message,

must be incorrect.

 

Could someone please tell me what I am doing wrong with a possible solution. This would be much appreciated.

 

Regards

 

Lodder

Link to comment
https://forums.phpfreaks.com/topic/255434-help-with-joomla-15-shoutbox/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.