PDA

View Full Version : Help Please! PHP Petition..


gregfindley.com
12-11-2006, 11:21 AM
Hi everyone,

Hoping someone can help me out pretty quick with a few niggling issues I have on a website...

(The site is www.sharkyandgeorge.com, I have integrated phpPETITION scripts into the site)

-The e-mail verification is working, sending out the e-mail, but their signature appears in the petition whether its confirmed or not, how can I change this?

-How to setup the message field so it has a max. no of characters say 150?

-How to change the petition results so it displays 14 or 16 on the first page of results instead of 10?

Thanks for any replies!!
Greg

davidj
12-11-2006, 11:53 AM
what is this PHP petition script

Im asuming that this is a third party class

If so i need to see the code

gregfindley.com
12-11-2006, 11:57 AM
Hi DJ,

Here is the signature.php which is included in the sign the petition page;

<?php
require_once('Connections/petitionscript.php');

mysql_select_db($database_petitionscript, $petitionscript);
$query_rs = "SELECT count(*) as RecordCount FROM signature";
$rs = mysql_query($query_rs, $petitionscript) or die(mysql_error() . " <a href='setup.php'>Click Here</a> to Setup the Table");
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);

mysql_free_result($rs);
?>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<form action="received.php" method="post" name="form1" onSubmit="MM_validateForm('FirstName','','R','LastName','',' R','Email','','RisEmail');return document.MM_returnValue">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="FirstName" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="Email" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><p>Message:</p>
<p>(max. 150 characters)</p></td>
<td><textarea name="Message" rows=5 cols="30"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input name="submit" type="submit" value="SIGN PETITION"></td>
</tr>
</table>
<input type="hidden" name="IP" value="<?php Echo $_SERVER['REMOTE_ADDR'] ?>" size="32">
<input type="hidden" name="Date" value="<?php Echo date('Y-m-d H:i:s') ?>" size="32">
<input type="hidden" name="MM_insert" value="form1">
</form>

gregfindley.com
12-11-2006, 11:58 AM
Is there a way to set the 'Message' Field to a max of 150 characters firstly?
Thanks! Greg

davidj
12-11-2006, 01:50 PM
<script type="text/JavaScript">

function countText(){
var c0 = 150;
f3 = document.getElementById("Message");
c1 = document.getElementById("counter");
c1.innerHTML = c0 - f3.value.length;
if(f3.value.length > 149){
f3.disabled = true;
}
}
function formValid() { //v4.0
f1 = document.getElementById("FirstName");
f2 = document.getElementById("Email");
f3 = document.getElementById("Message");
w1 = document.getElementById("warning");
if(f1 && f2){

if(f3.value.length < 150){

document.forms[0].submit();

}

}else{

w1.innerHTML = "You have an empty field";

}
}
//-->
</script>
<body>
<form action="received.php" method="post" name="form1" onSubmit="formValid()">
<table align="center">
<tr valign="baseline">
<td width="133" align="right" nowrap>Name:</td>
<td width="285"><input type="text" name="FirstName" value="" size="32" id="FirstName"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email:</td>
<td><input type="text" name="Email" value="" size="32" id="Email"></td>
</tr>
<tr valign="baseline">
<td height="114" align="right" valign="top" nowrap><p>Message:</p>
<p>(max. 150 characters)</p></td>
<td><p>
<textarea name="Message" rows=5 cols="30" id="Message" onKeyDown="countText()"></textarea>
<br>

Remaining Chars <div id="counter"></div>

</p>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input name="submit" type="submit" value="SIGN PETITION"></td>
</tr>
<tr valign="baseline">
<td height="44" colspan="2" align="center" valign="middle" nowrap>

<div id="warning"></div>

</td>
</tr>
</table>
<input type="hidden" name="IP" value="<?php Echo $_SERVER['REMOTE_ADDR'] ?>" size="32">
<input type="hidden" name="Date" value="<?php Echo date('Y-m-d H:i:s') ?>" size="32">
<input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>

gregfindley.com
12-11-2006, 02:18 PM
Thanks for that DJ!

The only thing is it locks up the text box if you go over 100 characters (reduced it from 150 to 100) and then you can't edit it without refreshing the page. Is there anyway to make it so you can still edit, but not submit if that makes sense?

Thanks for your help!
Really appreciated :)

Greg

davidj
12-11-2006, 02:49 PM
replace

f3.disabled = true;

with


f3.value = f3.value.substring(1, c0);

gregfindley.com
12-11-2006, 02:57 PM
Thats great thanks DJ!! :D

Can you help me setup the petition results page so it displays 14 results instead of 10 per page?

