1
Daigoro
Quick petition (Survey hack)
  • 2006/10/26 14:43

  • Daigoro

  • Quite a regular

  • Posts: 223

  • Since: 2003/7/3 2


A short while ago, I suddenly found myself needing a way to make a petition, that would verify the persons participating.
I needed it pretty fast, too, so I had to locate something that either did what I needed or could be quickly modified.

The petition I did just ended, and I have removed the code and module from the active site. While doing so, I thought I'd share what I did.

Looking around in the repository and on the web, I found nothing that really fitted my needs.

However Mithrandir's Survey module looked promising to be modified to fit my needs.
It allowed me to make a survey, add the questions I needed answering, export collected data and it even did IP, Cookie or Email verification on the participants.
What it really missed, was some kind of feedback, which I decided would be easiest to add as XOOPS Custom Blocks.

So I made a survey, asking for Name, Address and Email (in that order) - all had to be answered. The address was a text-field, the others only text-strings.

Then I made two Custom Blocks (type = PHP). One to show the current count of participants - and one to display the names of the last 10 people to sign up.

The counter required the following code:
global $xoopsDB;
 
$xoopsDB =& Database::getInstance();
 
$res $xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix("survey_reply")." WHERE formid=1");
 list(
$count) = $xoopsDB->fetchRow($res);
 echo 
'
  <center>
  <b>Currently</b><br />
  <font style="font-size:20px;font-weight:bold;color:#B70000;">'
$count .'</font><br />
  <b>answers.</b>
  </center>
 '
;

Inside the above code, I also had a "Click here to participate", that would link directly to the active survey.


To list the last 10 names, I used the following code:
global $xoopsDB;
 
$xoopsDB =& Database::getInstance();
 
$res $xoopsDB->query("SELECT answer FROM ".$xoopsDB->prefix("survey_answer")." WHERE qid = 1 ORDER BY replyid DESC LIMIT 10");
 while ( list(
$answer) = $xoopsDB->fetchRow($res) ) {
 echo 
ucwords(strtolower($answer))."<br />";
};


I also had to make a few hacks to the module:

This code in survey/form.php had to be fixed
$form->assign(&$xoopsTpl);


so it was changed into:
$form->assign($xoopsTpl);


and finally, I didn't like the way a survey ended, so I did some modifications to survey/submit.php.
This code:
echo $myts->displayTarea($form->f_submit_message1);


was changed into:
redirect_header(XOOPS_URL,5,$myts->displayTarea($form->f_submit_message1));



All of this has worked perfectly, and has been working for about two months now. (But looking at the code to list the names while writing this text, I think it may fail if more then one survey is active.)

I hope you can make use of the above to make your own petitions.
Best regards,
Daigoro

Login

Who's Online

172 user(s) are online (118 user(s) are browsing Support Forums)


Members: 0


Guests: 172


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits