Homework 9 (Remember the Cow) FAQ

Q: What if the user submits a really long string into the to-do list? Should I truncate it or limit its width?
A: You don't have to worry about this.
Q: When I add an item, it appears for a split second but then the list becomes empty again. Why?
A: This might be happening if you are wrapping your buttons in a form since it will be treating those buttons as potential submit buttons in Firefox. Don't use a form.
Q: Is it possible to make it so that the user can just press Enter to add their item, rather than needing to click the Add button?
A: You can optionally add a key event listener to the text box, if you like, to detect Enter keypresses. See the book Chapter 11 on key events for an example of this.
Q: Does the order we save our list in matter? If the user changes the order, then refreshes the page should the server reflect those changes, or revert back to the pre sorted order?
A: Yes it does matter, and yes the server should save it in the rearranged order.
Q: The writeup says we should reject empty strings as to-do items. Should our todolist.php accept strings consisting of just spaces to add to the list? It's technically not an 'empty string' but HTML doesn't display whitespace very well.
A: We won't test this case, so you can do what you want. If you want to reject a spaces-only string, go ahead, but you are not required to do so. But otherwise accept any string given to you by the user.
Q: Why doesn't my Sortable work? Why can't I drag all of the items in the list? Why doesn't the onUpdate event occur?
A: You usually need to set particular ids on your li elements as described in the book/slides. Something like "item_1", "item_2", etc. for each item. You can do this in your JavaScript code.
Q: I'm getting an odd result when I try to make my list sortable. Everything but the last item can be moved around. Any suggestions on what to check?
A: Note that if you make a list Sortable, and then change the list through the DOM (adding an item, etc.), the newly added items won't be movable/draggable/sortable, unless you re-Sortable-ize the list again.
Q: I'm grabbing all the elements that have an li tag and then fading the first one and then deleting it with after that effect finishes with element.remove... Firebug is giving me this error: element.parentNode is undefined it works (fades and deletes) but I always get this error and I have no idea why or how to fix it.
A: some effects (e.g. Shrink) are technically "parallel effects", so to access the modified element, you write effect.effects[0].element rather than just effect.element .
Q: My Ajax requests aren't working. When I debug them in Firebug's Net tab, I see "OPTIONS" and an XML processing error. Why?
A: This happens when you're requesting an HTTPS URL from a regular HTTP site or vice versa. It's probably that you put a complete URL such as "http://webster..." in your code rather than just a relative path. Or change your URL in your code to say "https" rather than "http" or vice versa.
Q: When I send my Ajax.Request to the PHP web service, the data doesn't arrive or get saved properly. But I can see that it is sending the data in Firebug.
A: You may not be using the right choice between GET and POST.
Q: If the file todo.json doesn't exist, are we supposed to create it?
A: According to the PHP web site, file_put_contents() will create a file if it's not already there.
Q: When i tried to use file_put_contents, the permission is denied even though I have set the permission in the webster to be ok to write, so how could i get the permission to write in the file.
A: Did you say okay to write to the file, or the homework folder itself? Because there's a definite difference and I've had a problem with that before. Make sure you have checked the boxes for the Write permissions on the file, and if that doesn't work, make sure that your directory for the assignment (hw8) has write and execute permissions turned on. Execute permission on a directory allows someone to enter that directory and view its contents. If you are getting "permission denied" messages, try changing the read/write permissions on your hw8 folder in Webster.
Q: When I want to indicate an error, do I want my php code to kill the program (die), or do I want to return the error code to my Ajax request and do something with it in an onSuccess method?
A: Use the header function to return an error code to the page. It should show up with a red error code in Firebug.
Q: My redirect doesn't work. Why not?
A: Any calls to PHP's header function must come before you produce any output from your file. If you output any HTML and then try to set a header, PHP will complain. So do any code/logic involving headers first. Keep in mind that even just having whitespace from being in non-HTML mode, or an HTML comment at the top of your file, or including a file full of HTML, will count as "output".
Q: How do I remember whether the user is logged in? How do I log the user out?
A: Store information as a PHP session. You should decide what info should be saved in the session, but save enough to know that the user logged in successfully. When they log out, destroy the session to 'forget' the data that you saved.
Q: I wrote the PHP code to create a session and remember some session data, but then the next page can't find the data. What is wrong?
A: You have to call session_start at the start of every page that uses sessions. The session_start function doesn't create a new empty session every time you call it. It just initializes PHP's session management system and creates/fills in the $_SESSION array for you.
Q: My "log out" code doesn't work. I followed the examples from the book/slides, but I can't get it to "forget" the user.
A: One weird thing about sessions is that you have to call session_start to initialize PHP's session system before you can call session_destroy.
Valid HTML5 Valid CSS JavaScript Lint
This document and its content are copyright © Marty Stepp, 2012. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.