Where can I get a specific Question and Answer script?
Ive tried one other java script, but it allows people to click one of four answers.
I need a script that makes the user have to type in the answer, then hit submit. And takes the user to a correct.php page so they can get the prize.. I dont want them to pick an answer, otherwise its too easy.
I say this because Im giving away my dropshipping list now, and in order to get that list, they have to visit a page and get the answer I asked. Which is,"what is the coupon code".
Just so I can at least get them to the affiliate URL im providing.
Anyone know of sucha script lying around?
Thanks heaps guys. Honestly, ive tried looking...you know I only come here as a last resort .
decibel.places posted this at 15:38 — 10th January 2009.
He has: 1,494 posts
Joined: Jun 2008
I would hope you would come here for the comraderie...
On form submission, you need to check the coupon code input...
So you need a validation script, either in PHP or JS...
usually when I am looking for code, I try Hot Scripts or SourceForge - or Google Code Search
cmoyer posted this at 02:57 — 11th January 2009.
He has: 131 posts
Joined: Jun 2008
You would need to validate the form input as decibel.places said. You could do this easily with php using this code.
<?php
$coupon_code = $_POST[ 'user_guess'];
$real_coupon_code = "ENTER YOUR COUPON CODE HERE";
if($coupon_code)
{
if($coupon_code === $real_coupon_code)
{
echo 'congrats! you have entered the code correctly!';
}
else
{
echo 'Wrong coupon, try again or be gone with ya!';
?>
<form id="user_guess" action="couponcode.php" method="post">
<input type="text" name="user_guess" />
<input type="submit" value="Guess Code" />
</form>
<?php
}
}
else
{
?>
<form id="user_guess" action="couponcode.php" method="post">
<input type="text" name="user_guess" />
<input type="submit" value="Guess Code" />
</form>
<?php
}
?>
Now it's time to break this down!
part 1
$coupon_code = $_POST[ 'user_guess'];
This gets the users guess at the coupon
part 2
$real_coupon_code = "ENTER YOUR COUPON CODE HERE";
This sets the acceptable coupon code
replace ENTER YOUR COUPON CODE HERE with your coupon, there can be no spaces!
part 3
if($coupon_code === $real_coupon_code)
{
echo 'congrats! you have entered the code correctly!';
}
else
{
echo 'Wrong coupon, try again or be gone with ya!';
?>
<form id="user_guess" action="couponcode.php" method="post">
<input type="text" name="user_guess" />
<input type="submit" value="Guess Code" />
</form>
<?php
}
This checks if the users code is correct, if not they are prompted to try again or leave.
part 4
if($coupon_code)
{
// checking code
}
else
{
?>
<form id="user_guess" action="couponcode.php" method="post">
<input type="text" name="user_guess" />
<input type="submit" value="Guess Code" />
</form>
<?php
}
?>
This checks if the user has submitted a code if not they are shown the main form page.
That's all there is to it!
Also, I would think about coming here first, we don't bite!
DSSR posted this at 10:26 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Nah, I don't want to bother you guys with my silly problems till I need to - I'm sure there are pleanty other people with bigger more important problems than mine.
Anyways, again, tx for your hospitality decibel.
And cmoyer, the code works perfectly, but I need it to go to a page which allows them to enter in their email so they can grab my dropshipping list.
So when it echos "Congratz" can it send them to a seperate page that says;
"Congratz, please enter your email to request our dropshipping list"
I have the email form all setup, I just need the php page to go to it instead of just echoing text to the same page.
Again, I don't think you undersand the importance of this place. Each of you should have a donation tab, one for each user.
You guys are the best.
Thanks again, I'm wrapped
DSSR posted this at 11:41 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Okay, I figured out how to point to another page, but..
I made the first one
<form id="user_guess" action="correct.php" method="post">
which points to my corrct page. But, even if the code is entered in wrong, it still points to correct.php.
So I made the lower one point to couponcode.php, but no matter what the bottom one is, the top one overrides it and still sends them to the correct.php page.
I tried visa versa too.
Still working on it...Maybe I have to make a wrong.php page to point to it instead of back to couponcode.php..And Ill add the same couponcode php stuff to that wrong page so they can try again?
cmoyer posted this at 19:40 — 11th January 2009.
He has: 131 posts
Joined: Jun 2008
When the code was written there only was one php page called couponcode.php and all the requests could in essence be processed through this one page(couponcode.php).
To add another field for the passed section you can add the form there, you can do it somewhat like this
{
echo 'congrats! you have entered the code correctly!';
?>
<form id="user_email" action="couponcode.php" method="post">
<input type="hidden" value="<?php echo $coupon_code; ?>" name="user_code" />
Your Name:<input type="text" name="user_name" />
Your Email:<input type="text" name="user_email" />
<input type="submit" value="Submit" />
<?php
}
See the attached file for the rest of the php.
I added a simple check if the user is human, not very good but will work a little. This form needs email validation added to it, not sure how to do that, but will look into it.
Also, do you want to send an email? or put information into a database? or write it to an xml file? You're going to want to store the user's info somewhere. The attached file has a .html extension so you will need to change the .html at the end to .php
DSSR posted this at 20:19 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Oh thanks for the reply mate.
All I need is the script to point to my correct.php page when the code entered is the right one.
If its wrong, they can go back to the same couponcode.php page and try again.
Once they have the right code, my correct.php page already has a form for them to enter their email address, and my email has been set to autorespond to their request.
I also have a script which blocks certain IPs which links to a spam site I use for my forum.
That "Are you human" thing is a nice touch ..
(are you saying I can put my email form in the couponcode.php page and it wont display until they enter the correct coupon code?)
Again, thanks for all your help mate, I appreciate your time greatly!.
cmoyer posted this at 20:44 — 11th January 2009.
He has: 131 posts
Joined: Jun 2008
You can integrate the email forms into the couponcode.php or you can do an html redirect like this
<meta http-equiv="REFRESH" content="15;url=correct.php">
This will redirect to correct.php after 15 seconds
Just make sure that this line comes before the text so it would look like this (I added a link just in case the user's browser doesn't support redirects)
if($coupon_code === $real_coupon_code && $are_human === "6")
{
echo '<meta http-equiv="REFRESH" content="15;url=correct.php">';
echo 'congrats! you have entered the code correctly!<br />';
echo '<a href="correct.php">Click here if you aren't redirected</a>';
}
A security bug that I see for using a redirect is that anyone who knows the correct address is correct.php could go there without entering the coupon.
Also, I forgot to mention in the above that the code I had in the file was super
DSSR posted this at 20:53 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Ill intergrate it if thats easier. Where abouts in the couponcode.php file would I put my email form code?
This is the code.
<!--email form start-->
<div class="important">
<form method="post" action="requestform.php">
<fieldset style="border: 0px none;">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi; ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi; ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti; ?>" />
Your Email:
<br />
<input type="text" name="visitormail" size="35" />
<br />
Attention:
<br />
<select name="attn" size="1"><option value=" Drop Shipping List Contact Form ">Admin-Level1</option></select>
<br />
<br />
<input type="submit" value="Request Drop Shippers" />
<br />
<br />
</fieldset>
</form>
</div>
<!--/email form end-->
Thanks again mate.
DSSR posted this at 21:12 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
AHhh I got it I got it ....I just used the redirect
Mate, Iappreciate all your help...
Heres a working sample.
http://www.only-the-truth.com/couponcode.php
edit: sorry, the code (answer) is 75off
DSSR posted this at 21:15 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Oh bugga, the code doesnt validate.
There are 3 errors
1.)
document type does not allow element "input" here; missing one of "ins", "del", "h1", "h2", "h3", "h4", "h5", "h6", "p", "div", "address", "fieldset" start-tag.
<input type="text" name="user_guess" />
2.)
end tag for "form" which is not finished.
</form>
3 is same as 1.
Any ideas?
decibel.places posted this at 21:35 — 11th January 2009.
He has: 1,494 posts
Joined: Jun 2008
maybe
<form ... >
tag was not opened?DSSR posted this at 21:47 — 11th January 2009.
They have: 166 posts
Joined: Mar 2006
Its the code that cmoyer posted at first. It seems there is a Form tag open, then its closed.
http://www.only-the-truth.com/couponcode.php
Click the XHTML validation icon, then click show source when you try validate it. It seems to be okay?
decibel.places posted this at 23:46 — 11th January 2009.
He has: 1,494 posts
Joined: Jun 2008
beats me - something is screwy
try hacking out sections and validating to narrow down the culprit
or you could begin by validating the form code to make sure it validates, then adding pieces until it breaks...
DSSR posted this at 00:00 — 12th January 2009.
They have: 166 posts
Joined: Mar 2006
nah its okay, Ill leave it, better working than broken ..Validate can eat me ...At least my index is validated ..
lol..thanks champ have a great day!
cmoyer posted this at 00:55 — 12th January 2009.
He has: 131 posts
Joined: Jun 2008
Sorry, didn't think about the validation, it is xhtml. to validate it use this code in the form spot in the php.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Coupon Code Enter</title>
</head>
<body>
<form id="user_guess" action="couponcode.php" method="post"><p>
Enter coupon code here<input type="text" name="user_guess" /><br />
<input type="submit" value="Guess Code" />
</p></form>
</body>
</html>
Hope this clears things up a bit.
decibel.places posted this at 01:10 — 12th January 2009.
He has: 1,494 posts
Joined: Jun 2008
aha!
so a form requires a container such as a p element - what about div? or span?
greg posted this at 01:49 — 12th January 2009.
He has: 1,581 posts
Joined: Nov 2005
In XHTML strict,
<input>
is not a valid child element of<form>
.An input tag has to be wrapped with a block-level element that allows inline elements to be in them, such as
<p>
or<fieldset>
.Make sure you don't have a default class in your CSS for
<p>
or<fieldset>
or whatever you choose to use.such as
p{
margin: 20px;
}
etc
As this would alter your form layout/appearance.
You can of course set yourself a specific class or id for forms...
p .form_inputs{
margins, padding, whatever
}
DSSR posted this at 02:30 — 12th January 2009.
They have: 166 posts
Joined: Mar 2006
ahhh, I did that but in the wrong palce.. I checked some other form I had which validated and I knew it had to do with a container, but where to place it had me, because it doesnt work at teh start of the whole form.
Thanks champ,I really appreciate this ..
Have a good one!
DSSR posted this at 05:30 — 12th January 2009.
They have: 166 posts
Joined: Mar 2006
Greg, what do I do for the xhtml tag for p .form_inputs
is it or something like that?
Because I do have a class p already.
Thanks mate.
greg posted this at 17:32 — 13th January 2009.
He has: 1,581 posts
Joined: Nov 2005
If you use just
<p>
in your forms for the inputs, then whatever you have set in your CSS forp
will affect the layout of the forms with whatever attributes you have in your CSS forp
.EG a 20px top margin etc.
If you use the default p, such as
<p><input type="text"></p>
and it looks fine then for the purpose of you getting it validated it will be fine. If you change the CSS for
p
it will of course alter your form layout accordingly, which is why I suggested making a specific class for the form inputs.But to be honest, if you are going to make a specific class for the form inputs then you are getting into styling your forms with layout, colours etc, which is a good idea, but then you would be better off putting the form in a more appropriate layout such as using lists.
This is where you are getting into managing the styles and layouts for your entire site, as the default
<p>
has CSS for specific areas of your site, other areas you might want a paragraph to have more space below or above, or be indented or whatever. Such as using a specific<p>
with CSS styling for form inputs. If later you want to alter the form layout, it's the form paragraphs CSS you change, and the default paragraphs that use<p>
around your site will remain unchanged.Without this approach, I.E. just using
<p>
everywhere on your site with the same CSS, means you cannot change individual areas or aspects of your site.So, again, for validation and nothing else just use
<p>
, or perhaps use<fieldset>
if you don't alreadyHave a read of this if you want to start adding style to your forms, and of course if you get stuck with it just ask
http://www.alistapart.com/articles/prettyaccessibleforms
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.