Jump to content

Recommended Posts

Posted

hoping some night owl will be able to see something i can't.

 

basically you load a page i.e. page.php, it brings in the code from pmform.php (below) via a require call. when you submit it goes to page.php?step=1

 

here is the relevant part of page.php. this is where step=1, i.e. they have just submitted the form.

>$bad = "true";
if($message == '' || $sendto == '')
{
echo 'No fields may be left blank.';
}
else
{
if(!checkexist($sendto))
{
echo 'That user does not exist. Check the name and try again.';
}
else
{
 if (sendpm($sendto, $message, $username))
 {
 echo 'Message has been delivered!';
 $bad = "false";
 }
 else
 {
 echo 'An error occurred. Message not sent. Please try again in a few minutes.';
 }
}
}
if($bad == "true")
{
echo '<br/>';
require('pmform.php');
}

 

 

here is pmform.php:

><form method="post" action="url/page.php?step=1">
To:
<input title="To" size="10" maxlength="10" name="sendto" value="<?=$sendto?>" /> <br />
Message:
<input title="Message" maxlength="255" value="<?=$message?>" name="message" /> <br />
<input type="submit" value="Send" />
</form>

 

$sendto and $message are not necessarily set, so when they aren't, it's just a blank form. however if $bad = true, i.e. something went wrong, it loads the form into the page again but $message and $sendto ARE set because the user just submitted it, it just had something wrong with it.

 

my problem is that no matter what, $sendto is always blank. $message is coming through fine but i am getting the "No fields may be blank" error every time and the form fills out the sendto field as blank and the message field with the message. When i took out the blankfield check, it came up with that the user did not exist. this was working fine a bit ago and i must have changed something cause now it won't work. can anyone see something i can't?

Posted

I can't tell you 100% that this is the answer... but it's a change you should definitely make.

 

You shouldn't program with the assumption that globals are configured 'on' (which they are).

 

The start of your code should initialize your posted data in a manner close to this:

 

>$sendto = $_POST['sendto'];
$message = $_POST['message'];

 

now, to debug your script, I would add this to the top of page.php

 

>$var = $_POST;
print_r($var);
exit;

 

That should show you all the posted data and give you an idea of what is missing and maybe some ideas as to why.

 

One last thing... although it's good to know how to write your own code and this is a wonderful way to learn php, it appears that the code you are writing already exists. You seem to be creating a checkbox of email recipients and a manner to email them.

 

Why reinvent the wheel?

Posted

Thanks. Initializing the posted variables worked.

 

I may be reinventing the wheel, but I think the intent of the script is a bit different than you think it is (or it may not be). On the form, the person enters the username of someone and a message and it sends them a private message.

Privatechat.php has the mysql database variables and opens the connection.

 

string propersn (string $sn) returns $sn without spaces and all lowercase for comparative purposes, i.e. logging in as 'HaR R Y' is the same as 'h Arry'.

 

On any given page, there is a bool newpm($sn) function that checks to see if any messages have sentto = $sn and readyet = 0, and if returned true, a link to view your private message inbox is displayed.

 

>function sendpm($to, $msg, $from)
{
require ('/home/glassgo/offline/privatechat.php');

$go = time();
$to = propersn($to);
$from = propersn($from);

$chatquery = "insert into $dbtabl (sentfrom, sentto, sentwhen, message, readyet) values ('$from','$to','$go','$msg','0')";
$chatreturn= mysql_query($chatquery,$link);

mysql_close ($link);

return $chatreturn;
}

 

Anyway, thanks for your help. I hope I didn't reinvent the wheel cause it took a long time to throw all these pages together. It's especially tough to get wireless browsers to accept it! They are the most uninformative browsers ever and just about everything is improper syntax when it comes to them.

 

One last thing, what do you think I'm reinventing? It may be useful / prettier / easier etc to kill my code and replace it with whatever already exists.

Posted

I thought you were trying to reinvent the web based contact form.

 

But it sounds like you could actually borrow from the private message posts from Invision Board or phpBB

 

Good luck.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...