...

View Full Version : For the love of god please...



KRAK_JOE
03-18-2006, 06:35 PM
Here's a form, lovely isn't it.....



<form action="send.php" method="post" >
<table border="0" bgcolor="#f0f0f0" ID="Table1">
<tr>
<td valign="top">Recipient:</td>
<td>
<input size="13" type="text" name="Recipient" value="+44">
<br>
<font size="1" face="sans-serif"><b><font color="#700000">UK RECIPITENTS ONLY </font></b></font> </td>
</tr>
<tr>
</tr>
<tr>
<td valign="top">Message:<br>(max. 160 chars)</td>
<td>
<textarea rows="3" name="Message" cols="38"></textarea>
</td>
</tr>
</table>
<br>
<input type="submit" value="Send Message">
<br>
<br>
<b>IMPORTANT:</b> Please press the button <b>only once</b>, and allow some time for the SMS to be processed.
</form>

What I would like is somebody to change this so that the first field is validated by PHP - (because js can be disabled) to make sure it starts with either +44 or 07, and to make sure the second field is no more than 160 characters.

Pretty please!!!

GJay
03-18-2006, 06:53 PM
if(!(substr($_POST['recipient'],0,3)=='+44'||substr($_POST['recipient'],0,2)=='07')||strlen($_POST['message']>160) {
die("error");
}

should point you in the right direction...

bustamelon
03-18-2006, 07:09 PM
Sorry GJay.... I believe in "give a man a fish.... teach a man to fish..." but I went and did it all, might as well post it.


<?php
$message = array();
$valid = 1;
if ( isset( $_POST['send'] )) {
$pos1 = strpos( $_POST['Recipient'], "+44" );
$pos2 = strpos( $_POST['Recipient'], "07" );

if ( $pos1 !== 0 && $pos2 !== 0 ) {
$valid = 0;
$message[] = "Recipient field must be either 07 or +44.";
}

if ( isset( $_POST['Message'] )) {
if ( strlen( $_POST['Message'] ) > 160 ) {
$valid = 0;
$message[] = "Your message cannot exceeed 160 characters in length.";
}
}

if ( $valid ) {
// success! do something here... redirect maybe?
// header( "Location: /somefile.html" );
}
}
?>

<html>
<head></head>
<body>
<form action="" method="post" >
<?
foreach( $message as $msg ) {
echo "<span style=\"color: #990000; font-weight: bold;\">$msg</span><br/>";
}
?>

<table border="0" bgcolor="#f0f0f0" ID="Table1">
<tr>
<td valign="top">Recipient:</td>
<td>
<input size="13" type="text" name="Recipient" value="+44">
<br>
<font size="1" face="sans-serif"><b><font color="#700000">UK RECIPIENTS ONLY </font></b></font> </td>
</tr>
<tr>
</tr>
<tr>
<td valign="top">Message:<br>(max. 160 chars)</td>
<td>
<textarea rows="3" name="Message" cols="38"></textarea>
</td>
</tr>
</table>
<br>
<input type="submit" name="send" value="Send Message">
<br>
<br>
<b>IMPORTANT:</b> Please press the button <b>only once</b>, and allow some time for the SMS to be processed.
</form>

</body>
</html>

Calilo
03-18-2006, 07:16 PM
since PHP is a server side scripting language, the importat part of code here would be the php script that manages the information sent by the form you posted that would be "send.php" if you post that code we could help you do what you want, it is very easily done using if conditionals like this:



if ((stripos($text, "+44") == "0") OR (stripos($text, "07") == "0")) { // do the rest of the script
} else { // Tell the user his number is wrong.
}



luck
Calilo

KRAK_JOE
03-18-2006, 07:32 PM
since PHP is a server side scripting language, the importat part of code here would be the php script that manages the information sent by the form you posted that would be "send.php" if you post that code we could help you do what you want, it is very easily done using if conditionals like this:



if ((stripos($text, "+44") == "0") OR (stripos($text, "07") == "0")) { // do the rest of the script
} else { // Tell the user his number is wrong.
}



luck
Calilo

Thanks

Heres send.php


<html>
<head>
<META HTTP-EQUIV="CONTENT-Type" CONTENT="text/html;CHARSET=utf-8" >
<title>Insides-Out SNS Service Status</title>
</head>
<body>
<em><font face="sans-serif" size="2"> </em>
<hr size="1" color="#707070">
<div align="center"><em><font size="4"><strong>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="503" height="30" title="title">
<param name="movie" value="text1.swf">
<param name="quality" value="high">
<embed src="text1.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="503" height="30" ></embed>
</object>
</strong></font>
<br>
<br>
</em> </div>
<hr size="1" color="#707070">
<div align="center"><em><br>

<?php

$objSmpp = new COM ( "ActiveXperts.Smpp" );

$objSmpp->Server = "localhost";
$objSmpp->ServerPort = 6000;
$objSmpp->SystemID = "*******";
$objSmpp->SystemPassword = "*******";
$objSmpp->SystemType = "SMPP";

$objSmpp->MessageRecipient = $_POST['Recipient'];
$objSmpp->MessageData = $_POST['Message'];
$objSmpp->MessageType = 0;
$objSmpp->Logfile = "c:\\PhpSmppLog.txt";
$objSmpp->ServerTimeout = 5000;
$objSmpp->SystemMode = 1;

$objSmpp->Connect();

if ( $objSmpp->LastError == 0 )
{
$objSmpp->Send();
}

if ( $objSmpp->LastError == 0 )
{
Echo "Message successfully submitted.";
}
else
{
$ErrorNum = $objSmpp->LastError;
$ErrorDes = $objSmpp->GetErrorDescription ( $ErrorNum );

Echo "Error sending message: #$ErrorNum ($ErrorDes).";
}
?>

<br>
<br>
</em>
</div>
<hr size="1" color="#707070">
</body>
</html>


Also the number doesn't have to be either +44 or 07 but start with those numbers it's a text message script, I'm sure you've worked out - but I don't want ppl to be able to send outisde the UK so I figure if they can't use anything but 07 and +44 to begin that won't happen.

BTW you're all geniusus.

Calilo
03-18-2006, 08:43 PM
Ok, since send.php is the script that makes the connection to the activexpers thing or sending sms and paging, i would leave that script intact, and change the form in order to make it a script, which would then send the right info to send.php.

Bustamelon posted the answer, and a great answer actually, the only thing there to add is what to do with the info, when the uses submits the right number and message. si i would tell you just to add this, instead of where Bustamelon typed


// success! do something here... redirect maybe?
// header( "Location: /somefile.html" );

Replace with this"



include ("path/to/Send.php");
exit;


this way when the user submits the right number and message the script will call send.php and pass the variables to it, then it will exit so wont continue printing the form
So thank Bustamelon

Luck
Calilo

KRAK_JOE
03-18-2006, 08:54 PM
Thanks, but it didn't work, no matter what the message fails to get to send.php - the path is right, and the syntax. So what now???



<?php
$message = array();
$valid = 1;
if ( isset( $_POST['send'] )) {
$pos1 = strpos( $_POST['Recipient'], "+44" );
$pos2 = strpos( $_POST['Recipient'], "07" );

if ( $pos1 !== 0 && $pos2 !== 0 ) {
$valid = 0;
$message[] = "Recipient field must be either 07 or +44.";
}

if ( isset( $_POST['Message'] )) {
if ( strlen( $_POST['Message'] ) > 160 ) {
$valid = 0;
$message[] = "Your message cannot exceeed 160 characters in length.";
}
}

if ( $valid ) {
include ("send.php");
exit;
}
}
?>


<html>
<head>
<META HTTP-EQUIV="CONTENT-Type" CONTENT="text/html;CHARSET=utf-8" >
<title>Insides-Out SMS Service</title>
</head>
<body>
<font face="sans-serif" size="2">
<hr size="1" color="#707070">
<div align="center"><font size="4"><em><strong>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="364" height="30" title="title">
<param name="movie" value="text2.swf">
<param name="quality" value="high">
<embed src="text2.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="364" height="30" ></embed>
</object>
</strong></em> </font>
<br>
<br>
</div>
<hr size="1" color="#707070">
<br>
<form action="send.php" method="post" >
<div align="center">
<table border="0" bgcolor="#f0f0f0" ID="Table1">
<tr>
<td valign="top">Recipient:</td>
<td>
<input size="13" type="text" name="Recipient" value="+44">
<br>
<font size="1" face="sans-serif"><b><font color="#700000">UK RECIPITENTS ONLY </font></b></font> </td>
</tr>
<tr> </tr>
<tr>
<td valign="top">Message:<br>(max. 160 chars)</td>
<td>
<textarea rows="3" name="Message" cols="38"></textarea> </td>
</tr>
</table>
<br>
<input type="submit" value="Send Message">
<br>
<br>
<b><em>IMPORTANT:</em></b><em> Please press the button <b>only once</b>, and allow some time for the SMS to be processed.</em>
</div>
</form>
<br>
<hr size="1" color="#707070">
<div align="center">
</div>
</body>
</html>


This is what I got is that right?

bustamelon
03-18-2006, 09:15 PM
You need to update your form with the one I posted... I gave the submit button a name ("send") and added message reporting at the top. Basically, use my whole post, then replace the "success!" comment with the include() that Calillo posted. Got it?

KRAK_JOE
03-18-2006, 09:22 PM
You guys are the ****.......cheers :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum