Jump to content

TOA

Members
  • Posts

    623
  • Joined

  • Last visited

Everything posted by TOA

  1. Hey guys, got a problem and I don't work much with javascript, so I'm stuck. I found a couple scripts online and merged them into this script for testing <!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> <script> function checkAge(input) { var today = new Date(); var d = document.getElementById(input).value; if (d == "") { showMessage('empty',input); return false; } if (!checkFormat(input)) { // check valid format return false; } d = d.split("-"); var byr = parseInt(d[0]); var nowyear = today.getFullYear(); if (byr >= nowyear || byr < 1900) { // check valid year showMessage('impossible',input); return false; } var bmth = parseInt(d[1],10)-1; // radix 10! if (bmth <0 || bmth >11) { // check valid month 0-11 showMessage('impossible',input); return false; } var bdy = parseInt(d[2],10); // radix 10! var dim = daysInMonth(bmth+1,byr); if (bdy <1 || bdy > dim) { // check valid date according to month showMessage('impossible',input); return false; } var age = nowyear - byr; var nowmonth = today.getMonth(); var nowday = today.getDate(); var age_month = nowmonth - bmth; var age_day = nowday - bdy; if (age < 18 ) { showMessage('child',input); return false; } else if (age == 18 && age_month <= 0 && age_day <0) { showMessage('child',input); return false; } } function checkFormat(input) { var validformat = /\d{4}\-\d{2}\-\d{2}/; var d = document.getElementById(input).value; if (!validformat.test(d)) { // check valid format showMessage('format',input); return false; } return true; } function showMessage(messagetype, input) { if (messagetype == "format") { alert ("Invalid date format - please re-enter as YYYY-MM-DD"); } else if (messagetype == "impossible") { alert ("Impossible year/month/day of birth - please re-enter."); } else if (messagetype == "child") { alert ("Only adults are allowed."); } else if (messagetype == "empty") { alert ("Nothing was filled out."); } document.getElementById(input).select(); } function daysInMonth(month,year) { // months are 1-12 var dd = new Date(year, month, 0); return dd.getDate(); } </script> </head> <body> <form action="" method="POST" onsubmit="return checkAge('dob')"> <input type="text" name="dob" id="dob" value="" /> <input type="submit" value="submit" /> </form> </body> </html> Works great, love it. I tried to add it to the php script I need to run it in and it's like it's not even there. Here's the two scripts needed for the php stuff one setup script that is included in others // more html/php stuff here .... function outputHeader($title, $id, $ids, $desc) { ?> <!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=iso-8859-1" /> <meta name="description" content="<?php echo $desc; ?>" /> <title><?php echo $title ?></title> <script type="text/javascript"> function checkAge(input) { var today = new Date(); var d = document.getElementById(input).value; if (d == "") { showMessage('empty',input); return false; } if (!checkFormat(input)) { // check valid format return false; } d = d.split("-"); var byr = parseInt(d[0]); var nowyear = today.getFullYear(); if (byr >= nowyear || byr < 1900) { // check valid year showMessage('impossible',input); return false; } var bmth = parseInt(d[1],10)-1; // radix 10! if (bmth <0 || bmth >11) { // check valid month 0-11 showMessage('impossible',input); return false; } var bdy = parseInt(d[2],10); // radix 10! var dim = daysInMonth(bmth+1,byr); if (bdy <1 || bdy > dim) { // check valid date according to month showMessage('impossible',input); return false; } var age = nowyear - byr; var nowmonth = today.getMonth(); var nowday = today.getDate(); var age_month = nowmonth - bmth; var age_day = nowday - bdy; if (age < 18 ) { showMessage('child',input); return false; } else if (age == 18 && age_month <= 0 && age_day <0) { showMessage('child',input); return false; } } function checkFormat(input) { var validformat = /\d{4}\-\d{2}\-\d{2}/; var d = document.getElementById(input).value; if (!validformat.test(d)) { // check valid format showMessage('format',input); return false; } return true; } function showMessage(messagetype, input) { if (messagetype == "format") { alert ("Invalid date format - please re-enter as YYYY-MM-DD"); } else if (messagetype == "impossible") { alert ("Impossible year/month/day of birth - please re-enter."); } else if (messagetype == "child") { alert ("Only adults are allowed."); } else if (messagetype == "empty") { alert ("Nothing was filled out."); } document.getElementById(input).select(); } function daysInMonth(month,year) { // months are 1-12 var dd = new Date(year, month, 0); return dd.getDate(); } </script> <?php // more html/php stuff here .... } and this is how I call it <?php // more html/php stuff here /**** list everything out ****/ outputHeader($title, $id, $ids, ""); // included here // list columns echo "<p>To add/edit a family member (18 and older), include their information in the form below and click submit. <br />To remove them, click the remove link to the right of the family member you wish to remove.</p><p class='small'>*Note: \"Family members\" are defined as: spouse or partner, children - includes step and adopted children (must be over age 18), parents of employee and parents of spouse or partner.</p>"; if ($error == true) { $_SESSION['EnrollError'] = "Sorry, there was a system error. Please contact adminstrator."; } if (isset($_SESSION['EnrollError'])) { echo "<p id=\"err\">$_SESSION[EnrollError]</p>"; } echo "<form action='' method='POST' id='enrollment_form' onsubmit=\"return checkAge('DOB')\">\r\n"; // called here echo "<table id='enrollment_table'>\r\n"; //more html/php stuff here .... ?> I have no idea why it won't work inside the php script. I know that's alot of code, but I only posted what I thought would be relevant. Any help would be appreciated.
  2. http://php.net/manual/en/function.str-replace.php This should help
  3. @KDM: FYI- this could be condensed into one statement if you wanted; like: if (isset($_POST['submit']) && $car_class == FALSE) { // code to execute }
  4. You need to give more than 14 minutes to help
  5. You don't need the function keyword before your call; it's a built in function and php thinks you're trying to re-write it
  6. What version of php do you have? I ask because of this error: Usually that's because the version is less than 5.x
  7. I suspect your issue is here. You're not actually setting the session variable to anything. else { $_SESSION['username']; $display = $_SESSION['username']; echo "<font color=green><font face=verdana><font size=4>You are now Logged In, " .$_SESSION['username']. "</font>"; You also set the session to another variable, then don't use it. Unless you use it later, seems pointless. But I reiterate: Hope that helps
  8. The dash may or may not be needed depending on your setup. If you need to store first name in one field and last in another, the dash is needed to parse out the pieces, otherwise if you are storing them in one field, it would not.
  9. Most of it You lose me a little at the end there. Can you show a dump of your db so we can see your structure? I think I get what you mean, but seeing the actual thing will help.
  10. Sure it could, but if you read up on normalization, you'll see why its usually done this way. Has to do with unique keys and such; but yes, you could do it that way. Good luck!
  11. Info Table UserID | UserName | ListID 1 | ibauser | 1 2 | i2bauser | 2 List Table ID | ListID | Field | Show 1 | 1 | fake@email.com | 1 2 | 1 | 555-555-5555 | 0 3 | 2 | fake2@email2.com | 0 4 | 2 | 555-555-1234 | 1 User 1 (ibauser) has his email showing according to ListID 1 User 2 (i2bauser) has their phone number showing according to ListID 2 Think of it this way: A user owns the listID associated to it in the Info table, so anything with the matching listID in the List table is his data Hope that helps
  12. Close, but not quite. For that, you would add a primary key, most likely auto-incrementing. I can help throw that in if you need it. ListID would represent all the choices ibauser made. Notice all the ListID's in the List table say 1. That means that all those choices belong to the User with ListID 1. Make sense? So... ibauser has an email of fakeemail@faker.net and a phone number 555-555-5555, and only wants to show the email address because it's marked with a 1 for true. To get his info, we would grab all fields in List that have a ListID=1 because that's ibauser's ListID. See what I mean?
  13. Try this. I didn't test it though. Just removed the parts I mentioned in my previous post <?php session_start(); if( isset($_POST['submit'])) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. echo 'Thank you. Your message said "'.$_POST['message'].'"'; } else { ?> <h1>Guestbook with Captcha</h1> <form action="form.php" method="post"> <table> <tr> <td>Name</td><td> <input type="text" name="name" id="name" /></td> </tr> <tr> <td>Email</td><td> <input type="text" name="email" id="email" /></td> </tr> <tr> <td valign="top">Message</td><td> <textarea rows="5" cols="30" name="message" id="message"></textarea></td> </tr> <tr> </tr> <tr> <td <input type="submit" name="submit" value="Submit" /> </td> </tr> </table> </form> <?php } ?>
  14. You were attempting to turn this into this if I'm understanding you correctly. And the point was to allow people to turn on/off parts of their profiles for display. Correct? So we take all those parts out of the original table and create a new table out of them, adding a field that takes a true or false value that tells us whether or not to show it. The new table's list id goes into the old table as a foreign key. Here's an example: Info Table UserID | ListID ibauser | 1 List Table ListID | Field | Show 1 | fakeemail@faker.net | 1 1 | 555-555-5555 | 0 This shows imaginery data. You would get everything by using sql similar to this: SELECT your,fields,here FROM Info INNER JOIN List ON Info.ListID=List.ListID WHERE UserID='ibauser' AND Show='1' Hope that helps to clarify. Let me know if you need more
  15. You would want to remove the input on the form, and remove the if/else that checks for the security code when processing.
  16. You're absolutely right about that Normalization is what you need, and in particular, relational tables. T'were me, I would go this route: Info table UserID, ListID <-- *note* This is a foreign key, coming from the table below List table ListID, Field, Show <-- *note* 'Field' would be where you stored the name of the field such as Phone, email, etc, and 'Show' would be a true/false value indicating show or hide Then you use a join (most likely inner) to link the info when pulling it from your db. Yep. See below. while($row = mysql_fetch_assoc(YOURMYSQLQUERYRESULTHERE)) { // do something with each row } Hope this all helps
  17. K. Worth a shot. I just looked at your op, and line 140, when your echoing the $_SERVER['PHP_SELF'], since you're echoing it in double quotes, you don't need the single quotes inside the brackets so try echo "$_SERVER[php_SELF]" Posting the most recent code might help too
  18. Your original error says output was started in index on line 9. If my math is correct, that is where you include menu.php. Might there be something outputting in that file?
  19. Or not enough of it's matching tag.. You probably needed that 3rd } that was referred to above. Try adding it back in and see if that helps
  20. Nevermind, I read it wrong
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.