<?php require_once('Connections/petitionscript.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rsResult = 10;
$pageNum_rsResult = 0;
if (isset($_GET['pageNum_rsResult'])) {
$pageNum_rsResult = $_GET['pageNum_rsResult'];
}
$startRow_rsResult = $pageNum_rsResult * $maxRows_rsResult;

mysql_select_db($database_petitionscript, $petitionscript);
$query_rsResult = "SELECT * FROM signature";
$query_limit_rsResult = sprintf("%s LIMIT %d, %d", $query_rsResult, $startRow_rsResult, $maxRows_rsResult);
$rsResult = mysql_query($query_limit_rsResult, $petitionscript) or die(mysql_error());
$row_rsResult = mysql_fetch_assoc($rsResult);

if (isset($_GET['totalRows_rsResult'])) {
$totalRows_rsResult = $_GET['totalRows_rsResult'];
} else {
$all_rsResult = mysql_query($query_rsResult);
$totalRows_rsResult = mysql_num_rows($all_rsResult);
}
$totalPages_rsResult = ceil($totalRows_rsResult/$maxRows_rsResult)-1;

$queryString_rsResult = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsResult") == false &&
stristr($param, "totalRows_rsResult") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rsResult = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rsResult = sprintf("&totalRows_rsResult=%d%s", $totalRows_rsResult, $queryString_rsResult);
?><html>




<title>SharkyandGeorge.com - Petition for the crimebusters of the sea</title>
<meta http-equiv="content-type" content=
"text/html; charset=utf-8" />

<script language="javascript">
//--------------- LOCALIZEABLE GLOBALS ---------------
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
//--------------- END LOCALIZEABLE ---------------
</script>

<meta name="description" content="Sharky and George.com the online petition for the crimebusters of the sea" />
<meta name="keywords" content="sharky and george, sharky, george, sharky n george, sharkey and george, sharky and georges, crimebusters of the sea, crimebusters, sharkyandgeorge" />
<meta name="author" content="SharkyandGeorge.com" />
<meta name="copyright" content="SharkyandGeorge.com" />
<meta name="company" content="SharkyandGeorge.com" />
<meta name="revisit-after" content="3 days" />
<link rel="shortcut icon" href="/favicon.ico" type=
"image/x-icon" />
<link rel="stylesheet" href="sitestyle.css" type="text/css" media=
"screen" />
<link rel="stylesheet" href="thickbox.css" type="text/css" media=
"screen" />
<style type="text/css" media="all"></style>
<style type="text/css" media="all"></style>
<script language="JavaScript" type="text/JavaScript">
<!--



function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<script type="text/javascript">
function bookmark(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
</script>
</head>
<body>
<center>

<div id="header">
</div>


<div id="content">



<div id="horizontal">
<div id="horizontaltext"> <a href="http://www.sharkyandgeorge.com/index.html">Welcome</a>
| <a href="http://www.sharkyandgeorge.com/petition/index.php">Sign the
Petition</a> | <a href="http://www.sharkyandgeorge.com/petition/results.php">View
the Petition</a> | <a href="http://www.sharkyandgeorge.com/gallery.html">Gallery
</a>| <a href="javascript:bookmark('SharkyandGeorge.com - Petition for the crimebusters of the sea', 'http://www.sharkyandgeorge.com')" ('bookmark','','images/bookmark_on.gif',1)">Bookmark us</a>
| <a href="http://www.sharkyandgeorge.com/banners.html">Get a Banner</a>
| <a href="http://www.sharkyandgeorge.com/links.html">Links</a></div>
</div>

<script type="text/javascript"><!--
google_ad_client = "pub-3181967717440575";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "0066CC";
google_color_text = "000000";
google_color_url = "3D81EE";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>




<div id="maincontent">



<table width="675" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><p><font color="#0066CC"><img src="phpPetitionTemplate/mm_spacer.gif" alt="" width="1" height="1" border="0">&nbsp;
<br>
<b>
<?php echo "So far we have " . $totalRows_rsResult . " signatures" ?>
</b> </font></p>
<table width="675" border="0" cellpadding="5">
<tr align="center" valign="middle" bgcolor="#3165CE">
<?php
if ((isset($_GET['ADMIN'])) && ($_GET['ADMIN'] != ""))
echo '<td><span class="style1">Delete</span></td>';
?>
<td width="176"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Name</span></font></td>
<td width="359"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Message</span></font></td>
<td width="102"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1">Date
</span></font><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><span class="style1"><font color="#FFFFFF"><br>
</font> </span></font></td>
</tr>
<?php //$row = 0+$startRow_rsResult ?>
<?php do { ?>
<?php //$row == $row++ ?>
<tr>
<?php
if ((isset($_GET['ADMIN'])) && ($_GET['ADMIN'] = "On"))
echo '<td><a href=Delete2.php?ID='.$row_rsResult['ID'].'>Delete<a></td>';
?>
<td><font color="#000000" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_rsResult['FirstName']; ?></font></td>
<td><font color="#000000" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_rsResult['Message']; ?></font></td>
<td align="center"><font color="#000000" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_rsResult['TSDate']; ?> </font></td>
</tr>
<?php } while ($row_rsResult = mysql_fetch_assoc($rsResult)); ?>
</table>
<p>&nbsp;</p>
<table border="0" width="30%" align="center">
<tr>
<td width="23%" align="center"><font color="#0000FF">
<?php if ($pageNum_rsResult > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsResult=%d%s", $currentPage, 0, $queryString_rsResult); ?>"><img src="Admin/Images/Begining.gif" alt="Goto First Signature" width="21" height="21" border=0></a>
<?php } // Show if not first page ?>
</font></td>
<td width="31%" align="center"><font color="#0000FF">
<?php if ($pageNum_rsResult > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsResult=%d%s", $currentPage, max(0, $pageNum_rsResult - 1), $queryString_rsResult); ?>"><img src="Admin/Images/backward.gif" alt="Previous Page" width="20" height="20" border=0></a>
<?php } // Show if not first page ?>
</font></td>
<td width="23%" align="center"><font color="#0000FF">
<?php if ($pageNum_rsResult < $totalPages_rsResult) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsResult=%d%s", $currentPage, min($totalPages_rsResult, $pageNum_rsResult + 1), $queryString_rsResult); ?>"><img src="Admin/Images/Forward.gif" alt="Next Page" width="21" height="20" border=0></a>
<?php } // Show if not last page ?>
</font></td>
<td width="23%" align="center"><font color="#0000FF">
<?php if ($pageNum_rsResult < $totalPages_rsResult) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsResult=%d%s", $currentPage, $totalPages_rsResult, $queryString_rsResult); ?>"><img src="Admin/Images/End.gif" alt="Goto Last Signature" width="22" height="21" border=0></a>
<?php } // Show if not last page ?>
</font></td>
</tr>
</table> </td>
</tr>
</table>




