Jump to content
Larry Ullman's Book Forums

Wagtail

Members
  • Posts

    136
  • Joined

  • Last visited

  • Days Won

    1

Wagtail last won the day on October 25 2013

Wagtail had the most liked content!

Wagtail's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Ok, thanks Larry. I think I'll first have to understand Yii a bit more before trying to integrate it with jQuery Mobile. Cheers!
  2. Hi Larry and forum members, how are you all? I am learning the Yii framework and am wondering if it is possible to integrate Yii with jQuery Mobile? Do you think this can be done? Thank you for your time!
  3. HartleySan, thank you very much for getting back to me. I think I'll need to use a similar technique for the time being. I appreciate your help and hope you're well. Cheers.
  4. Hello forum members, here is a link to Stack Overflow which demonstrates how to use prepared statements with the IN operator: http://stackoverflow.com/questions/11938876/mysqli-prepared-statements-with-in-operator Could someone please have a look at the post (the first answer)? Would you recommended this technique or should I use something else? Thank you!
  5. Thanks HartleySan, I really appreciate you answering all of my questions. It's nice to get help from someone with your level of expertise. My "coding skills" are a lot better than what they were a year ago (at least I hope so), but there's still so much more to learn. I sometimes find it difficult to keep track of all of these functions and methods and classes etc etc.. Anyway, let me get on with it. Thanks again for helping me
  6. Hi HartleySan, thanks for replying. Thank you, I'll give that a try. Yes, but why is a request to the same page a bad thing? Should I always send an Ajax request to another PHP file? I'm wondering what to do about sessions times when a user has JavaScript disabled. Must I keep the script, for example, add_cart.php in my existing file and place a copy of it in an external file for the Ajax request? How can I ensure that both scripts are the same should I make a change in one? Different variable or database column names etc.. The external PHP file might not have access to all of the variables that have been defined in the existing file. Must I send all of this info with the Ajax request? Sorry for all of these questions. Thanks again.
  7. Hello forum members, I have a form which has a select menu, allowing users to update the quantities in their shopping cart, similar to the E-Commerce example in chapter 19. Now I'd like to add Ajax functionality to the page. I have tried the $.ajax() and .load() methods but haven't had any luck so far. Surely I can use these Ajax methods to post data to the same page, so that a page load isn't necessary? Any ideas will be more than welcome. Thank you.
  8. Cool, that seems to work. I didn't know about that method. Thank you for helping me.
  9. Thanks for all of the info. If I do an Ajax request to another PHP script, as in chapter 15, do you know how I should handle the header function? Instead of: if (response == 'CORRECT') { // Hide the form: $('#login').hide(); // Show a message: $('#results').removeClass('error'); $('#results').text('You are now logged in!'); } I would need to do: if (response == 'CORRECT') { header('location: /mysite/$name/$id'); exit (); } But clearly this won't work? I am a bit lost... Thank you for your help.
  10. Hi HartleySan, thanks for getting back to me. Looking at the console, the response I get back is the complete page and not a specific string such as "INVALID_EMAIL". When I do make a request to another PHP file, then a string is returned. The reason why I want to make a request to the same page is because once the form has been successfully filled out, I need to call the header function, which includes variables that aren't present in the external PHP file. Thank you for helping me. My setup looks like this: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" /> <script type="text/javascript" src="js/jquery-1.6.1.min.js" charset="utf-8"></script> </head> <body> <!-- Script 15.8 - login.php --> <?php if (isset($_GET['email'], $_GET['password'])) { // Need a valid email address: if (filter_var($_GET['email'], FILTER_VALIDATE_EMAIL)) { // Must match specific values: if ( ($_GET['email'] == 'email@example.com') && ($_GET['password'] == 'testpass') ) { // Set a cookie, if you want, or start a session. // Indicate success: echo 'CORRECT'; header('location: /mysite/$name/$id'); exit (); } else { // Mismatch! echo 'INCORRECT'; } } else { // Invalid email address! echo 'INVALID_EMAIL'; } } else { // Missing one of the two variables! echo 'INCOMPLETE'; } ?> <h1>Login</h1> <p id="results"></p> <form action="login.php" method="post" id="login"> <p id="emailP">Email Address: <input type="text" name="email" id="email" /><span class="errorMessage" id="emailError">Please enter your email address!</span></p> <p id="passwordP">Password: <input type="password" name="password" id="password" /><span class="errorMessage" id="passwordError">Please enter your password!</span></p> <p><input type="submit" name="submit" value="Login!" /></p> </form> <script> $(function() { var url = window.location.pathname; // Hide all error messages: $('.errorMessage').hide(); // Assign an event handler to the form: $('#login').submit(function() { // Initialize some variables: var email, password; // Validate the email address: if ($('#email').val().length >= 6) { // Get the email address: email = $('#email').val(); // Clear an error, if one existed: $('#emailP').removeClass('error'); // Hide the error message, if it was visible: $('#emailError').hide(); } else { // Invalid email address! // Add an error class: $('#emailP').addClass('error'); // Show the error message: $('#emailError').show(); } // Validate the password: if ($('#password').val().length > 0) { password = $('#password').val(); $('#passwordP').removeClass('error'); $('#passwordError').hide(); } else { $('#passwordP').addClass('error'); $('#passwordError').show(); } // If appropriate, perform the Ajax request: if (email && password) { // Create an object for the form data: var data = new Object(); data.email = email; data.password = password; // Create an object of Ajax options: var options = new Object(); // Establish each setting: options.data = data; options.dataType = 'text'; options.type = 'get'; options.success = function(response) { // Worked: if (response == 'CORRECT') { // Hide the form: $('#login').hide(); // Show a message: $('#results').removeClass('error'); $('#results').text('You are now logged in!'); } else if (response == 'INCORRECT') { $('#results').text('The submitted credentials do not match those on file!'); $('#results').addClass('error'); } else if (response == 'INCOMPLETE') { $('#results').text('Please provide an email address and a password!'); $('#results').addClass('error'); } else if (response == 'INVALID_EMAIL') { $('#results').text('Please provide your email address!'); $('#results').addClass('error'); } }; // End of success. options.url = url; // Perform the request: $.ajax(options); } // End of email && password IF. // Return false to prevent an actual form submission: return false; }); // End of form submission. }); // End of document ready. </script> </body> </html>
  11. Hello forum members, I am using Ajax with one of my forms after having gone through chapter 15: Introducing jQuery. Script 15.10 - login.js makes a request to a PHP file - login_ajax.php. The Ajax options include this line: options.url = 'login_ajax.php'; Instead of making a request to another PHP file, I need to make a request to the same PHP page, which includes the login_ajax.php script. I'm using URL rewriting and so the options.url line looks like: options.url = '/mysite/somedirectory/blah'; Is this correct? I've kept the other Ajax options as they are, for example, options.type = 'get'; So far this isn't working - I don't get any response when the submit button is clicked. What might the problem be? Please let me know if you require more info. Thank you for any help.
  12. Hi HartleySan, Thank you for your quick response, it appears to be working now. I must say that creating and using functions does trip me up sometimes, I guess I need to practise a lot. Anyway, thanks again and I hope you're having a good week. Cheers.
  13. Hi Larry and HartleySan, would one of you know how I can make a variable available outside of the make_text_input function? For example, how would I be able to access the $filtered array outside of the function? The function should validate every text input and then assign said variable to the $filtered array. Then I can do something like this outside of the make_text_input function: if (!empty($filtered['first-name']) && !empty($filtered['last-name'])) { // create email body and send email } Thank you in advance. function make_text_input($name, $label, $errormsg) { if (isset($_POST[$label])) { $filtered = array(); $errors = array(); $filtered[$label] = filter_var($_POST[$label], FILTER_SANITIZE_STRING); if (!$filtered[$label]) { $errors[$label] = $errormsg; } } }
  14. Hello everyone, this is a quick question about the PHP include() function. Is it possible to pull in specific sections of an include file? Such as: include ("inc/menu.php #div1"); The following code snippets are both in the same include file but they need to be called separately. Should I wrap these in functions? The table can probably be assigned to a variable. # Script 10.5 - #5 // Determine the sort... // Default is by registration date. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd'; // Determine the sorting order: switch ($sort) { case 'ln': $order_by = 'last_name ASC'; break; case 'fn': $order_by = 'first_name ASC'; break; case 'rd': $order_by = 'registration_date ASC'; break; default: $order_by = 'registration_date ASC'; $sort = 'rd'; break; } echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users.php?sort=fn">First Name</a></b></td> <td align="left"><b><a href="view_users.php?sort=rd">Date Registered</a></b></td> </tr> '; Thanks in advance!
×
×
  • Create New...