Jump to content

Psycho

Moderators
  • Posts

    12,159
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. I see one problem with your current code. The onsubmit trigger is not using a "return". So, even if validation fails the form will still be submitted. It should look like this: <form name="auto1" method="post" class="beccas" action="confirm.php" onsubmit="return returnValidate();"> The validation function should return a true/false based on whether validation passes and the "return" in the onsubmit trigger will submit or not submit the form accordingly. Personally, I would just name the function validate() or validateForm() plus I would pass the form object in the call like this onsubmit="return validateForm(this);" The function to validate just the three fields could be as simple as this: function validateForm(formObj) { if (!formObj.name.value || !formObj.last.value || !formObj.email.value) { //Validation failed alert('Name, Last and email are all required.'); return false; } //Validation passed return true; } You can expand on that as much as you want to give more detailed errors or do more comprehensive validation, such as ensuring the email is properly formatted. But, with any JS validation it is only an "enhancement" of any server-side validatin that needs to be done.
  2. From the manual: The description is pretty clear. Then just test using a single file, ensure you get the results you want, and then implement in your current code to process all the files. The manual includes a very simple example that should make it easy to get started. OK, now you are just being silly. Are you really asking if a PHP function works? It's not like the manual is filled with functions that don't work. It would take less than 5 minutes to copy the example from the manual to test it for yourself. You already had your answer when you started this thread.
  3. function returnFirstImage($inputArray) { $outputArray = array(); foreach($inputArray as $record) { if(!isset($outputArray[$record['prod_id']]) { $outputArray[$record['prod_id']] = $record['image'] } } return $outputArray; }
  4. You are making no sense now. I don't see what that question has to do with what you originally asked. You need to understand that we are not sitting there with you involved in whatever you are working on. We only know what you tell us, and that isn't much. However, I will venture a guess that what you are doing is trying to process some data file and create multiple flat HTML pages. And now you are wanting to create links in those HTML files to navigate from one page to another. Why? If you are using PHP, just create ONE PHP page that will allow the user to dynamically display the different "pages"? The whole point of using a server-side language is that you don't have to hard code the pages - they can be dynamic. And, you seem to have taken the approach of using PHP to generate hard coded pages. Give this a try. Just set the $dataFile to the file you are reading data from. You can now have all your "pages" with a single file. And if your input file with the data changes you don't have to regenerate the flat files - this page will continue to work with the new data. <?php $recordsPerPage = 3; $dataFile = 'somefile.txt'; $fileContents = file($dataFile); foreach ($fileContents as $line) { list ($website, $description) = explode('|', $line); $website = trim($website); $description = trim($description); $http = (substr($website, 0,7)=="http://") ? '' : 'http://' ; $website = "<a href=\"{$http}{$website}\">{$website}</a><br/> "; $rows[] = array( 'website' => $website, 'description' => $description, 'adsense' => $adsense ); } //Set number of total pages $pageCount = ceil(count($rows) / $recordsPerPage); //Set current page $page = (int) $_GET['page']; if ($page<1 || $page>$pageCount) { $page = 1; } //Create page specific output $rowsHTML = ''; for ($i=0; $i<$recordsPerPage; $i++) { $record = ($page-1) * $recordsPerPage + $i; $rowsHTML .= " <tr> "; $rowsHTML .= " <td>{$rows[$record]['website']}</td> "; $rowsHTML .= " <td>{$rows[$record]['description']}</td> "; $rowsHTML .= " <td>{$rows[$record]['adsense']}</td> "; $rowsHTML .= " </tr> "; } //Create page navigation $nav = "Page {$page} of {$pageCount}: "; $nav .= ($page==1) ? 'Prev': '<a href="?page='.($page-1).'">Prev</a>'; $nav .= ' | '; $nav .= ($page==$pageCount) ? 'Next': '<a href="?page='.($page+1).'">Next</a>'; //Set todays date $lastUpdate = date('j F Y', getlastmod()); ?> <html> <head></head> <body> <table> <?php echo $nav; ?> <br /><br /> <?php echo $rowsHTML; ?> </table> <br /><br /> <p><small>1 December 2004 ยท Last updated: <?php echo $lastUpdate; ?> </body> </html>
  5. OK, I misread your first post and thought you wanted separate tables on the same page. No matter the logic is still valid. You just need to create a new file on each iteration of the first for loop where this line is $tablesHTML .= "<table> {$rowsHTML}</table> ";
  6. A lot of your code makes no sense. If you are giving $row an incremental value, then why are you sorting the array? It will already be in sequential value. Plus sort() is not meant to be used on a multidimensional array. reset() will also not be needed since the array will already be at the first element. In fact, you don't need $row at all. <?php while (!feof($fp)) { $line = fgets($fp,1024); //use 2048 if very long lines list ($website, $description) = split ("|", $line); //$website= "<a href="" . $website . "">" . $website . "</a><br/>"; $http = (substr($website, 0,7)=="http://") ? '' : 'http://' ; $website = "<a href="{$http}{$website}">{$website}</a><br/> "; $rows[] = array( 'website' => $website, 'description' => $description, 'adsense' => $adsense ); } fclose($fp); $tableCount = ceil(count($rows)/3); $recordsPerTable = 3; $tablesHTML = ''; for($i=1; $i<=$tableCount; $i++) { $rowsHTML = ''; for ($j=1; $j<=$recordsPerTable; $j++) { $rowsHTML .= " <tr> "; $rowsHTML .= " <td>{$rows[$i]['website']}</td> "; $rowsHTML .= " <td>{$rows[$i]['description']}</td> "; $rowsHTML .= " <td>{$rows[$i]['adsense']}</td> "; $rowsHTML .= " </tr> "; } $tablesHTML .= "<table> {$rowsHTML}</table> "; } echo $tablesHTML; echo "<p><small>1 December 2004 ยท Last updated: ".date('j F Y', getlastmod()); $HtmlCode = ob_get_contents(); ob_end_flush(); $fh=fopen('cookies.html','w'); fwrite($fh,$HtmlCode); fclose($fh); ?>
  7. Try changing the plus sign to the min and max number of characters you want to allow - encased in curly braces. I would assume the minimum would be 5 characters: a single letter file name, the period and a three character extension. So, you would use "{5,64}" to allow 5 to 64 characters. Example: preg_match('^[a-zA-Z0-9_s-]{5, 64}$', $fieldname)
  8. In my sig it states That line is missing a second single quote mark at the end of the line. That should have been easy to determine. Not sure what the confusion is. The other block of code that goes at the top of the page is the "logic" which will build the options you need and assign them to the variable $pageOptions. The code inside the display content (i.e. HTML) simply echos those options to the page.
  9. Once you get those pages converted to php, this will be a little more logical and easier to maintain. Put the logic of your code at the top of the page and the output at the bottom of the page. Makes maintenance much easier. <?php $pages = array( 'Page 1' => 'link1.php', 'Page 2' => 'link2.php', 'Page 3' => 'link3.php' ); $pageOptions = ''; foreach ($pages as $link => $page) { $selected = ($page==$_SERVER['PHP_SELF']) ? ' selected="selected" : ''; $pageOptions .= "<option value=\"{$page}\"{$selected}>{$link}</option>"; } ?> <form class="form_margin" name="form" id="form"> <select name="jumpMenu" class="wood" id="jumpMenu" onChange="MM_jumpMenu('parent',this,0)"> <?php echo $pageOptions; ?> </select> </form>
  10. It is not goop practice to put logic into your trigger (i.e. onclick="num=num+1"), instead you should call a function. <script type="text/javascript"> var num=0 function addToNum() { num++; if (num<6) { window.alert("Please add more to Num!"); } else { window.alert("congrats"); } return; } </script> <input name="Add" type="button" value="Add More!" onclick="addToNum();" /> <br /> <a href="#" onclick="alert(num)">Check Value of Num</a><br /><br />
  11. <html> <head> <script type="text/javascript"> var outTimes = new Array(); function validateForm(formObj) { var errors = new Array(); //Trim leading and trailing spaces formObj.tarea.value = formObj.tarea.value.replace(/^\s+|\s+$/g,''); //Validate the textarea if (!formObj.tarea.value) { errors[errors.length] = "Textarea is empty."; } //Validate the file upload if (!formObj.ffield.value) { errors[errors.length] = "A file must be selected."; } //Validate the checkboxes if (!formObj.cbox1.checked || !formObj.cbox2.checked) { errors[errors.length] = "At least one checkbox must be checked."; } //Process errors if (errors.length!==0) { var errMsg = 'The following errors ocured:\n'; for (var i=0; i<errors.length; i++) { errMsg += '\n - ' + errors[i]; } alert(errMsg); return false; } //No errors occured alert('No Errors'); return false; } </script> </head> <body> <form onsubmit="return validateForm(this)"> Textarea:<br /> <textarea name="tarea" id="tarea"></textarea> <br /><br /> File:<br /> <input type="file" name="ffield" id="ffield"> <br /><br /> Checkbox 1: <input type="checkbox" name="cbox1" id="cbox1" value="1"><br /> Checkbox 2: <input type="checkbox" name="cbox2" id="cbox2" value="2"><br /> <br /><br /> <button type="submit">Submit Form</button> </form> </body> </html>
  12. http://drewd.com/2007/01/25/reading-from-a-word-document-with-com-in-php http://phpclasses.goodphp.com/browse/package/3553.html http://davidwalsh.name/read-pdf-doc-file-php
  13. Yes, but the "content" will not be what you really want. The content will include a lot of markup data that describes how the content will be displayed. So, it will basically be unreadable in its native format. To make matters worse MS has recently changed the format of Word docs from a prioprietary format to an XML type format. Your best bet is to find an existing class to read the files for you.
  14. I have an idea that should work, but I'll leave it to you to implement. First, create a global variable to set whether the mp3 is playing or not. If you only have one div for this functionality a simple true/false will work. If you have multiple divs then I would set the value of the variable to the "active" div. Second, create a function that runs onload of the page. In that function have it process each of these divs in the following manner: 1) get the onmouse over event for the div, 2) recursively iterrate through each child element and apply the same onmouseover event to each child element. Now, when you mouse over the image inside the div the function to play the track will also be called. But, I suspect that the song will start at the beginning again, which I doubt you want. So, there is a little more to do. If the user is mousing DIRECTLY from one object to another there is only a millisecond of difference from the onmouseout to onmouseover triggers. So, for the mouseout event call a function first sets the gloable variable to "OUT" then uses a settimeout() call of about 1/10th of a second (or whatever works). that will in turn call another function which will check the global variable. If the global variable is still "OUT" it will stop the song and set the variable to FALSE. If not it does nothing. Then, on the onmouseover events the function called will check the gloabl variable. If set to "OUT" that means the song is still playing and does not start the song again, but it sets the variable to TRUE. If se tto FALSE it will start the song - and sets the variable to TRUE So, if the user mouses from one object in the div to another the progression would be like this: 0. If song is playing global var is set to TRUE 1. Mouseout function will set var to "OUT" 2. Mouseover function sets var to TRUE 3. Mouseout function (after .1 seconds) checks var and value is TRUE 4. Mouseout function does not stop the song
  15. Do your logic (i.e. PHP) first - THEN do your output. So, put all your PHP at the top if the page. For any output that the PHP generates, save it to appropriate variables and output those variables within the HTML output. Unorganized way <html> <body> Today is a <?php $dow = date("l"); if($dow=='Saturday' ||$dow=='Sunday') echo "weekend."; } else { echo "workday."; } ?> </body> </html> Better way <?php $dow = date("l"); if($dow=='Saturday' ||$dow=='Sunday') $dayType = "weekend."; } else { $dayType = "workday."; } ?> <html> <body> Today is a <?php echo $dayType; ?> </body> </html>
  16. Ok, a little googling came up with the function tep_draw_pull_down_menu for the OsCommers application. The parameters are: tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) And $values appears to need to be a multi-dimensional array in the format array ( [0] => array ( ['id'] => '1', ['text'] => 'Value 1' ), [1] => array ( ['id'] => '2', ['text'] => 'Value 2' ) )
  17. It is difficult to tell you how to accomplish this without knowing how the tep_draw_pull_down() function operates. What are the parameters for that function and what do they do? For example, how do you pass it the values? I would suspect it takes an array for the values (and possibly the labels). So, you can either create a hard-coded list or generate the list from a database. If the list will never (or rarely) change, then a hard-coded list is the easier way to go. if the list will change often, then you can create the list in a database and then create functionality to give an admin the ability to modify the list.
  18. If there is a reason you do not want to allow certain characters for a particular field (e.g. alpha characters in a date) then you need to create validation for that. But, you do not need to do that type of validation to prevent SQL Injection. As Mchl has already stated you need to use mysql_real_escape() for any user data that is included in a query. That function will make the appropriate "escapes" in the value to ensure it is safe for a query. So, you can allow any and all characters (as appropriate for the data) as input and still be secure.
  19. Most of that code is using the same math operators that PHP uses: plus (+), multiply (*), divide (/), and even the function for square root (sqrt()) is the same. The only exception, as marvelade pointed out, is "eff%". I'm thinking that that is either a special operator in cold fusion or it is simply a variable and CF support the percent sign in variables. So, just change the variables to PHP variables (and figure out the use of "eff%") and you should have something similar to this $itemPts = $basePrice * $quantity * $effPercent / 150; $drugPts = sqrt($drugVal) * 100 + $drugVal; $cashPts = sqrt($cash) * 50 + $cash; $ScorePotential = $itemPts + $drugPts + $cashPts + $NT/15 + $SC/15 + $PR * 1.5 + ($OffensiveTroops + $MaxOffense) * ($OffensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel) + ($DefensiveRating + $MaxDefense) * ($DefensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel) + $Hoes * ($HoIncomeBonus + 0.1) * (1-$HoDrugUseBonus) * 300 + $TotalGrown / 2 + $TotalSold / 2 + ($SoldiersKilled - $SoldiersLost) / 20 + ($drugsStolen -$drugsLost) / 500 + ($hoesStolen - $hoesLost) * 4 + ($cashStolen - $cashLost) / 1000; Personally I would create a variable for the following: $personality = ($OffensiveBonus + 0.1) * 2 * (4 + $streetcredlevel + $notorietylevel); (or some other description that is more appropriate) And then use that variable on lines 5 & 6 for the definition of $ScorePotential for readability of the code
  20. Yes. Are you wanting to dynamically create those text boxes or do the textboxes already exist but in a hidden state? Personally, I always prefer to create elements in a hidden state than to create them dynamically as you have done above. Whatever the case you can either define the process to create/display those checkboxes when defining that dynamic function sel.onclick = function() { //Insert code to create text boxes } Or you can create the function independently and then assign the onclick to that function function createBoxes() { //Insert code to create text boxes } sel.onclick = createBoxes;
  21. The OPTION elements don't appear to support the onclick trigger in IE. If this is a single select list, then you should use the onchange trigger on the SELECT element to get the selected value: <select name="sel" id="sel" onchange="alert(this.value);"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> If this is a multi-select list then it becomes more difficult because I'm not sure you can determine which exact option was clicked. If you use "selectedIndex" on the SELECT element it will give you the first selected elment even if you select another element. Plus, you have to consider that the user may be clicking on an element to unselect it.
  22. You say you've already done that, but the "whole code" you just posted shows the same process of defining functions inside of functions. Every time the function checkAccess() is called you are again redefining functions. If that function is called (or the first sub-function which is assigned to a click event) you are redefining functions dynamically. Not only that but the click function is iterrating through every input element on the page and redefining a function for each element. That is most likely the cause of your problem. I don't work with JQuery and I can't tell what the functinos actually do without the HTML content, but I know that the logic is not efficient.
  23. Well, without understanding the whole process it is a little difficult to provide a lot of feedback. but, I notice that the first block of code has functions nested two levels deep. If you are running that function at any time other than initial page load, that is where I would start. In most instances you should not need to redefine functions. You can just change the parameters used when calling a function to change the behavior.
  24. OK, so use THAT field for this number. Just start the auto-increment from the number you need to start at and, as I stated above, use PHP to format the number appropriately for display purposes. Maybe I am missing something, but it would seem that two auto-increment fields for a table are superfluous.
×
×
  • 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.