</body>
</html>
<?php
mysql_free_result($rsResult);
?>

</div>



</div>


<div id="footer"></div>


</center>
</body>
</html>

gregfindley.com
12-11-2006, 02:59 PM
I tried changing this "$maxRows_rsResult = 10;" to 14 but nothing changed still displayed 10?

Thanks,
Greg

davidj
12-11-2006, 02:59 PM
replace
$maxRows_rsResult = 10;
with
$maxRows_rsResult = 14;

:mrgreen:

davidj
12-11-2006, 03:00 PM
I tried changing this "$maxRows_rsResult = 10;" to 14 but nothing changed still displayed 10?

clear your cache

gregfindley.com
12-11-2006, 03:32 PM
Great thanks DJ :)

One last thing.... sorry! know im being a pain today...
Do you know how I can change the date format from YYYY-MM-DD to DD-MM-YYYY?

I have tried using mySQL management to change the format but it doesnt seem to work? not sure what I'm doing wrong?

Thanks!!
Greg

davidj
12-11-2006, 04:00 PM
its the bigest bind i have when working with dates and is common

here is a function i have used for some other apps i wrote. Its nowt bling but does the trick

// display date correctly in form fields dd/mm/yyyy
function displaydate($date){
if (strlen($date)==10){
$year = substr($date,0,4);

if (is_numeric($year)){
$year = substr($date,0,4);
$month = substr($date,5,2);
$day = substr($date,8,2);

$displaydate = $day.'-'.$month.'-'.$year;
return $displaydate;

}else{

return $date;

}
}
}


to use just do this..

where you have your date var echo $date;

do

echo displaydate($date)

where $date is the var you want to convert

also i would drop that function into an include() and call it in every page that needs it

gregfindley.com
12-11-2006, 04:08 PM
Hi DJ,

I have this code:

<td align="center"><font color="#000000" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_rsResult['TSDate']; ?> </font></td>

not: echo $date;

Any ideas on how I should edit it?
Thanks,
Greg

davidj
12-11-2006, 04:45 PM
<?php echo displaydate($row_rsResult['TSDate']); ?>

gregfindley.com
12-11-2006, 06:10 PM
Cool working now thanks!

Thanks for all your help :D
Greg