• Content count

  • Joined

  • Last visited

Everything posted by iwato

  1. Hi, Ingolme! I can see how use of the term form element can lead to confusion. On the one hand, it refers to the form tag <form>; on the other hand, it refers to any HTML element related directly to the creation of a form -- both non-control and control elements alike. Since the form attribute of the fieldset element is not recognized by any recent browser (see W3Schools), I will assume that it is a non-control form element only useful for decoration and the organization of form-control elements. To play it safe I will remove all of my non-essential <form> tags. Originally, all of my control-elements pointed to the same <form> tag, but each was grouped with other control elements in different <form> tags that did not contain a type='submit' control element.
  2. QUESTION ONE: When using the form attribute with a non-form element to redirect the contents of the non-form element to the form element, will confusion be created, if the non-form element is included in a form element different from the form element that contains the type='submit' input element? QUESTION TWO: Are fieldset elements an exception in this regard? Or, are they, too, treated as non-form elements.
  3. Dsonesuk: The form page is local. It is on my test server and likely not accessible to the average user.
  4. This is another strategy question. Multiple answers are welcome. What is written in present tense should be thought of as future, not yet realized activity. BACKGROUND: I have constructed a form whose intended purpose is to create chunks of data including text, links, and images that can be entered into a MySQL database for both immediate and future use. For the moment, I am only concerned about their immediate use. From the database these same chunks of data are retrieved and entered into an HTML template that serves as the backbone for an email insert that is, in fact, a weekly newsletter that can be viewed directly in one's mailbox or viewed on line should the insert fail. The mail insert is then distributed using PHPMailer that takes advantage of an assembled list of subscribers stored in the same database. Based on previous experience I believe that I am well able to handle this routine except for one hitch -- the treatment of the HTML data. MY DILEMMA: In the form are <textarea> elements that I intend to fill with a combination of plain text, HTML, and CSS styling attributes. That the HTML does not render as anything but the code itself is not a cause for concern on my part. Rather, I am bothered about how to send this data to the remote server. Now, I have been taught to filter and sanitize $_POST variable data as it is received and before processing. This time, however, I am sending the data to myself, and what will be generated and sent to my subscribers will also be generated by me. Do I even need to worry how about filtration and sanitation when I am both the source and the receiver of the data? Further, it is my understanding that MySQL is indifferent how the data is received, and that it will automatically return data in the same format that it is received. Am I making a big ado about nothing? By the way, it is not just a matter of filtration and sanitization. Take, for example, the following script used to process form data on the same page that it is entered. <form id="sevengates" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
  5. Ingolme: The end-users (the recipients of the email insert) should see the highlighted Q&A text -- not the HTML that creates it. Donesuk: I followed you until your last sentence, but believe that everything essential was already said. I believe to be on a clear track now, but will not know for sure until I have succeeded with the implementation. So, for now, thanks to you both! I will be back with a report of success or failure, but am momentarily engaged in another routine that I wish to consummate first.
  6. Ingolme: The HTML Template unless rendered is filled with HTML script: <h3>, <p>, <table>, &, etc. When I pass the information contained in the $_POST variable to this file why must it be altered? Should it not look just like all of the rest of the code in the file -- i.e., the same as it appears in the initial <textarea> element of the form from which it arose? This $html_message = str_replace('%something%', htmlspecialchars($something), $html_message); makes no sense to me in the context that I have provided. Indeed, whatever encoding need to be performed so that the email insert appears correctly in the subscribers email box appears to be performed by the PHPMailer's $mail->msgHTML($html_message); function. Does this not appear reasonable?
  7. QUESTION TWO: Because the data that reside in the $_POST variable are the same that reside in the <textarea> element, and the data that reside in the HTML template are all in unrendered HTML script when I pass the data from the $_POST variable to the HTML template no explicit modification of the code is needed on my part. True or False? Please be patient with my insistence, as I am truly confused.
  8. Ingolme: I understand the code that you have written, but I am having trouble with your English. Please allow me to help by passing your response through a series of true/false questions. QUESTION ONE: My assumption is that the data that I type into my form's <textarea> -- namely, <h3>Q&A</h3> will appear everywhere the same, just as you see it now. Everywhere in this interpretation refers to the contents of the the <textarea> form element, the $_POST variable, and the MySQL database tables I am assuming no explicit modification of the HTML script on my part. Is this statement true or false?
  9. Ingolme: I still do not understand. I will surely use code similar to the following to fetch my HTML template before attaching it to the mail that I will send to my subscribers. $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); At this point is the file still not an unrendered HTML file? The story with which I started this query has changed somewhat since I wrote it. My current, more reflected intention is to to do the following: When the completed form data arrives at the remote server from my local test server via the $_POST variable two things will happen: one, a large portion of the information will be placed into the HTML template before being sent out as an email insert to my subscribers; and two, the entirety of the data will be archived in various tables in my remote host server account's MySQL data base. My assumption is that the data that I type into my form's <textarea> -- namely, <h3>Q&A</h3> will appear everywhere the same, just as you see it now. Everywhere refers to the contents of the <textarea> element, the $_POST variable, the MySQL database tables, and the HTML template before it is sent. If this is true, why would any encoding or decoding of the HTML code be necessary?
  10. Thank you, Dsonesuk, for responding. It is good to know that I can avoid the normal security procedures. The second part of my question, however, is the need for encoding and decoding the HTML. Recall that my goal is to have appear in my HTML template exactly what I write in my <textarea> element. In other words, I want the recipient of the email insert to see Q&A, but in my template I wish to see exactly what I type into my <textarea> element -- namely, <h3>Q&A</h3>. The transmission path is 1) <textarea> on locally created form 2) $_POST variable sent to PHP file on remote server. 3) Insertion of the contents of the <textarea> into the HTML template via the PHP file on the remote server 4) SMTP transmission to subscribers mailbox with the modified HTML template included. In other words, at only one point do I want the code <h3>Q&A</h3> to appear as Q&A with <h3> element highlighting. QUESTION: Must I encode the HTML script as HTML entities before sending the $_POST variable and then decode the entities as HTML script after the transmission? If so, why? If not, I understand.
  11. Hi, Shan!  I am happy to have you aboard.  It is my hope that you can learn from my carefully formatted ignorance.

  12. Say, I enter the following line of code into a <textarea> element in the same manner that it appears below. <h3>Q&A</h3> is there any reason that I would have to encode it using the htmlspecialchars( ) method before sending it to the MySQL database. Recall that upon retrieval from the database, it will be inserted into an HTML page.
  13. SET-UP: When you open to the main page of my website two consecutive splash panels appear. The second of these leads you to a form with a reward for its completion. If the form is successfully completed, a confirmation page appears that congratulates you on successful completion of the form and invites you to return to the main page. Under normal conditions an if-statement whose condition is performance.navigation.type === 0 suppresses the splash panels from reoccurring when the main page is refreshed. When the main page is reopened from the confirmation page, however, this suppression technique fails. QUESTION: How would you recommend that I suppress the reoccurrence of the splash panels when the user seeks to access my site's main page using the link provided on the confirmation page? Mind you, I wish to retain the current suppression of the main page in the event that the users seeks to refresh the page! For example, is there a way that I could fool the browser into thinking that the main page is being refreshed when it is opened from the confirmation page?
  14. 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?
  15. 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(); } }); }
  16. 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.
  17. Is it like this? $( id + 'textarea') $( id + 'span.display_count'), and $( id + 'span.words_remaining')
  18. 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.
  19. 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
  20. 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
  21. 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' ), );
  22. <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?
  23. 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
  24. 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 />'; });