Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. The theory is simple. The important attribute in the form is target. Here's pretty much how it works, though there may be better done scripts than this, I just made this one up on the spot. HTML: <iframe name="fileupload" id="fileupload"></iframe><form id="fileform" method="post" enctype="multipart/form-data" action="upload.php" target="fileupload"><div><input type="file" name="file"></div></form><form... id="mainform"> <!-- Other form --></form> Javascript: var form = document.getElementById("mainform");var frame = document.getElementById("frame");var fileform = document.getElementById("fileform");frame.onload = checkFile;form.onsubmit = doStuff;function doStuff(e) { e = e || window.event; // Upload the file first, when it's uploaded, manage the rest of the data fileform.submit(); if(e.preventDefault) e.preventDefault(); return false;}function checkFile() { var data = frame.contentDocument.body || frame.contentWindow.document.body; if(data == "OK") { // Manage the rest of the form data with ordinary AJAX requests here } else { console.log("Unable to upload file"); }} PHP (upload.php): <?php // Do ordinary file upload stuff here. $success = false; if(!$_FILES['file']['error']) { $success = move_uploaded_file( ... ); } if($success) { echo 'OK'; }?>
  2. The explanation is here in detail: http://en.wikipedia.org/wiki/Floating_point#Representable_numbers.2C_conversion_and_rounding You can't represent 0.1 as a sum of 2^N where N is a positive or negative whole number, so the computer tries to approximate. Often the rounding error is only noticeable after adding to another number that had a rounding error in the same direction.
  3. jQuery is Javascript so setInterval would work just fine with it.
  4. Yes, that's exactly what's happening. Use <button type="button"> to tell it that it's not meant to submit the form.
  5. Generally a request is sent every 3 or 5 seconds using setInterval() Don't send requests too frequently or you'll waste a lot of bandwidth and possibly slow down the browser.
  6. Hidden iframe is the safest approach. As an effort to push browsers to support HTML 5 I'd only use the iframe as a fallback method for if the HTML 5 API isn't available. The reason you need an iframe for files and not for any other kind of input is because all the other inputs can have their values read by Javascript without a problem. Javascript can't read file content.
  7. If the internet connection is slow, the browser will first set up a blank page and then start filling it with content as data arrives from the server. I'm not sure if modern browsers still do that, I think they wait for the content to arrive before rendering. There's no solution.
  8. Spanish keyboards have four keys right next to the "Enter" key with diacritics. Press the diacritic and whichever letter you press after that will have the diacritic on it. If the letter isn't meant to have a diacritic then the diacritic will be put on its own followed by the letter. I don't know about other countries, I'm Spanish.
  9. Where in $category_data[] do you want the subcategories? Is it a property of category_data? To start off, initialize all your arrays before filling them up: $category_data = array(); You can avoid a lot of the extra loops like this: $category_data = array();while ($row = mysql_fetch_object($category_query)) { $category_data[] = array( "category id" => $row->category_id, "category name" => $row->category; ); // // Do the subcategory things here //}
  10. If you're doing multiple string manipulations, it's probably best to use the same variable for it. Each variable is a pointer to a different space in memory, if you used different variables you'd have pieces of memory with half-processed strings that would remain there until the garbage collector came around. I wouldn't recommend using the same variable name in two separate parts of the program because you might accidentally overwrite a value you needed.
  11. < and > need to be escaped all the time because that has to do with the HTML parser and not the encoding.
  12. If you save as UTF-8, you don't need to do anything with special characters. If you use one of the single-byte encodings, then any character that's outside of that encoding needs to be converted to an entity. Single-byte encodings are ISO-8859-1, Windows-1252 and many others. Personally, I just use UTF-8 for everything. Yes, foreign programmers do need to learn english, or just memorize keywords and function names.
  13. AJAX support isn't related to the server, it's related to the client. All servers "support" AJAX, and as of today, so do all browsers. AJAX is the only solution to your problem.
  14. It says you have to buy it from them for $8. There's no simple code for that. It would take weeks of programming to set up a system like that one.
  15. Up to now, what I understood as a "banner" is an image file. What is the Javascript supposed to do?
  16. Ingolme

    sanitize filters

    The filters are being set up, but they haven't been used on the $_POST array yet. There's more code that you omitted. The following line is this: $revised_post_array = filter_var_array($_POST, $postfilter); // must be referenced via a variable which is now an array that takes the place of $_POST[]
  17. It seems you still need to learn more about arrays and the foreach loop. This line of your code creates one element in the $serviceslist array called "services" $serviceslist['services']=$services->servicename; The foreach loop in your code assigns the value of $serviceslist['services'] to the variable $value, so $value is a string and $serveiceslist only has one element. Birbal's code will work but your array needs to be structured as follows: $serviceslist[0] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[1] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[2] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[3] = array( 'price' => 'X', 'name' => 'Y'); A shorthand way to add new elements onto the end of an array without having to know what numeric index to use is the following: $a[] = "value"; Given that knowledge, the previous code can be written as: $serviceslist = array();$serviceslist[] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[] = array( 'price' => 'X', 'name' => 'Y');$serviceslist[] = array( 'price' => 'X', 'name' => 'Y'); It doesn't seem extremely useful at the moment, but it's exceptionally useful when getting values from a loop, for example databases. $serviceslist = array();while ($row = mysqli_fetch_assoc()) { $serviceslist[] = array( 'price' => $row['price'], 'name' => $row['name'] )}
  18. By putting the whole script on one line the comments have removed a lot of the code.
  19. The file to be downloaded is larger. As for empty tags, the reason I don't close them is because the validator interprets it as the old SGML shorttag syntax.
  20. That means $value is a string. You weren't meant to just copy the code he gave you, he said to restructure your arrays.
  21. The <!DOCTYPE> declaration indicates it's an HTML 5 document. Despite being valid to leave unclosed <p> elements, I recommend closing them all anyways. HTML 5 is allowed to be serialized as XML, that's when you would use the xmlns attribute. If you're not intending the document to be read by XML parsers, I would advise against closing empty elements with />. Empty elements are <br>, <img>, <link> and others like that.
  22. The problem is that the links are going to send the user back to the original site, unless you convert all the links into links to a PHP page that loads the HTML content as well. Overall it's really complicated and iframes are there for a reason. Though I can't think of a reason you would want to show another website inside yours.
  23. Ingolme

    sanitize filters

    $_POST is an array and it's being manipulated here: array_filter($_POST, 'trim_value'); I assume trim_value is a function that removes whitespace from the left and right of all the strings that the array contains.
  24. You can load the HTML of another page with PHP, but it's likely that a whole lot of links and stylesheets will be broken. Iframe is pretty much the only way.
  25. The width and height attributes of the <canvas> element are there to determine the size of the drawing area. The CSS will distort the canvas in the same way it would distort an <img> element, try setting the width to 400px with CSS while keeping the width attribute at 200 just to see what happens. You can put the attributes on the <canvas> element or set them with Javascript: var c=document.getElementById("myCanvas");c.width = 200;c.height = 200;
×
×
  • Create New...