Jump to content

Recommended Posts

I got the variables down and everything it works I even tested it!! But I want it to send the message when somone fills it out instead of everytime i refresh it sends the message, lol :)

 

thanks

 

$SDK->write_pm ("1", "Hello!", "Hello! This is a test message sent to user id 1");

 

 

Currently everytime i refresh my page it sends this message to user id 1 of my forum [witch is me] and title: Hello! and message next..

 

How can i put this into a form so people can fill out what to say and to who and click submit.. so it doesnt send message everytime u refresh.

 

here is the function for it:

 

function write_pm($to_id, $title, $message, $cc = array(), $sentfolder = '0') {
	if (!$this->is_loggedin()) {
		$this->sdkerror($this->lang['sdk_membersonly']);
		return FALSE;
	}
	if (!$to_id) {
		$this->sdkerror($this->lang['sdk_pm_no_recipient']);
		return FALSE;
	}
	if (!$title OR strlen($title) < 2) {
		$this->sdkerror($this->lang['sdk_pm_title']);
		return FALSE;
	}
	if (!$message OR strlen($message) < 2) {
		$this->sdkerror($this->lang['sdk_pm_message']);
		return FALSE;
	}

	$sendto = array();

	$this->DB->query("SELECT m.name, m.id, m.view_pop, m.mgroup, m.email_pm, m.language, m.email, m.msg_total, g.g_use_pm, g.g_max_messages FROM ibf_groups g, ibf_members m WHERE m.id='" . intval($to_id) . "' AND g.g_id=m.mgroup");
	if ($row = $this->DB->fetch_row()) {
		// Just incase
		if (!$row['id']) {
			$this->sdkerror($this->lang['sdk_pm_mem_notexist']);
			return FALSE;
		}
		// Permissions Check
		if ($row['g_use_pm'] != '1') {
			$this->sdkerror($this->lang['sdk_pm_mem_disallowed']);
			return FALSE;
		}
		// Space Check
		if ($row['msg_total'] >= $row['g_max_messages'] AND $row['g_max_messages'] > 0) {
			$this->sdkerror($this->lang['sdk_pm_mem_full']);
			return FALSE;
		}
		// Block Check
		if ($this->is_pmblocked($GLOBALS['ibforums']->member['id'], intval($to_id))) {
			$this->sdkerror($this->lang['sdk_pm_mem_blocked']);
			return FALSE;
		}
		// CC Users
		$ccusers = array();

		if ($GLOBALS['ibforums']->member['g_max_mass_pm']) {
			if (is_array($cc) AND count($cc) > 0) {
				if (count($cc) > $GLOBALS['ibforums']->member['g_max_mass_pm']) {
					$this->sdkerror($this->lang['sdk_pm_cclimit']);
					return FALSE;
				}

				foreach ($cc AS $i) {
					// Check CC user stuff
					// I really should clean up the code here, it uses alot of queries in some cases, which isn't good. Should really merge this with the main sending message code instead of replicating stuff for CCs.
					$this->DB->query("SELECT m.name, m.id, m.view_pop, m.mgroup, m.email_pm, m.language, m.email, m.msg_total, g.g_use_pm, g.g_max_messages FROM ibf_groups g, ibf_members m WHERE m.id='" . intval($to_id) . "' AND g.g_id=m.mgroup");
					if ($ccrow = $this->DB->fetch_row()) {
						// Permissions Check
						if ($ccrow['g_use_pm'] != '1') {
							$this->sdkerror($this->lang['sdk_pm_rec_disallowed']);
							return FALSE;
						}
						// Space Check
						if ($ccrow['msg_total'] >= $ccrow['g_max_messages'] AND $ccrow['g_max_messages'] > 0) {
							$this->sdkerror($this->lang['sdk_pm_rec_full']);
							return FALSE;
						}
						// Block Check
						if ($this->is_pmblocked($GLOBALS['ibforums']->member['id'], intval($to_id))) {
							$this->sdkerror($this->lang['sdk_pm_rec_blocked']);
							return FALSE;
						}
					}

					$ccusers[] = intval($i);
				}
			}
		}
		// Actually send it
		$ccusers[] = intval($to_id);

		foreach ($ccusers as $recipient) {
			$DBstring = $GLOBALS['std']->compile_db_string(array('member_id' => $recipient,
					'msg_date' => time(),
					'read_state' => '0',
					'title' => $title,
					'message' => $GLOBALS['std']->remove_tags($message),
					'from_id' => $GLOBALS['ibforums']->member['id'],
					'vid' => 'in',
					'recipient_id' => $recipient,
					'tracking' => '0',
					));
			// Insert
			$this->DB->query ('INSERT INTO ibf_messages (' . $DBstring['FIELD_NAMES'] . ') VALUES (' . $DBstring['FIELD_VALUES'] . ')');
			unset($this->DBstring);

			$this->DB->query("UPDATE ibf_members SET msg_total = msg_total + 1, new_msg = new_msg + 1, msg_from_id='" . $GLOBALS['ibforums']->member['id'] . "', show_popup='1', msg_msg_id='" . $this->DB->get_insert_id() . "' WHERE id='" . $recipient . "'");
		}

		if ($sentfolder) {
			$DBstring = $GLOBALS['std']->compile_db_string(array('member_id' => $GLOBALS['ibforums']->member['id'],
					'msg_date' => time(),
					'read_state' => '0',
					'title' => 'Sent: ' . $title,
					'message' => $GLOBALS['std']->remove_tags($message),
					'from_id' => $GLOBALS['ibforums']->member['id'],
					'vid' => 'sent',
					'recipient_id' => $recipient,
					'tracking' => '0',
					));

			$this->DB->query ('INSERT INTO ibf_messages (' . $DBstring['FIELD_NAMES'] . ') VALUES (' . $DBstring['FIELD_VALUES'] . ')');
		}

		return TRUE;
	} else {
		$this->sdkerror($this->lang['sdk_pm_mem_notexist']);
		return FALSE;
	}
}

 

if u needed that just incase ;p;

 

 

Everything thing works I just need know how to make a form so people can fill it out and press submit for it to work instead of refreshing page and then it load all the time..

Link to comment
https://forums.phpfreaks.com/topic/157326-how-do-i-add-this-into-a-form/
Share on other sites

In a PHP file, use xHTML to write out the form with the necessary fields (message, title, etc). Using PHP, check if the form is submitted and if so, send the PM.

 

I cant use xhtml only html

 

Can u start the form for me, I can finish i hope and i can hope i use html

 

This forum doesn't handle requests. Please read #12 of Forum Rules. Follow the link in my signature. But if you can't write a form, it's most likely you will need someone to write this for you. o.o

 

Thank you!

 

im not requesting anything.. this is php help isnt it? looks like no help for me :(

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.