Jump to content

4xjbh

Members
  • Posts

    18
  • Joined

  • Last visited

4xjbh's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was wondering if I use model dialogs for forms, confirmation and alerts should I be using one div and use jquery to set the parameters or should I have a div for each input form (catalogue, companies etc), a confirmation div, alert div, etc. What would be the best way to load in html files dynamically into one div (one file at a time) if I go that way. Options, options, options. What lessons have you learnt regarding this or am I over complicating this? James.
  2. OK, I removed my JS from the php file and put it in a twig block in the catalogues template which extends the main layout single.html and it works fine now. Thank you very much jazzman.
  3. Thank you for your time but I fail to see what the problem actually is. The js library code only exists in one location and occurs one in the html. Changing it to be loaded from the code library has no change. Attached is a view-source copy and paste instead of a save as from the browser which changes the headers etc. Where have I missed your point, thanks.
  4. I select the label '#notes_sh' to show/hide the text area '#fld_notes. http://youtu.be/6olI1MdnJlc catalogues.php <script src="javascript/jquery-1.10.2.min.js"> </script> <script> $(document).ready(function(){ // ---------------------------------------------------------------------------------------------------------------------------------- // Things to do after page loads var search_watermark = 'Search here'; $('#search').val(search_watermark).addClass('watermark'); // Add the search water mark to the search field. $("#fld_notes").hide(); // Hide the notes text area. // ---------------------------------------------------------------------------------------------------------------------------------- $('#new').click( function() { // $(".message").hide(); $('.message').text("New Catalogue"); $('#category_id').val("Please Select"); //reset showDialog(); checkCategory(); }); $('#category_id').change( function() { checkCategory(); // checks value and enables/disables subcategory control var catid = $(this).val(); var dataString = 'catid='+catid; $.ajax ({ type: "POST", url: "catalogues.php", data: dataString, cache: false, success: function(data) { $('#subcategory_id').html(data).focus(); } }); }); $('#close').click( function() { hideDialog(); }); $("#notes_sh").click(function(){ // Notes show and hide toggle, off by default, $("#fld_notes").toggle(); }); $("#save").click(function(){ // Notes show and hide toggle, off by default, // So some save activity here $(".message").show().addClass("message_success", "message").text("Record saved successfully."); setTimeout(function() { $('.message').removeClass("message_success").text("Saved record title and file code goes here."); }, 5000); }); // ---------------------------------------------------------------------------------------------------------------------------------- // JS functions function hideDialog() { // Hide the dialog $('#dialog').fadeOut("slow"); $('#dialog_wrapper').fadeOut("slow"); } function showDialog() { // Show the dialog $('#dialog_wrapper').fadeIn(); $('#dialog').fadeIn("slow"); } // If category was changed adjust select boxes to suit. If category equals 'Please Select', sub-category should be disabled and set to 'Please Select' function checkCategory() { if ($('#category_id').val() == 'Please Select') { $('#subcategory').hide(); } else { $('#subcategory').show(); } } }); </script> <?php $pagetitle = "Catalogues"; // Set template page title require "includes/connection.php"; require_once 'library/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); $loader = new Twig_Loader_Filesystem('templates'); $twig = new Twig_Environment($loader, array('cache' => 'compilation_cache','debug' => true )); $template = $twig->loadTemplate('catalogues.html'); // ---------------------------------------------------------------------------------------------------------------------------------- // No matter what get all of the records and desplay them to the template $sql = "SELECT catalogues.id, catalogues.title, catalogues.manufacturer, catalogues.keywords, catalogues.file_code, catalogues.modified, catalogues.media_id, catalogues.website, catalogues.category_id, catalogues.subcategory_id, catalogues.author_id, catalogues.created, companies.company_name, catalogues_categories.category AS category_name, catalogues_categories.category, catalogues_subcategories.category AS subcategory_name FROM catalogues LEFT JOIN companies ON catalogues.manufacturer = companies.id LEFT JOIN catalogues_categories ON catalogues.category_id = catalogues_categories.id LEFT JOIN catalogues_categories AS catalogues_subcategories ON catalogues.subcategory_id = catalogues_subcategories.id"; $results=$conn->query($sql); $count = $results->rowCount(); // --------------------------------- // Get media_id array for select box $sql_manuf = "SELECT companies.id, companies.company_name FROM companies ORDER BY companies.company_name ASC"; $query_manuf = $conn->query($sql_manuf); $results_manuf = $query_manuf->fetchAll(); // --------------------------------- // Get category_id records for select box $sql_category = "SELECT catalogues_categories.id, catalogues_categories.category, catalogues_categories.parent_id, catalogues_categories.inuse FROM catalogues_categories WHERE catalogues_categories.parent_id = 0 AND catalogues_categories.inuse = 1 ORDER BY catalogues_categories.category ASC"; $query_category = $conn->query($sql_category); $results_category = $query_category->fetchAll(); // --------------------------------- // Get subcategory_id records for select box if(isset($_POST['catid'] )) { $catid=$_POST['catid']; $sql_subcategory = "SELECT catalogues_categories.id, catalogues_categories.category, catalogues_categories.parent_id, catalogues_categories.inuse FROM catalogues_categories WHERE catalogues_categories.parent_id = '$catid' AND catalogues_categories.inuse = 1 ORDER BY catalogues_categories.category ASC"; $query_subcategory = $conn->query($sql_subcategory); $results_subcategory = $query_subcategory->fetchAll(); echo '<option value= "-1"> Please Select </option>'; foreach ( $results_subcategory as $row ){ echo '<option value="'.$row['id'].'">'.$row['category'].'</option>'; } $conn = null; // Play it safe and close the connection $_POST['catid'] = null; // Reset post category id as we dont need it any more. } else { $results_subcategory = null; } // --------------------------------- // Get media_id array for select box $sql_media = "SELECT catalogues_media.id, catalogues_media.media FROM catalogues_media ORDER BY catalogues_media.media ASC"; $query_media = $conn->query($sql_media); $results_media = $query_media->fetchAll(); // ---------------------------------------------------------------------------------------------------------------------------------- // Output template variables echo $template->render(array( 'results' => $results, 'pagetitle' => $pagetitle, 'count' => $count, 'results_manuf' => $results_manuf, 'results_media' => $results_media, 'results_category' => $results_category )); ?> html: <div class="dialog_form"> <div class="message" > </div> <div style='float: left'> <div class='field'><label>Title:</label><input class="field" id='title' name="title" type='text' value= {{ row.title }} ></div> <div class='field'><label>Manufacturer:</label> <select class="required" id="manufacturer" name="manufacturer"> <option>Please Select </option> {% for row_manuf in results_manuf %} <option value= {{ row_manuf.id }} > {{ row_manuf.company_name }} </option> {% endfor %} </select> </div> <div class='field'><label>File Code:</label><input class="field" type='text' name='file_code' value= {{ row.file_code }} ></div> <div class='field'><label>Catalogue URL:</label><input class="field" type='text' name='website' value= {{ row.website }} ></div> </div> <div style='float: right'> <div class='field'><label>Media:</label> <select class="required" id="media_id" name="media_id"> <option>Please Select </option> {% for row_media in results_media %} <option value= {{ row_media.id }} > {{ row_media.media }} </option> {% endfor %} </select> </div> <div class='field'><label>Category:</label> <select class="required" name="category_id" id="category_id"> <option>Please Select </option> {% for row_category in results_category %} <option value= {{ row_category.id }} > {{ row_category.category }}</option> {% endfor %} </select> </div> <div class='field' id="subcategory"><label >Sub-category:</label> <select class="required" name="subcategory_id" id="subcategory_id"> <option>Please Select </option> </select> </div> </div> <div style='clear:both;'><br/> <label >Notes:</label> <label id="notes_sh" >Show/Hide</label><br/> <textarea id="fld_notes" name="notes" rows="10" cols="128"> {{ row.notes }} </textarea><br/> <label>Keywords:</label><br/> <input style="width:100%;" type='text' name='keywords' value= {{ row.keywords }} > </div> <div style='text-align: right ; margin-top: 20px; clear:both;'> Multiple <input type='checkbox' name='multiple' > <input type='hidden' name='id' value= {{ row.id }} > <input class='Button' id='save' type='submit' value='Save' name='save'> <input id="close" class='button' type='button' value='close' name='close' > </div> </div> catalogues.html catalogue_form.html
  5. Hi all, I have this form that has a label with a click event mapped to toggle the visibility of a textarea and it worked great until I setup 2 combo boxes with an ajax call for the second. After opening the form the toggle on #notes_sh works ok. If I set values in the 2 combo boxes and then try to select the #notes_sh label there is no event fired. I have no errors coming up in my js console. Any ideas why this toggle it not firing after setting values in the combo boxes? James ps. Occurs on both Chrome and Firefox. $("#notes_sh").click(function(){ // Notes show and hide toggle, off by default, $("#fld_notes").toggle(); $('#category_id').change( function() { checkCategory(); // checks value and enables/disables subcategory control var catid = $(this).val(); var dataString = 'catid='+catid; $.ajax ({ type: "POST", url: "catalogues.php", data: dataString, cache: false, success: function(data) { $('#subcategory_id').html(data).focus(); } }); }); // Get subcategory_id records for select box if(isset($_POST['catid'] )) { $catid=$_POST['catid']; $sql_subcategory = "SELECT catalogues_categories.id, catalogues_categories.category, catalogues_categories.parent_id, catalogues_categories.inuse FROM catalogues_categories WHERE catalogues_categories.parent_id = '$catid' AND catalogues_categories.inuse = 1 ORDER BY catalogues_categories.category ASC"; $query_subcategory = $conn->query($sql_subcategory); $results_subcategory = $query_subcategory->fetchAll(); echo '<option value= "-1"> Please Select </option>'; foreach ( $results_subcategory as $row ){ echo '<option value="'.$row['id'].'">'.$row['category'].'</option>'; } $conn = null; // Play it safe and close the connection $_POST['catid'] = null; // Reset post category id as we dont need it any more. } else { $results_subcategory = null; }
  6. Should line 32 be: ' + option.category + ' instead of ' + option.name + ' $('#category_id').change( function() { checkCategory(); // checks value and enables/disables subcategory control var catid = $(this).val(); var dataString = 'catid='+catid; $.ajax ({ type: "POST", url: "catalogues.php", data: dataString, cache: false, success: function(data) { var el = document.getElementById('subcategory_id'); $(el).empty(); // remove all HTML inside <select/> $.each(data, function(i, option) { // add each <option/> from data $('<option value="' + option.id + '">' + option.name + '</option>').appendTo(el); }); } }); });
  7. Thanks but this returns a error in the js console (chrome) and the select control is empty. Uncaught TypeError: Cannot use 'in' operator to search for '3951' in <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
  8. I am trying to update the second select box 'subcategory_id' but I don't know how to return the query values back to the control/twig template. All of the examples I have seen echo back html from a option while loop. Should I be echo back the html as per other common examples or is there a more twig compliant way to do this, maybe returning an array variable. Thanks in advance, James catalogues.php <script> $('#category_id').change( function() { checkCategory(); // checks value and enables/disables subcategory control var catid = $(this).val(); var dataString = 'catid='+catid; $.ajax ({ type: "POST", url: "catalogues.php", data: dataString, cache: false, success: function() { $("#subcategory_id")..........; // ????? } }) }); </script> <?php if(isset($_POST['catid'] )) { $catid=$_POST['catid']; $sql_subcategory = "SELECT catalogues_categories.id, catalogues_categories.category, catalogues_categories.parent_id, catalogues_categories.inuse FROM catalogues_categories WHERE catalogues_categories.parent_id = {$catid} AND catalogues_categories.inuse = 1 ORDER BY catalogues_categories.category ASC"; $query_subcategory = $conn->query($sql_subcategory); $results_subcategory = $query_subcategory->fetchAll(); } else { $results_subcategory = null; } ?>
  9. Yes I could but single.html (master layout) would not be able to be used for say contacts because I would need to include contacts_form.html If I have single.html and contact.html that extends single.html how do I assign note.html, review.html, expense.html (dialog templates) to the one div if I cannot dynamically assign it based on the selected action. Do I have to have 3 divs with display:none, and individual includes?
  10. I have a div I use for dialogs and I want to pass a string to the div and then show the specific twig template as an include. The div dialog is displayed without the template embedded, What am I doing wrong, is there a better way to do it? $('#new').click( function() { var str = " {% include 'catalogue_form.html' %} "; $('#dialog').text(str).html(); showDialog(); }); function showDialog() { $('#dialog_wrapper').fadeIn(); $('#dialog').fadeIn("slow"); } Thanks in advance, James
  11. #$%^$@#.... This has been resolved.Might help if I put the 's' on 'catalogue' What a waste of time! Time for bed.
  12. I am changing my test code from mysqli to PDO. It worked for one of my forms but the other I racking my brain as to why it isn't. I have stripped it down, found a few typos but array 0000 error is occurring and I am unsure how to resolve it. Can you help? James connection $dbtype = "mysql"; $dbhost = "localhost"; $dbname = "mydb1"; $dbuser = "myusr1"; $dbpass = "mp1"; try { // database connection $conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); $conn -> exec('SET CHARACTER SET utf8'); } catch(PDOException $e) { echo 'There was a problem'; } php $sql = "UPDATE catalogue SET title=:title, manufacturer=:manufacturer WHERE id=:id"; $q = $conn->prepare($sql); $q->bindParam(':id',$_POST['id'], PDO::PARAM_INT); $q->bindParam(':title',$_POST['title'], PDO::PARAM_STR); $q->bindParam(':manufacturer',$_POST['manufacturer'], PDO::PARAM_INT); if ($q->execute()){ echo "Saved successfully"; } else { echo "<br/> Crap, something went wrong <br/>"; //just for testing echo $sql." <br/>"; print_r($_POST); print_r($conn->errorCode()); echo "<br/>"; print_r($conn->errorInfo()); echo "<br/>"; } output Crap, something went wrong UPDATE catalogue SET title=:title, manufacturer=:manufacturer WHERE id=:id Array ( [title] => Madinoz Pty Ltd [manufacturer] => 71 [media_id] => 1 [category_id] => 17 [subcategory_id] => Please Select [notes] => This is some text. [keywords] => Hardware, Handles, Hooks, Rails, Fittings, [save] => Save [id] => 2 ) 00000 Array ( [0] => 00000 [1] => [2] => )
  13. My php code is currently separated from my html, at least as much as possible without using a framework or template system. I am echoing out $result['title'] in my html, is there an easy way to convert it to a variable so I can use $title instead? current html: <?php foreach ($results as $row): ?> <?php echo $row['title'] ?> <?php echo $row['description'] ?> <?php endforeach; ?> php: $results=$conn->query($sql);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.