Jump to content

bukwus

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by bukwus

  1. No, I understand what you're saying, I just don't understand why my code won't work for me.
  2. Hi I'm working on a form that, when submitted via POST, the info goes to a separate PHP file for processing and then returns to the form page. Pretty standard stuff. Everything is working, except, when it sends an email via the mail() function, the first SESSION (containing what the user selected for "Country") works fine, but the second (which is supposed to contain what they selected for "Best Time to Call") will only display "Array" in the email. Here's the form, sorry for the huge arrays: <?php session_start(); // SET ARRAYS $countriesNum = 237; $countries = array(1 => 'United States','United Kingdom','Canada','Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua & Barbuda','Argentina','Armenia','Aruba','Ascension Islands','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegowina','Botswana','Bouvet Island','Brazil','British Indian Ocean Territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo, Dem. Rep. of the','Congo, Rep. of the','Cook Islands','Costa Rica','Côte d\'Ivoire','Croatia','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Heard & Mc Donald Islands','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts & Nevis','Saint Lucia','Saint Pierre & Miquelon','Saint Vincent & the Grenadines','Samoa','San Marino','Sao Tome & Principe','Saudi Arabia','Senegal','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','So. Georgia & So. Sandwich Is.','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Suriname','Svalbard & Jan Mayen Islands','Swaziland','Sweden','Switzerland','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United States Minor Outlying Is.','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (U.S.)','Wallis & Futuna Islands','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe'); $countryAbrv = array(1 => 'USA','GBR','CAN','AFG','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','ASC','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','CD','COG','COK','CRI','CIV','HRV','CYP','CZE','DNK','DJI','DMA','DOM','TMP','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','ATF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GG','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IDN','IRQ','IRL','IM','ISR','ITA','JAM','JPN','JE','JOR','KAZ','KEN','KIR','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROM','RUS','RWA','SHN','KNA','LCA','SPM','VCT','WSM','SMR','STP','SAU','SEN','SYC','SLE','SGP','SVK','SVN','SGS','SLB','SOM','ZAF','ESP','LKA','SUR','SJM','SWZ','SWE','CHE','TWN','TJK','TZA','THA','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','YUG','ZMB','ZWE'); $callTimeNum = 4; $callTimeAbrv = array(1 => 'any','morn','noon','eve'); $callTime = array(1 => 'Anytime','Morning','Afternoon','Evening'); ?> <form id="formIF" action="form-test-engine.php" method="POST"> <table> <tr> <td width="35%"> <label for="country">Country</label> </td> <td width="65%"> <select name="country" class="textIF"> <?php for ($i = 1; $i <= $countriesNum; $i++) { echo'<option '.$_SESSION['chkCountry'.$i].' value="'.$countryAbrv[$i].'">'.$countries[$i].'</option>'; unset($_SESSION['chkCountry'.$i]); } ?> </select> </td> </tr> <tr> <td> <label for="callTime">Best Time to Call</label> </td> <td> <select name="callTime" class="textIF"> <?php for ($i = 1; $i <= $callTimeNum; $i++) { echo'<option '.$_SESSION['chkCallTime'.$i].' value="'.$callTimeAbrv[$i].'">'.$callTime[$i].'</option>'; unset($_SESSION['chkCallTime'.$i]); } ?> </select> </td> </tr> <tr> <td colspan="2" id="submitIF"> <input type="submit" name="submit" value="Submit" /> <input type="submit" name="submitReset" value="Reset Form" /> </td> </tr> </table> </form> </p> <?php if ($_SESSION['process'] == 'yes') { $to = "oddidego@yahoo.com"; $email_subject = "Info request from Interface Financial Group on Buzgate"; $email_body = "Country: ".$_SESSION['country']."\n Best time to call: ".$_SESSION['callTime']."\n"; $headers = "From: oddidego@yahoo.com"; mail($to, $email_subject, $email_body, $headers); } $_SESSION['process'] = 'no'; ?> Here's the processing file: <?php session_start(); // CHECK IF RESET OR SUBMIT BUTTON WAS SELECTED if (isset($_POST['submitReset'])) { session_destroy(); $_SESSION['process'] = 'no'; } elseIf (isset($_POST['submit'])) { // SET ARRAYS $countriesNum = 237; $countries = array(1 => 'United States','United Kingdom','Canada','Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua & Barbuda','Argentina','Armenia','Aruba','Ascension Islands','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegowina','Botswana','Bouvet Island','Brazil','British Indian Ocean Territory','Brunei','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos (Keeling) Islands','Colombia','Comoros','Congo, Dem. Rep. of the','Congo, Rep. of the','Cook Islands','Costa Rica','Côte d\'Ivoire','Croatia','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Heard & Mc Donald Islands','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russia','Rwanda','Saint Helena','Saint Kitts & Nevis','Saint Lucia','Saint Pierre & Miquelon','Saint Vincent & the Grenadines','Samoa','San Marino','Sao Tome & Principe','Saudi Arabia','Senegal','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','So. Georgia & So. Sandwich Is.','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Suriname','Svalbard & Jan Mayen Islands','Swaziland','Sweden','Switzerland','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United States Minor Outlying Is.','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Virgin Islands (British)','Virgin Islands (U.S.)','Wallis & Futuna Islands','Western Sahara','Yemen','Yugoslavia','Zambia','Zimbabwe'); $countryAbrv = array(1 => 'USA','GBR','CAN','AFG','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','ASC','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','CD','COG','COK','CRI','CIV','HRV','CYP','CZE','DNK','DJI','DMA','DOM','TMP','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','ATF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GG','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IDN','IRQ','IRL','IM','ISR','ITA','JAM','JPN','JE','JOR','KAZ','KEN','KIR','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROM','RUS','RWA','SHN','KNA','LCA','SPM','VCT','WSM','SMR','STP','SAU','SEN','SYC','SLE','SGP','SVK','SVN','SGS','SLB','SOM','ZAF','ESP','LKA','SUR','SJM','SWZ','SWE','CHE','TWN','TJK','TZA','THA','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','YUG','ZMB','ZWE'); $callTimeNum = 4; $callTimeAbrv = array(1 => 'any','morn','noon','eve'); $callTime = array(1 => 'Anytime','Morning','Afternoon','Evening'); // SET SESSIONS if(isset($_POST['country'])) { for ($i = 1; $i <= $countriesNum; $i++) { if ($_POST['country'] == $countryAbrv[$i]) { $_SESSION['chkCountry'.$i] = 'selected="selected"'; $_SESSION['country'] = $countries[$i]; } } } if(isset($_POST['callTime'])) { for ($i = 1; $i <= $callTimeNum; $i++) { if ($_POST['callTime'] == $callTimeAbrv[$i]) { $_SESSION['chkCallTime'.$i] = 'selected="selected"'; $_SESSION['callTime'] = $callTime[$i]; } } } $_SESSION['process'] = 'yes'; } header('Location: form-test.php'); ?> And here's an example of the resulting email content: Country: American Samoa Best time to call: Array
  3. Unfortunately I need the number that is displayed on the page to go back to the number formatting that includes a comma. Is there a way to un-format the $POST data, place the un-formatted number in a variable and then format the variable without this happening?
  4. Hi I'm using a form that uses number_format. It works fine until the number in question gets into the thousands. I can enter "3000", click Calculate and it comes back as "3,000.00" which is perfect. But if I click Calculate again, it changes to "3.00". How can I get it to remain "3,000.00"? Here's the code: <form action="test.php" method="POST" > <?php if (empty($_POST['data1'])) { $number = ''; } else { str_replace(",","",$_POST['data1']); $number = number_format((double)$_POST['data1'],2); } ?> <input type="text" style="40" name="data1" value="<?php echo $number; ?>"> <input type="submit" name="submitCalc" value="Calculate" /><br /> <a href="test.php">Reset Form</a> </form>
  5. Wow. I clearly need an arithmetic refresher. Many thanks, this is very helpful.
  6. Hello I'm trying to use PHP "for loops" to build a table of 10 rows with 5 columns and I'm sure there's a better way to do this, but the result is the page won't fully load and continually spins its wheel. Here's the code: $states = array(1 => 'AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','OZ','PA','PR','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI' ); <table id="stateCheck"> <?php for ($i = 1; $i <= 10; $i++) { echo '<tr>'; for ($j = 5*$i; $j <= $j+4; $j++) { echo '<td> <input type="checkbox" name="state" value="'.$states[$j].'" /> '.$states[$j].' </td>'; } echo '</tr>'; } ?> <tr> <td> <input type="checkbox" name="state" value="WV" /> WV </td> <td> <input type="checkbox" name="state" value="WY" /> WY </td> </tr> </table> Is it breaking because I'm using arithmetic operators to define the nested for loop? Many thanks
  7. Thank you everyone. This was very helpful.
  8. Hi I have built a series of forms with PHP and have been using SESSIONS to carry values from one to another. In one, the value of a variable is determined by adding the values of several other variables together: $totalFixed = $fixedCost1 + $fixedCost2 + $fixedCost3 + $fixedCost4 + $fixedCost5; This equation is working fine on that page. I then place the value of $totalFixed in a SESSION variable: $_SESSION['totalFix']=$totalFixed; I then assign this SESSION variable's value to a new variable on another page in the series: $dataValue[4] = $_SESSION['totalFix']; The number displays fine on this page as well. However, when the value is above 1,000 and I try to subtract another number from it, it ignores everything to the right of the comma. For example, if $dataValue[4] is 10,132 and $dataValue[5] is 25 and I subtract $dataValue[4] from $dataValue[5], the result is -15. Does anyone know the reason for this? Many thanks, Andy
  9. Hello I'm getting the following error: number_format() expects parameter 1 to be double, string given in file path on line 118 And this is what's on line 118: $_SESSION['dataValue3'] = number_format($dataValue[3]); Any help would be greatly appreciated. Andy
  10. Real helpful, guys. Like I said, I'm just starting out and experimenting. My intention was to allow someone to create multiple instances via a button. Once I understood this step in the process I would move on and add more functionality.
  11. Here's what I've been playing around with just to get to know OOP a little better. I created a PHP file that allows you to create a visible table for each time you click on the "Create Table" button. It works fine, but I want to know if I should be putting more of this code inside the CLASS. Here's the code: <?php session_start(); class myClass { public $html = '<table width="50%" border="1"> <tr> <td width="50%" border="1"> Cell 1 </td> <td width="50%" border="1"> Cell 2 </td> </tr> </table>'; } if ((!isset($_POST['reset'])) && (!isset($_POST['createTable']))) { $_SESSION['tableCount'] = 0; } if (isset($_POST['reset'])) { $_SESSION['tableCount'] = 0; unset ($_POST['reset']); } if (isset($_POST['createTable'])) { $_SESSION['tableCount'] = $_SESSION['tableCount'] + 1; unset ($_POST['createTable']); } if ($_SESSION['tableCount'] > 0) { for ($i = 1; $i <= $_SESSION['tableCount']; $i++) { $obj[$i] = new myClass; echo $obj[$i] -> html; } } ?> <form action="class_lib2.php" method="post"> <p><input type="submit" name="createTable" value="Create Table" /></p> <p><input type="submit" name="reset" value="Reset" /></p> </form> <?php echo $_SESSION['tableCount']; ?> Any suggestions are welcome. Thanks...
  12. Thanks guys. Here's what I've been playing around with just to get to know OOP a little better. I created a PHP file that allows you to create a visible table for each time you click on the "Create Table" button. It works fine, but I want to know if I should be putting more of this code inside the CLASS. Here's the code: <?php session_start(); class myClass { public $html = '<table width="50%" border="1"> <tr> <td width="50%" border="1"> Cell 1 </td> <td width="50%" border="1"> Cell 2 </td> </tr> </table>'; } if ((!isset($_POST['reset'])) && (!isset($_POST['createTable']))) { $_SESSION['tableCount'] = 0; } if (isset($_POST['reset'])) { $_SESSION['tableCount'] = 0; unset ($_POST['reset']); } if (isset($_POST['createTable'])) { $_SESSION['tableCount'] = $_SESSION['tableCount'] + 1; unset ($_POST['createTable']); } if ($_SESSION['tableCount'] > 0) { for ($i = 1; $i <= $_SESSION['tableCount']; $i++) { $obj[$i] = new myClass; echo $obj[$i] -> html; } } ?> <form action="class_lib2.php" method="post"> <p><input type="submit" name="createTable" value="Create Table" /></p> <p><input type="submit" name="reset" value="Reset" /></p> </form> <?php echo $_SESSION['tableCount']; ?> Any suggestions are welcome. Thanks...
  13. Hi I'm attempting to learn more advanced PHP, such as OOP and the integration of XML, by making a browser-based version of the old Richard Garfield card game "Netrunner". I have a few years experience with pretty basic (bordering on intermediate) PHP. I've done some very basic coding for the game with PHP forms and I've researched some OOP (classes, objects, methods, etc.) but I'm not finding the beginner tutorials that I need. Everything I find has terminology and code that is beyond me. Does anyone have any book or website suggestions for me? I've tried the PHP online manual, but even that throws in advanced stuff all over the place. My goal is to better learn how to use PHP (because I've already put time into it) to create browser based games. Many thanks, Andy
  14. I need to know where to put an e-mail validation code in my form so it can check to see if valid e-mail I have tr5ied to place it but nothing seems to work I have attached the form code could some let me know where the validation code would go thanks jim here is the validation code function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } Form Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <META NAME="robots" CONTENT="noindex,nofollow"> <link href="../../../styles/_e-learning.css" rel="stylesheet" type="text/css" /> </head> <body background="images/background.jpg"> <div id="container" align="center"><a name="result"></a><div id="header"> <p class="tenTitle">Exercise 1a: 10 Great Reasons To Be In Business</p></div> <div id="main"> <?php // SET VARIABLES AND ARRAYS $stepNumber = '1a'; $numQuestions = '10'; $questions = array(1 => '1. Be your own boss', '2. Ability to set your own hours and working conditions', '3. Hard work directly benefits you and your business', '4. Undertaking an exciting new venture', '5. Control over earning and growth potential', '6. Unlimited opportunities to challenge yourself and learn', '7. Chance to be creative and take risks', '8. Ability to fully use your skills, knowledge, and talent', '9. Desire financial independence', '10. Ability to work in the industry/field of your choice' ); $numOptions = 5; $options = array(1 => 'Strongly Agree', 'Agree', 'Neutral', 'Disagree', 'Strongly Disagree' ); // IF FORM WAS FILLED OUT, CALCULATE SCORE, ELSE SCORE EQUALS 0 $score[] = 0; for ($i = 1; $i <= $numQuestions; $i++) { if(isset($_POST['radio'.$i])){ if ($options[$_POST['radio'.$i]] == $options[1]) { $score[$i] = 5; } elseif ($options[$_POST['radio'.$i]] == $options[2]) { $score[$i] = 4; } elseif ($options[$_POST['radio'.$i]] == $options[3]) { $score[$i] = 3; } elseif ($options[$_POST['radio'.$i]] == $options[4]) { $score[$i] = 2; } else { $score[$i] = 1; } } else { $score[$i] = 0; } } // UNIQUE TO FIRST SESSION OF EACH STEP $_SESSION['totalScore'] = 0; // ADD QEUSTIONS AND ANSWERS TO $EMAIL_BODY AND $EMAIL_BODYCC BELOW // IF FORM WAS SUBMITTED, MOVE ON TO NEXT STEP (ERROR CHECKING) if(isset($_POST['submit'])) { // CHECK FOR MISSING DATA (ERROR CHECKING) for ($i = 1; $i <= $numQuestions; $i++) { if (empty($_POST['radio'.$i])) { $problem = TRUE; $dataSpan[$i] = '<span style="color:red; font-weight:bold;">'.$questions[$i].'</span>'; } else { $dataSpan[$i] = $questions[$i]; } } if (empty($_POST['email'])) { $problem = TRUE; $emailSpan = '<span style="color:red; font-weight:bold;">*Your email address</span>'; } else { $emailSpan = '*Your email address'; } if (!empty($_POST['emailCc']) && (empty($_POST['name']))) { $problem = TRUE; $nameSpan = '<span style="color:red; font-weight:bold;">Your Name</span>'; } else { $nameSpan = 'Your Name'; } // IF MISSING DATA, PREPARE TO DISPLAY FORM. IF NO MISSING DATA, MOVE ON TO NEXT STEP (THANK YOU, SEND EMAILS AND LINK TO NEXT FORM) if ($problem == TRUE) { $display = TRUE; } else { $display = FALSE; } } // IF THE FORM IS NOT BEING SUBMITTED (FIRST VISIT TO PAGE), SET THE // FORM DISPLAY VARIABLE TO TRUE AND DEFINE VALUES OF DATA#SPAN VARIABLES (QUESTIONS) else { $display = TRUE; for ($i = 1; $i <= $numQuestions; $i++) { $dataSpan[$i] = $questions[$i]; } $emailSpan = '*Your email address'; $nameSpan = 'Your Name'; } if ($display == TRUE) { print '<p><strong>Instructions</strong>: Below are some of the attitudes and desires that many successful entrepreneurs possess. Read the list carefully. Think about how each of the statements relate to you - your ideas, desires, motivations, and areas of comfort or discomfort. In this exercise, quickly check each category with the answer that best relates to you, then go back and think about each - perhaps you might change your mind with this further refection - you can always come back later and change your answer.</p>'; if ($problem == TRUE) { print '<p>Please fill in questions marked in <span style="color:red; font-weight:bold;">red</p>'; } print '<div id="tenForm"> <form action="ten_steps_'.$stepNumber.'.html#result" method="POST" > <table border="0" cellpadding="4" cellspacing="3">'; for ($i = 1; $i <= $numQuestions; $i++) { echo '<tr> <td align="left" valign="top" border="0" class="submitCell"> <p>'.$dataSpan[$i].'</p>'; for ($j = 1; $j <= $numOptions; $j++) { $elemID = "radio" . $i . "_" . $j; $elemName = "radio" . $i; $chk = ""; if(isset($_POST[$elemName])) { if($_POST[$elemName] == ((string) $j)) { $chk = "CHECKED"; } } echo "<input type=\"radio\" id=\"$elemID\" name=\"$elemName\" $chk value=\"$j\">$options[$j]\n"; } print '</td> </tr>'; } print '</table> <table border="0" cellpadding="3" cellspacing="2"> <tr> <td align="left" valign="top" border="0">'; include ($filePath.'/e-learning/tenScores.html'); print '</th> </tr> <tr> <td align="left" valign="top" border="0"> Submitting the form (* = required) </th> </tr> <tr> <td class="submitCell"> '.$emailSpan.'<br /> (to receive a copy of this form)<br /> <input type="text" size="40" maxlength="100" name="email" value="'.$_POST['email'].'" /> </td> </tr> <tr> <td class="submitCell"> Send Copy To eMentor<br /> <input type="text" size="40" maxlength="100" name="emailCc" value="'.$_POST['emailCc'].'" /> </td> </tr> <tr> <td class="submitCell"> '.$nameSpan.'<br /> (*required if sending a copy)<br /> <input type="text" size="40" maxlength="100" name="name" value="'.$_POST['name'].'" /> </td> </tr> <tr> <td class="submitCell" align="center"> <input type="reset" value="Clear" /> <input type="submit" name="submit" value="Submit" /><br /> <a href="'.$filePathState.'about_privacy.html" target="_blank"><span style="font-size:9px;">View our privacy policy</span></a> </td> </tr> </table> </form> </div>'; } else { // DEFINE SESSION VARIABLES $_SESSION['email']=$_POST['email']; $_SESSION['emailCc']=$_POST['emailCc']; $_SESSION['name']=$_POST['name']; $_SESSION['score'.$stepNumber]=array_sum($score); $_SESSION['totalScore'] = $_SESSION['totalScore'] + $_SESSION['score'.$stepNumber]; // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $to = 'askbuz@buzgate.org,'.$_POST['email']; $email_subject = "Your Results: 10 Great Reasons To Be In Business"; for ($i = 1; $i <= $numQuestions; $i++) { $eBodyQuestions .= $questions[$i]."\n" .$options[$_POST[radio.$i]]."\n\n"; } $email_body = $eBodyQuestions."Score: ".array_sum($score)."\n INTERPRETING THE SCORE:\n Score of 34-50: High Match\n Score of 21-35: Medium Match\n Score of 0-20: Low Match\n Total Score: ".$_SESSION['totalScore']."\n\n"; $headers = "From:".$_POST['email']; //PLACE VARIABLES IN MAIL FUNCTION mail($to, $email_subject, $email_body, $headers); // DEFINE VARIABLES FOR MAILING TO USER AND BUZGATE $toCc = $_POST['emailCc']; $email_subjectCc = "Your Results: 10 Great Reasons To Be In Business from ".$_POST['name']; $email_bodyCc = $_POST['name']." has sent this to you from www.BUZGate.org/8.0/".$state_abbrv_low."/".$page_name."\n Please contact us at askbuz@buzgate.org if you have received this in error.\n\n"; $email_bodyCc = $email_bodyCc.$email_body; $headersCc = "From:askbuz@buzgate.org"; //PLACE VARIABLES IN CC MAIL FUNCTION mail($toCc, $email_subjectCc, $email_bodyCc, $headersCc); // DISPLAY RESPONSE TO CORRECTLY FILLING OUT FORM echo "<p class='textCenter' >Thank you ".$_POST['name']." for completing Step ".$stepNumber."</p> <p class='textCenter'>Your Step ".$stepNumber." Score: ".$_SESSION['score'.$stepNumber]."<br /> Your Total Score: ".$_SESSION['totalScore']."</p>"; include ($filePath.'/inc2/tenScores.html'); echo "<p class='textCenter'><a href='ten_steps_1b.html'>Click here</a> to continue to 1b: 10 Great Reasons Not To Be In Business</p>" ; } ?> </div> <div id="footer"></div></div> </body> </html>
  15. Hmmm Thanks Devils. I'll see what I can do.
  16. Hi I'm using PHP to check if a form was filled out correctly, or at all. I have questions and three answers in the form of radio buttons. I'm using "if empty" to check if a question wasn't answered but it's not doing the trick: for ($i = 1; $i <= $numQuestions2; $i++) { if (empty($_POST['radio'.$i])) { $problem = TRUE; $dataSpan2[$i] = '<span style="color:red; font-weight:bold;">'.$questions2[$i].'</span>'; } else { $dataSpan2[$i] = $questions2[$i]; } } How should I be doing this? Many thanks
  17. Okay, here's what it looks like now: <a name="result"></a> <?php $value = array(); if(isset($_POST['submit'])){ $value[] = $_POST['choice1']; $value[] = $_POST['choice2']; $value[] = $_POST['choice3']; } else { $value[] = 'Choose one...'; } ?> And the form: <form action="page-name.html#result" method="POST"> <select name="choice1"> <option>'.$value[0].'</option> <option value="Addressed">Addressed</option> <option value="Does not apply">Does not apply</option> <option value="Needs attention">Needs attention</option> </select> I made sure the first $value key was 0. When I fill out the form and submit, the values carry over just fine. Unfortunately, when you first come to the page, only the first select box is populated with "Choose one...". The others are blank. Any thoughts why? Thank you Andy
  18. Should this work, or am I incorrectly defining $value as an array? $value = array(); if(isset($_POST['submit'])){ $value[1] = $_POST['choice1']; $value[2] = $_POST['choice2']; $value[3] = $_POST['choice3']; } else { $value[] = 'Choose one...'; }
  19. Hi I'm beginning a form that asks questions and has a drop down list of options to choose from. I'm going to use PHP to check for errors, loops to cut down on repetition, etc., but right now I'm just testing code at a basic level. Here's the PHP: if(isset($_POST['submit'])){ $value[1] = $_POST['choice1']; $value[2] = $_POST['choice2']; $value[3] = $_POST['choice3']; } else { $value[1] = 'Choose one...'; $value[2] = 'Choose one...'; $value[3] = 'Choose one...'; } Here's the basic form element: <select name="choice1"> <option value="0">'.$value[1].'</option> <option value="Addressed">Addressed</option> <option value="Does not apply">Does not apply</option> <option value="Needs attention">Needs attention</option> </select> My problem is that the text displayed in the select box is only the first letter of whatever it's supposed to be. For example: if it's the first time visiting the form, each box only has "C" in it instead of "Choose one..." OR if "Does not apply" was chosen and the form is submitted, "D" is all that shows up in that box. Any idea what's happening here? Many thanks, Andy
  20. Hi I've built a form so that the questions generate automatically. I set the number of questions into $numQuestions, I put the questions in an array called $questions, then used a typical for loop to create the questions in an HTML table. for ($i = 1; $i <= $numQuestions; $i++) { echo '<tr> <td align="left" valign="top" border="0"> <p>'.$questions[$i].'</p> <textarea rows="5" cols="53" id="data'.$i.'" name="data'.$i.'">'.$_POST['data'.$i].'</textarea> </td> </tr>'; } It works fine. The purpose of this is because I'm building many forms with similar structure, but different questions and this saves a great deal of time. Here's where I'm getting stumped: When a user fills out the form and submits it, the results are sent to us as well as to their email address. I need to create a similar for loop that can generate the questions and the user's answers in the form email that is sent. The body of the email is the value of the $email_body variable. So, is there a way to assign the output of a for loop to the value of a variable? Many thanks, Andy
  21. It worked! Thanks man. You're a life saver.
  22. Hi I've created a form that includes check boxes. Here's a couple examples of the code: <input type="checkbox" name="category[]" value="Accounting" /> Accounting<br /> <input type="checkbox" name="category[]" value="Administration" /> Administration<br /> I'm trying to include the checked values of the array "category[]" with the rest of the form's info in an email that results when the form is filled out correctly. Here's the PHP I'm using to handle the email. I've placed ??? where I'm having the trouble: $to = 'email@company.org'; $email_subject = 'ExpertNet Aplicant'; $email_body = "Name: ".$_POST['firstName'] . $_POST['lastName']."\n Title: ".$_POST['title']."\n Email: ".$_POST['email']."\n Company: ".$_POST['company']."\n Company Description: ".$_POST['description']."\n Address: ".$_POST['address1']."\n Address: ".$_POST['address2']."\n City: ".$_POST['city']."\n State: ".$_POST['state']."\n Zip Code: ".$_POST['zip']."\n Phone#: ".$_POST['phone']."\n Fax#: ".$_POST['fax']."\n Web Address: ".$_POST['web']."\n Categories Chosen: "???" \n Other: ".$_POST['other']; $headers = "From:" .$_POST['email']; //Place variables in mail funciton mail($to, $email_subject, $email_body, $headers); Hope this makes sense. Many thanks, Andy
×
×
  • 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.