Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
validate form entries?
Old 03-22-2005, 09:44 PM validate form entries?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
is there a way i can validate form entris ie that the name box is filled and so on?

the other thing is that i want a if statement so if some one fills out a form to join my clan and they are too young ie 5-13 i want them redirected to a page stating sorry then to google.com

current code
PHP Code:
<?php
$age 
$_POST['age'];
if(
$age == '10-15')) {
echo 
'sorry you are too young';
} else {
include 
'sendmail.php';
)
?>
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 03-22-2005 at 09:57 PM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Old 03-23-2005, 06:40 AM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
i also am trying to set cookies so they cannot revist the site to retry signing up.
this is my javascript code for cookies
Read Cookie
Code:
<script>
function readCookie(age)
{
  var cookieValue = "too young";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
</script>
Write Cookie
Code:
<script = javascript>
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(age, too young, 100000)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
</script>
i need to use a php if function to see if the cookie has been set with the value "too young" to redirect to a sorry page
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-23-2005, 11:29 AM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
Just perform a check like the one below...

PHP Code:
if (!empty($_COOKIE['too_young'])) {
    
// too young
} else {
    
// let 'em pass

By the way, I suggest not using spaces in variable names as it may break your script and/or make it more difficult to check their values
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-23-2005, 03:08 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
OKay the other thing is that i need it to validate from a feild in a form and if age equals below 13 that saves a cookie saying too young.

then after the form has been sent to me to save another cookie to prevent people from signing up twice

current final.php coade
PHP Code:
<?php
$age 
$_POST['age'];
if(
$age == '10-15')) {
?>
<script = javascript>
// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.
function writeCookie(age, too young, 100000)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}
</script>
<?php
echo 'sorry you are too young';
} else {
include 
'sendmail.php';
)
?>
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-25-2005, 08:10 AM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
If you are going to use php, you might as well use it to set the cookie.

As for checking cookie and/or posted age...

PHP Code:
<?

if ($_POST['age'] == "10-15" || $_COOKIE['age'] == "too young") {
    
setcookie("age""too young"time()+60*60*24*30);
    echo 
"Sorry, but you are too young.";
} else {
    include(
"sendmail.php");
}

?>
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-26-2005, 06:03 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
so how would i use php to check the cookies
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-27-2005, 11:31 AM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
okay this relates to setting the cookies...
final.php
PHP Code:
<?php
include 'http;//jonspcrepair.com/inc/header.php';
if (
$_POST['age'] == "<13" || $_COOKIE['age'] == "too_young") {
    
setcookie("age""too_young"time()+60*60*24*30);
    include 
'sorry.php?p=young';
} else (
$_POST['submit'] == "true" || $_COOKIE['join'] == "completed") {
    
setcookie("join""completed"time()+60*60*24*30);
    include 
'sendmail.php';
}
?>
error
Code:
Parse error: parse error, unexpected '{' in /var/www/html/test/final.php on line 6
joinamw.php
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Join The AMW Clan</title>
</head>
<body>
<?php
include 'http://jonspcrepair.com/inc/header.php';

if (!empty(
$_COOKIE['too_young'])) {
    include 
'sorry.php?p=young';
} elseif (!empty(
$_COOKIE['completed'])) {
    include 
'sorry.php?p=completed';
} else {
    include 
'form.php';
}
?>
</body>
</html>
Form.php
PHP Code:
<form action="final.php" method="post" name="joinamw" id="joinamw">
  <
p>Please Fill out the following completly</p>
  <
p>* detnotes a required feild</p>
  <
table width="326" height="211" border="0">
    <
tr>
      <
td width="120"><div align="right">First Name </div></td>
      <
td width="196"><input name="fname" type="text" id="fname"></td>
    </
tr>
    <
tr>
      <
td><p align="right">Last Name</p>
      </
td>
      <
td><input name="lname" type="text" id="lname"></td>
    </
tr>
    <
tr>
      <
td><div align="right">Clan Name </div></td>
      <
td><input name="clanname" type="text" id="clanname"></td>
    </
tr>
    <
tr>
      <
td><div align="right">Town</div></td>
      <
td><input name="town" type="text" id="town"></td>
    </
tr>
    <
tr>
      <
td><div align="right">Connection Speed </div></td>
      <
td><select name="connect" id="connect">
        <
option value="56k">56k Dialup</option>
        <
option value="ISDN Line">ISDN</option>
        <
option value="DSL">DSL</option>
        <
option value="1 Mb Cable">Cable 1 Meg</option>
        <
option value="2 MB + Cable">Cable 2 Meg+</option>
        <
option value="No Clue">Dont Know</option>
      </
select></td>
    </
tr>
    <
tr>
      <
td><div align="right">Ability</div></td>
      <
td><select name="skill" id="skill">
        <
option value="super n00b">I Know nothing</option>
        <
option value="n00b">I can shoot</option>
        <
option value="average">i can kill some people kill 1-20</option>
        <
option value="above average">kills 20-50</option>
        <
option value="Man i need you">50+</option>
      </
select></td>
    </
tr>
    <
tr>
      <
td><div align="right">What Games?</div></td>
      <
td>      <p>
        <
input name="cs" type="checkbox" id="cs" value="Yes">
    
Counter-Strike</p>
        <
p>      <input name="bfv" type="checkbox" id="bfv" value="Yes">
      
Battlefield Veitnam      </p>
        <
p>
    <
input name="ut2k4" type="checkbox" id="ut2k4" value="Yes">
    
Unreal Tournament 2004</p></td>
    </
tr>
    <
tr>
      <
td><div align="right">Your Age </div></td>
      <
td><select name="age" id="age">
        <
option value="&lt;13" selected>Under 13</option>
        <
option value="16-18">16-18</option>
        <
option value="19-25">19-25</option>
        <
option value="25+">25+</option>
      </
select></td>
    </
tr>
    <
tr>
      <
td>&nbsp;</td>
      <
td><input type="submit" name="Submit" value="Continue"></td>
    </
tr>
  </
table>
  <
p>&nbsp;</p>
  <
p>&nbsp;</p>
  <
p>&nbsp;    </p>
  <
p>&nbsp;</p>
  <
p>&nbsp;</p>
  <
p>&nbsp;   </p>
</
form
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-28-2005, 10:44 AM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
1st things first... your error

PHP Code:
} else ($_POST['submit'
should be

PHP Code:
} else if ($_POST['submit'
besides that, your code looks okay at first glance. are you still having problems?
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-28-2005, 02:53 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
yea i got it to work after about 6 hours of screwing around with it. it now writes cookies reads them and sends me a email if all okay

and i removed the sendmail.php file as it would not get the $_POST items so i copied and rewrote the code in the final.php to send the email, check requirements and send me a email
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 03-28-2005 at 02:56 PM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-28-2005, 05:39 PM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
The included script should have been able to access the $_POST variables. Regardless, good for you since you got it working
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Old 03-28-2005, 07:41 PM
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
yea after about 6 hours of debuggin it. is there a free program that will go through it and tell me if i syntax errors and errors that relate to php? as it will save me hours of debugging in the future
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-28-2005, 10:43 PM
simptech's Avatar
Skilled Talker

Posts: 81
Location: Cape Coral, Florida, United States
Trades: 0
To be quite honest I have never checked. Only reason being, PHP normally gives you a pretty good idea of where the problem is. Otherwise I would not have been able to make good suggestions from your error notices
__________________

Please login or register to view this content. Registration is FREE

FREE PHP scripts for your website!
simptech is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to validate form entries?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33475 seconds with 12 queries