Jump to content

iwato

Members
  • Posts

    1,506
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by iwato

  1. Is it not this MySQL clause that insures that the records in the two databases match? ON w.`id` = `c`.`id` For, if the id's properly matched there would be no duplication in the joined result, unless, of course, there were duplication in both databases.
  2. Is it like this? $( id + 'textarea') $( id + 'span.display_count'), and $( id + 'span.words_remaining')
  3. Please consider the following function and explain how to format the selectors for the highlighted jQuery objects. Please explain why you recommend what you do so that I need not ask the same question again further down the line. The names of the Javascript variables in question are, of course id and max. An iteration over the property-value pairs of a nested JSON object yields the following two pairs of property-value pairs for a single object: id : #letter_abstract and length : 150.. All other objects that are traversed by the iteration share the same property names -- only the values are different. The values of these two property-value pairs will be read into the function as id and max, respectively -- in effect, id = id and max = length Now, the jQuery objects in question are: $ (id textarea) -- where id is a Javascript variable corresponding to the value of the id attribute of an HTML div element, and textarea is the generic name of an HTML element. $(id span.display_count) -- where id is a Javascript variable corresponding to the value of the id attribute of the same HTML div element, and span.display_count is a generic HTML span element whose class attribute has the value of "display_count". $(id span.words_remaining) -- Same as above. Only the value of the class attribute is different. QUESTION: "How does one format the selectors properly?" function setWordContraint(id, max) { $(id textarea).on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= max) { $(id span.display_count).text(words); $(id span.words_remaining).text(max-words); }else{ if (e.which !== 8) e.preventDefault(); } }); }
  4. QUESTION: How did I finally resolve the problem? ANSWER: I abandoned the idea of creating a Javascript array, learned a little more jQuery, and opted for the jQuery $.each( ) method that iterates over array-objects and objects with seeming indifference. Note: $wordmax is a nested, associative PHP array var wordmax = '<?php echo json_encode($wordmax)?>;'; var wordmax_json = JSON.parse(wordmax); $.each(wordmax_json, function(property, textobj) { $.each(textobj, function(name, val) { alert(name + ': ' + val); }); }); As always, thank you for your many suggestions and leads, Ingolme.
  5. Yes, I am of the same mind. My problem is that I have no experience working with objects in Javascript -- even though everything in the end is an object anyway. I recently found the following routine on the net and am going to try it. It appears to be written for two layers and thus suits my purpose well. The fact there is no easily found routine for recursive cloning of nested objects to nested arrays, also suggests that there is little need. And, it makes me feel a little stupid about my knowledge of nested objects and how to work with them in Javascript. for (var i in data) { var item = data[i]; var outer = []; if (typeof item === "object") { for (var j in item) { var temp = []; temp.push(j); temp.push(item[j]); outer.push(temp); } } if (outer.length) { chartData.push(outer); } } Roddy
  6. Ingolme: You were correct in your observation that I was confusing PHP with Javascript. Only after I made my posting did I realize this and attempt to correct for it. Please see my newly created post in the Javascript forum. Dsonesuk: I understand what you are saying and will likely do as you suggest, but only if I am unable to easily convert a nested JS object into a nested JS array, or alternatively, simply use the nested object, as if it were a nested array. I am unfamiliar with the use of Javascript objects, and only today did I truly discover JSON encoding and decoding. I am trying to avoid still another entirely new block of code learning and work only with what I already know. There will be time later for further refinement and code upgrade. As always, thank you for kind and generous guidance. You are both so very helpful. Roddy
  7. I recently used PHP's json_encode( ) function to covert an array created with PHP into a JSON encoded object, as the conversion appeared normal, I then assigned the value to a Javascript variable using PHP's echo construct and reproduced it with a JS alert. This too, appeared normal. My difficulty arose when I tried using the jQuery .map( ) method to convert my nested Javascript object into a nested Javascript array. I received the following error message in my Console: TypeError: e is not an Object. (evaluating 't-1 in e') Am I being foolish to believe that I need a nested array when I already have a nested object? If not, is there not a routine to perform this very conversion?
  8. <script> foreach($wordmax as $textarea => $arr) { $area_div = $arr['id']; $max = $arr['length']; $($area_div textarea).on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= $max) { $('.display_count').text(words); $('.words_remaining').text($max-words); }else{ if (e.which !== 8) e.preventDefault(); } }); } </script> <div id='letter_abstract'> <textarea name='letter_abstract' placeholder="Enter this week's abstract here!"></textarea><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> </div><!-- end div#letter_abstract --> <div id='letter_body'> <textarea name='letter_body' placeholder="Enter this week's content here!"><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> </div><!-- end div#letter_body --> One question, though: Are the selectors of the jQuery objects properly specified?
  9. After the above careful consideration I believe that I am in error, for there is nothing that binds the individual span tags to their respective <textarea> element. OK, so what if I were to include both <textarea> element and its respective <span> elements in the same <div> element, select the uniquely defined <div> element by its id='' attribute, and designate everything else by its more general HTML tag identity -- namely, <textarea> and <span>? Roddy
  10. Please consider the following code and answer the question. Please do not omit your reasons for answering as you did. CODE SYNOPSIS: This handy piece of code places a constraint on the number of words that can be placed in a selected <textarea> element. In addition, it displays the current status of the selected element as one enters text. This code, less the iterative aspect, has been tested for one <textarea> element, but I wish now to expand it to include many <textarea> elements. In order to do this I created a mixed associative array (see below) whose data I use to select each <textarea> element and apply a different constraint. Although I have identified each <textarea> element by its unique id='' attribute I have used the class='' attribute to display the current status of the selected <textarea> element. My motivation for doing this latter is, of course, one of efficiency. My belief is that specific overrides general, and that the values generated by the id='' attribute will override those designated by the class='' attribute -- a designation that is common to all <textarea> elements. QUESTION: Is this sound Javascript programming logic? Or, must I change the class='' attributes to the same id='' attribute for each <textarea> element? <?php foreach($wordmax as $textarea => $arr) { $area_id = $arr['id']; $max = $arr['length']; $($area_id).on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= $max) { $('.display_count').text(words); $('.words_remaining').text($max-words); }else{ if (e.which !== 8) e.preventDefault(); } }); } ?> <textarea id='letter_body' name='letter_body'>...</textarea><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> <textarea id='letter_abstract' name='letter_abstract'>...</textarea><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> $wordmax = array( 'letter_abstract' => array ( 'id' => '#letter_abstract', 'length' => '150' ), 'letter_body' => array ( 'id' => '#letter_body', 'length' => '800' ), . . . 'student_bio' => array ( 'id' => '#student_bio', 'length' => '400' ), );
  11. Yes, it works, even without the if-statement. What I have learned from this exercise is that the $GLOBALS variable and the global keyword are not equivalent alternatives to achieving the same outcome. Many thanks! And, still again. Roddy
  12. <input type="text" class="form-control" id="linked" name="txtfullname" placeholder="Last name" required data-validation-required-message="Please enter your Last name."> The highlighted word should be the value used for the name of your $_POST variable, not linked, for it is this variable -- namely, txtfullname -- that carries the text of your <input> element's textfield to the $_POST variable when you submit the form.
  13. Ingolme: Alright, I am unable to restructure the input array of an array_walk_recursive function. However, I know with certainty that I am able to echo the keys just as I would like them to appear as the values of an indexed array. So, why can I not convert this ability into the desired array? My logic being, if you can display it, you should be able to store it. By the way declaring $varnames as a global variable either inside the callback function or outside of the array_walk_recursive( ) function in a callback function that is read into the array_walk_recursive( ) function fails.
  14. OK, you guys (Ingolme and Dsonesuk) pay attention! Firstly and once again, the array called $insertion_vars is a nested associative array whose keys are well identified, but whose non-recursive endpoints (read values) are all empty. Secondly, I wish to produce an indexed array whose values contain the keys of the key-value paris whose endpoints (read values) are empty. Ingolme's suggestion changes the endpoint values from zero to 'changed_', it neither restructures the array, nor does it return the keys as values. See code below: Array ( [subscriber] => changed_ [time] => changed_ [date] => changed_ [letter] => Array ( [letter_no] => changed_ [letter_title] => changed_ [letter_abstract] => changed_ [letter_body] => changed_ [letter_link] => changed_ [Letter_links] => Array ( [link_one] => changed_ [link_two] => changed_ [link_three] => changed_ [link_four] => changed_ [link_five] => changed_ ) ) [student] => Array ( [student_name] => changed_ [student_bio] => changed_ [student_img] => changed_ ) [qa] => Array ( [question] => changed_ [answer] => changed_ ) [podcast] => Array ( [podcast_no] => changed_ [podcast_title] => changed_ [podcast_abstract] => changed_ [podcast_itunes] => changed_ ) [nextletter] => Array ( [nextletter_no] => changed_ [nextletter_title] => changed_ [nextletter_abstract] => changed_ ) [webmaster_updates] => Array ( [new_features] => changed_ [security] => changed_ [upcoming_innovation] => changed_ ) [miscellany] => Array ( [miscellany_one] => changed_ [miscellany_two] => changed_ [miscellany_three] => changed_ ) ) Dsonesuk's suggestion, if I have understood it correctly, was already tried and leads to an empty array no different than the one defined outside of the function. Please see the code below: $varnames = array(); $result = array_walk_recursive($insertion_vars, function($value, &$key) { $varnames[] = $key; }); print_r($varnames); // Array()
  15. BACKGROUND: The following routine takes a nested, associative array whose end-values are empty, extracts the keys of each non-recursive subarray, and properly echoes each. Rather, than returning the result as a newly constituted array, however, the function returns boolean true and displays the desired result in a non-useable form. Now, I have tried in vain to get the call-back function to produce an index-array of the echoed values that I can use outside the scope of the array_walk_recursive( ) function, but have failed miserably. QUESTION: How does one produce from the function a useable array that can be used outside of the function. $result = array_walk_recursive($insertion_vars, function($key, $value) { echo $value . '<br />'; });
  16. This was a timely inquiry. Throttling is a concept that I should seriously consider. Thanks!
  17. Hi, Ingolme! So, may I then assume that PHP has completed its tasks even before the $.ready( ) function has been triggered? If so, this would suggest strongly that the entire routine should be run with PHP. Do you know of a well-written online tutorial that I can read (not watch), and that would teach me how to program the behavior of <select>, <option>, and <input> elements using PHP? Showing you my actual code would probably be confusing. It is even confusing to me, and I am the one who wrote it! In brief, I have a series of data checks that generate error messages and a <select> element that generates an <input> element with a text field when a certain <option> element is selected. The data checks and error messages are generated in PHP, and the creation of the <input> element is achieved using jQuery. If you would like to see the confusion in operation, you are welcome. Go to http://www.grammarcaptive.com/_gates/gate7/gate7d.php and click the SEND button without having filled in any data. Do this for each form element one at a time and watch what happens. The troubled area is language selection, and its integration with the error statements of the other form elements. Do not be concerned with filling in my database table with useless information, as I will clean it once everything is in working order. Nothing will be sent until all of the information has been filled in, anyway. If you want to view the page in its proper context, then open to http//www.grammarcaptive.com/overview.html and follow the splash screen to the end of the final gate. The backward arrows in the bottom of the splash panels will get you to the desired location more quickly than the forward arrows. Roddy
  18. QUESTION: How does one manipulate jQuery in a $( document ).ready( function( ) {...}); with PHP? Is it even possible? BACKGROUND: I have created a form whose performance depends on a combination of both PHP and jQuery. Unfortunately, I cannot get the two sets of code to synchronize properly. A seasoned programmer would probably tell me to start over and use one or the other, but not both. Unfortunately, there are things that I know how to do in Javascript, but not in PHP, and vice versa. It is because of this that I have gotten myself into this mess.
  19. iwato

    The header( ) Function

    I would like to thank everyone for your patience, encouragement, and most of all your insight. The failure of the confirmation page to appear has been resolved. Apparently there were two complications that had been resolved separately, but not together: one, placing the PHPMailer code ahead of all HTML code, and two, setting the STMPDebug property value to 0. Doing both of these together appears to have resolved the problem. Hooray, hooray, hooray! Roddy
  20. iwato

    The header( ) Function

    Please read carefully. Long ago I tried putting the PHP first, but there was no change. The header( ) function failed. Maybe it is because I am using the PHPMailer Autoloader. It spews out the entire correspondence with the SMTP server, as well as error messages that surely must surely be generated by PHP echo statements. Then too, the statements are unformatted, so there is likely no HTML contained within. Roddy
  21. iwato

    The header( ) Function

    Firstly, already long ago I tried moving the last, above, displayed section of PHP to the top of the page, but it had no effect. Secondly, there is PHP contained in the body of the page. <form id="subscribe" method="post" name="subscribe" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"> <input type="text" name="name" id="name" value='<?php echo $name;?>'> <input type="checkbox" value="1" id="checkbox1" name="newsletter" <?php if(isset($_POST['newsletter'])) echo 'checked'; ?> /> <?php echo '<p><span style="font-size:0.7em; color:#f00;">' . $error_msg . '</span></p>';?> etc. I fear that I must do what I was loathe to do at the beginning and believed that this dialogue would inevitably lead me -- separate the email processing page from the form page. Am I correct?
  22. iwato

    The header( ) Function

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Gate Seven - An Invitation and Gift</title> <meta name="generator" content="BBEdit 11.6" /> <link rel="stylesheet" href="../../_utilities/css/gc_splash.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $( document ).ready(function() { console.log( "ready!" ); var tongue = 'other_tongue'; $('#other').hide(); $('#tongue').change(function() { if ($('#tongue').val() == tongue) { $('#other').show(); } if ($('#tongue').val() != tongue) { $('#other').hide(); } }); }); </script> </head> <body> This is the HTML that appears before the <?php tag. I see no effect on the headers. All non-essential blank spaces were stripped away. Actually, there were none. Only tabs and line breaks remain.
  23. iwato

    The header( ) Function

    This is how the email is sent. I have eliminated all comments and non-essential code. Sensitive information has been replaced with placeholders. In addition, I have added row spaces to departmentalize the code into specific tasks for easier digestion. No rearrangement of code that I have made achieves the desired affect -- namely, the loading of the confirmation page (gate_confirmation.html). The sending of the verification email (confirmation_mail.php) works fine! The desired affect, by the way, can be viewed by going to the last (5th) frame of the last gate (7th) in the second splash panel at www.grammarcaptive.com/overview. The quickest way to get there is by using the back arrows built-into the splash panels. If you know the way, you can arrive in seconds. Please enter a phony email address, if you do not wish to be entered into my database. The only check for validity is format. Also, if you wish to repeat the procedure, you can get the splash panel to reopen by clicking on my stylized image on the main page.. require_once '../../_utilities/php/php_mailer/PHPMailerAutoload.php'; $name = $email = $newsletter = $webinar = $language = $error_msg = '' ; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST['language'])) { $error_msg = "Please select your first language."; } else if ($_POST['language'] == 'other_tongue') { if (empty($_POST['other'])) { $error_msg = "Please enter your first language."; } else { $language = filter_var($_POST["other"], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); } } else { $language = filter_var($_POST["language"], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); } if (!($_POST["newsletter"]) && !($_POST["webinar"])) { $error_msg = "Have you forgotten to select a gift?"; } else { $newsletter = filter_var($_POST["newsletter"], FILTER_SANITIZE_NUMBER_INT, FILTER_VALIDATE_INT); $newsletter = !empty($newsletter) ? "$newsletter" : 0; $webinar = filter_var($_POST["webinar"], FILTER_SANITIZE_NUMBER_INT, FILTER_VALIDATE_INT); $webinar = !empty($webinar) ? "$webinar" : 0; } if (empty($_POST["email"])) { $error_msg = "Please enter your email address."; } else if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_EMAIL)) { $error_msg = "Invalid email format. Please try again!"; } else { $email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_EMAIL); } if (empty($_POST['name'])) { $error_msg = "Please enter a name with which you would like to be greeted."; } else { $name = filter_var($_POST["name"], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); } if ((!empty($name) && !empty($language) && !empty($email) && (isset($_POST["newsletter"]) || isset($_POST["webinar"])))) { $hostname = "localhost"; $user = "..."; $pwd = "..."; $db = "..."; $mysqli_obj = mysqli_connect($hostname, $user, $pwd, $db); $mysqli_obj->set_charset("utf8"); function random_password() { $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!$%&!$%&!$%&!$%&!$%&!$%&'; $pass = array(); $alphaLength = strlen($alphabet) - 1; for ($i = 0; $i < 8; $i++) { $n = rand(0, $alphaLength); $pass[] = $alphabet[$n]; } return implode($pass); } $password = random_password(); $hash = password_hash($password, PASSWORD_DEFAULT); $active = 0; $tbl_name = '---.---'; $sql_1 = "INSERT INTO " . $tbl_name . " (user_name, language, email_address, hash, active, newsletter, webinar) VALUES ('" . $name . "','" . $language . "','" . $email . "','" . $hash . "','" . $hash . "','" . $newsletter . "','" . $webinar . "')"; $mysqli_obj->query($sql_1); $mail = new PHPMailer; $mail->CharSet = 'UTF-8'; $mail->isSMTP(); $mail->SMTPDebug = 0; $mail->Debugoutput = 'html'; $mail->Host = "---.---.com"; $mail->Port = ...; $mail->SMTPAuth = true; $mail->Username = "---@---.---"; $mail->Password = "..."; $mail->setFrom('---@---.com', 'Grammar Captive'); $mail->addReplyTo('---@---.com', 'Grammar Captive Administration'); $mail->addAddress($email, $name); $mail->Subject = 'Account Verification'; $html_message = file_get_contents('../../confirmation_mail.php'); $html_message = str_replace('%username%', $name, $html_message); $html_message = str_replace('%email%', $email, $html_message); $html_message = str_replace('%hash%', $hash, $html_message); $mail->msgHTML($html_message); $alt_message = 'Congratulations, ' . $name . '! You have successfully created a Grammar Captive account./n/r Please click on the link below to verify that you are the owner of the account and to receive the first edition of Seven Gates, the Grammar Captive weekly newsletter./n/r http://www.grammarcaptive.com/email_verify.php?name=' . $name . '&email=' . $email . '&hash=' . $hash; $mail->AltBody = $alt_message; if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { header('Location: ../../gate_confirmation.html'); } } } I suppose that the best way for you to help me at this time is to regroup the above code in the matter that you believe will work. Then, I can test and compare it with Ingolme's explanation and grasp the entire concept in a flash. Roddy
  24. iwato

    The header( ) Function

    This is how the email is sent. if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { // echo "Message sent!"; header('Location: ../../gate_confirmation.html'); }
×
×
  • Create New...