TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 468
  • Total: 469
  • @rjen

Feed Back Visual Confirm?

Started by JCphotog, September 14, 2006, 03:31:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

akulion

no idea

sounds complicated though

JCphotog

Another route might be to just keep some of the feilds in the form required.  Which I also don't know how to do.  I love the idea though of a required answer..

JPDeni

I could show you how to put it in a php page, but not a block. I really need to figure out how to work with AJAX.

JCphotog

That would be great, then I could just call it as a pop up from a link in a block.

JPDeni

I'll have something for you in the morning.

JPDeni

I learned something. This will work in a php block, at least on the front page. If visitors use it on other pages, it will send them back to the front page again. I don't know if there's a way around that.

As it stands, it checks for a correct email address format and the correct answer to the question. The check for comments doesn't seem to be working, although I'm not sure why. I left it in there, in case someone is able to tweak it and figure out how to make it work.

global $scripturl;

$question = 'What is 4 + 2 + 1?'; // Defining the question here makes it easier to change.
$right_answer = '7';

$youremail = 'you@yourdomain.com'; // Enter your email address here


$textarea_end = '</' . 'textarea' . '>'; // Solves a little problem with the editor.

if (isset($_POST['submit']))
{
  $message='';
  isset($_POST['email']) ? $email = $_POST['email'] : $email = '';
  if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
    $message = 'You must enter a valid email address<br />';
  isset($_POST['comments']) ? $comments = $_POST['comments'] : $message .= 'You must enter a comment.<br />';
  isset($_POST['answer']) ? $answer = $_POST['answer'] : $answer='';
  if ($answer <> $right_answer)
    $message .= 'You must answer the question correctly.<br />';
  if ($message)
  {
    echo $message;
    echo '<a href="' . $scripturl . '">Try again</a>';
  }
  else
  {
    mail( $youremail, "Feedback Form Results", $comments, "From: $email" );
    echo 'Thank you for your comments';
  }
}

else
{
  // You'll want to make the form prettier
  echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
  echo '<table>';
  echo '<tr><td>Email address:</td></tr><tr><td><input type="text" name="email" />*</td></tr>';
  echo '<tr><td>Comments:</td></tr><tr><td><textarea name="comments">'. $textarea_end . '*</td></tr>';
  // add whatever other fields you want for your form

  echo '<tr><td>' . $question . '<br>(This is just to prove you<br>are a human and not a computer.)</td></tr><tr>
        <td><input type="text" name="answer" />*</td></tr>';
  echo '<tr><td align="center"><input type="submit" name="submit" value="Send"></td></tr>';
  echo '<tr><td>Fields marked with a * are required.</td></tr></table>';
  echo '</form>';
}

akulion

hey i like your mathematics approach

cant u use like an actual addition function instead of a fixed one?

so that the script randomly generates numbers to add and checks them itself

if u get my meaning

JPDeni

The trouble with random is that, once the page is printed, it would forget what the random number is.

Hmmmm.

You could create a random function and both display it and add it to a hidden field. Then, when the form is submitted, the program would evaluate the function and come up with the correct answer to compare to the one in the field.

Or you could create a random function when the page is created and then save the correct answer to a .txt file or a database record. (Seems like a lot of work to go to.)

Or you could create a whole database table of questions and answers, to be pulled in at random when the page is created. In the form would be a hidden field with the ID number of the current question and answer and the script would look it up when the form is submitted.

You could even have a whole bunch of images. Create a database table that has three fields -- the ID, the name of the image file and the correct answer. Pick a row at random when the page is created and save the ID to a hidden field. Then look up the record when the file is submitted.

There's lots and lots of different options. :) A lot depends on how much work you want to do.

akulion

 :o ok lets stick to this basic method lol


This website is proudly hosted on Crocweb Cloud Website Hosting.