Jump to content

hobbiton73

Members
  • Posts

    78
  • Joined

  • Last visited

Everything posted by hobbiton73

  1. Hi Christian F. thank you for your continued help with this, and my sincere apologies for not providing you with enough details. Please find below the expressions I've tried: I initially started with the more striaght forward combinations: else if(!preg_match('/^[A-Za-z0-9 \']{5,60}$/', $locationname)) else if(!preg_match('/^[A-Za-z0-9 ']{5,60}$/', $locationname)) I then tried the following: else if(!preg_match('/^[A-Za-z0-9 .,;\-\']{5,60}$/', $locationname)) else if(!preg_match('/^[A-Za-z0-9 .,;\'\-]{5,60}$/', $locationname)) else if(!preg_match('/^[-A-Za-z0-9 .,;\']{5,60}$/', $locationname)) else if(!preg_match('/^[-A-Za-z0-9 .,;']{5,60}$/', $locationname)) As I said in my earlier posts, these have been unsuccessful and when the validation fails, I receive this error mesage: $message = "Invalid Location Name, please try again!"; I've looked to see if 'Magic_Quotes' are turned on and they are, but am I correct in thinking that this is a fale safe aginst SQL Injection? My apologiezs if my understanding is incorrect. Many thanks and kind regards Chris
  2. Hi @requinix, thank you also for taking the time to reply to my post. My sincere apologies for being a little inexperienced, but could you possibly what i would need to do to change the 'php.ini' file? Many thanks and kind regards Chris
  3. Hi @Christian F., thank you for taking the time to reply to my post. When a user wants to save a record, there are two validation files which I use. The first is the actual form validation where the relevant jquery success or failure messages are displayed, and for this I use the following regex: "onlyMapmyfinds": { "regex": /^$|^[-A-Za-z0-9 .,;']+$/, "alertText": "* No special characters allowed" }, As you can see this incoporates the apostrophe without any problem. The second file is the PHP script which saves the record to a mySQL database which is where I have the problem. As it currently stand this is the specific line which throws up the error message: else if(!preg_match('/^[A-Za-z0-9 .,;-]{5,60}$/', $locationname)){ //validate email address - check if is a valid email address $status = "error"; $message = "Invalid Location Name, please try again!"; } I hope this helps. Many thanks and kind regards Chris
  4. Hi, I wonder whether someone may be able to help me please. I'm using the regex expression below as part of my form validation. else if(!preg_match('/^[A-Za-z0-9 .,;-]{5,60}$/', $locationname)) As it currently stands the expression works fine, but I'm having great difficulty when tyrying to add the ' (apostrophe). I've been working on this for a couple of days now, escaping the charcater, moving it to different positions within the expression, sadly without any luck. I just wondered whether someone could possibly look at this please and let me know where I'm going wrong and put me out of my misery . Many thanks and kind regards Chris
  5. Hi, I wonder whether someone may be able to help me please. I've put together this page http://www.mapmyfind.../chris/test.php which allows the user to add and remove Google Map markers via a 'Category' check box selection. In addition, as each marker is added or removed from the map, the linked 'Description' is added and removed from the 'Sidebar' (shown in orange). You will see that as a map marker is selected a 'Infowindow' is created above the marker and the linked 'Sidebar Description Item' is highlighted in grey. The problem I'm having is that I cannot find a way to make the 'Sidebar' automatically scroll so the the sidebar item is visible to the user. To illustrate this a little better than I can perhaps explain, I have found an example here http://www.blocsoft....xample12.V3.asp which highlights the behaviour I'm looking for. I've read many a tutorial and tried several plugins, all without success. I just wondered whether someone could perhaps take a look at this please and let me know where I'm going wrong. I really would be most grateful of any help as I've been working on this for several weeks. Many thanks and kind regards
  6. Hi, firstly I am by no means an expert when it comes to this. But I was trying to do something similar for my current project. I, probably like yourself, did a lot of searching and found this http://www.profilepicture.co.uk/sticky-sidebar-jquery-plugin/. I'm not sure whether this is of any use, but I've found it to be a really useful plugin. My apologies If I've misunderstood what you're trying to achieve, but I hope this may help. Many thanks and kind regards
  7. Hi, i'm not sure whether this will help at all, but I've recently dealt with this for my current project and, I too found it difficult to get my head around The following links are what I used as a starting point. They provide fairly simple examples to the more advanced. Anyway this is the link for the front end http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/ and this is source for the back end validation I used http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ I hope it helps. Kind regards
  8. I wonder whether someone may be able to help me please. Firstly, my apologies because I'm not particularly well versed with Javascript, so perhaps this may be a very basic error to some. I've put together this page http://www.mapmyfind.../chris/test.php which allows users to add and remove map markers via 'Marker Category' check box selection. In addition, as the markers are added to the map, an associated 'Sidebar' item is also created (shown in orange text). If a map marker is clicked, a 'Infowindow' appears over the marker and the relevant 'Sidebar' item is highlighted with a grey background. The problem I'm having is that the once the map marker has been selected, I cannot get the 'Sidebar' to automatically scroll, so that the 'Sidebar' item is visible to the user. I appreciate that my description of the problem may not be particularly well detailed, so please find a link to an example page here http://www.blocsoft....xample12.V3.asp which illustrates what I'm trying to achieve. I've been working on this for a while now and read through quite a lot of 'plugins' and tutorials to try and find the solution, unfortunately without any success. I just wondered whether someone may be able to look at this please and offer some guidance on how I may be able to solve this problem. Many thanks and kind regards
  9. Hi @ChristianF, I hope you are well. I wonder whether you may be able to help me please. Following on from your much appreciated advice yesterday, I went away to research 'Server' side validation. I found that the tutorial I was using did cater for this here http://www.position-absolute.com/articles/using-form-ajax-validation-with-the-jquery-validation-engine-plugin/. I've been working through the 'Inline' demo, but I wonder whether you may be able to help me please with a few things I'm not too clear about. The demo deals with 3 PHP files (shown below) in conjunction with main HTML page. jquery.validationEngine-en.js (function($){ $.fn.validationEngineLanguage = function(){ }; $.validationEngineLanguage = { newLang: function(){ $.validationEngineLanguage.allRules = { "required": { // Add your regex rules here, you can take telephone as an example "regex": "none", "alertText": "* This field is required", "alertTextCheckboxMultiple": "* Please select an option", "alertTextCheckboxe": "* This checkbox is required", "alertTextDateRange": "* Both date range fields are required" }, "requiredInFunction": { "func": function(field, rules, i, options){ return (field.val() == "test") ? true : false; }, "alertText": "* Field must equal test" }, "dateRange": { "regex": "none", "alertText": "* Invalid ", "alertText2": "Date Range" }, "dateTimeRange": { "regex": "none", "alertText": "* Invalid ", "alertText2": "Date Time Range" }, "minSize": { "regex": "none", "alertText": "* Minimum ", "alertText2": " characters allowed" }, "maxSize": { "regex": "none", "alertText": "* Maximum ", "alertText2": " characters allowed" }, "groupRequired": { "regex": "none", "alertText": "* You must fill one of the following fields" }, "min": { "regex": "none", "alertText": "* Minimum value is " }, "max": { "regex": "none", "alertText": "* Maximum value is " }, "past": { "regex": "none", "alertText": "* Date prior to " }, "future": { "regex": "none", "alertText": "* Date past " }, "maxCheckbox": { "regex": "none", "alertText": "* Maximum ", "alertText2": " options allowed" }, "minCheckbox": { "regex": "none", "alertText": "* Please select ", "alertText2": " options" }, "equals": { "regex": "none", "alertText": "* Fields do not match" }, "creditCard": { "regex": "none", "alertText": "* Invalid credit card number" }, "phone": { // credit: jquery.h5validate.js / orefalo "regex": /^([\+][0-9]{1,3}[\ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9\ \.\-\/]{3,20})((x|ext|extension)[\ ]?[0-9]{1,4})?$/, "alertText": "* Invalid phone number" }, "email": { // HTML5 compatible email regex ( http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html# e-mail-state-%28type=email%29 ) "regex": /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/, "alertText": "* Invalid email address" }, "integer": { "regex": /^[\-\+]?\d+$/, "alertText": "* Not a valid integer" }, "number": { // Number, including positive, negative, and floating decimal. credit: orefalo "regex": /^[\-\+]?((([0-9]{1,3})([,][0-9]{3})*)|([0-9]+))?([\.]([0-9]+))?$/, "alertText": "* Invalid floating decimal number" }, "date": { // Check if date is valid by leap year "func": function (field) { var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/); var match = pattern.exec(field.val()); if (match == null) return false; var year = match[1]; var month = match[2]*1; var day = match[3]*1; var date = new Date(year, month - 1, day); // because months starts from 0. return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day); }, "alertText": "* Invalid date, must be in YYYY-MM-DD format" }, "ipv4": { "regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/, "alertText": "* Invalid IP address" }, "url": { "regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i, "alertText": "* Invalid URL" }, "onlyNumberSp": { "regex": /^[0-9\ ]+$/, "alertText": "* Numbers only" }, "onlyLetterSp": { "regex": /^[a-zA-Z\ \']+$/, "alertText": "* Letters only" }, "onlyLetterNumber": { "regex": /^[0-9a-zA-Z]+$/, "alertText": "* No special characters allowed" }, // --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings "ajaxUserCall": { "url": "ajaxValidateFieldUser", // you may want to pass extra data on the ajax call "extraData": "name=eric", "alertText": "* This user is already taken", "alertTextLoad": "* Validating, please wait" }, "ajaxUserCallPhp": { "url": "phpajax/ajaxValidateFieldUser.php", // you may want to pass extra data on the ajax call "extraData": "name=eric", // if you provide an "alertTextOk", it will show as a green prompt when the field validates "alertTextOk": "* This username is available", "alertText": "* This user is already taken", "alertTextLoad": "* Validating, please wait" }, "ajaxNameCall": { // remote json service location "url": "ajaxValidateFieldName", // error "alertText": "* This name is already taken", // if you provide an "alertTextOk", it will show as a green prompt when the field validates "alertTextOk": "* This name is available", // speaks by itself "alertTextLoad": "* Validating, please wait" }, "ajaxNameCallPhp": { // remote json service location "url": "phpajax/ajaxValidateFieldName.php", // error "alertText": "* This name is already taken", // speaks by itself "alertTextLoad": "* Validating, please wait" }, "validate2fields": { "alertText": "* Please input HELLO" }, //tls warning:homegrown not fielded "dateFormat":{ "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(??:(?:0?[13578]|1[02])(\/|-)31)|(??:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(??:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(??:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/, "alertText": "* Invalid Date" }, //tls warning:homegrown not fielded "dateTimeFormat": { "regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1}$|^(??:(?:0?[13578]|1[02])(\/|-)31)|(??:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|AM|PM){1})$/, "alertText": "* Invalid Date or Date Format", "alertText2": "Expected Format: ", "alertText3": "mm/dd/yyyy hh:mm:ss AM|PM or ", "alertText4": "yyyy-mm-dd hh:mm:ss AM|PM" } }; } }; $.validationEngineLanguage.newLang(); })(jQuery); ajaxValidateFieldName.php <?php /* RECEIVE VALUE */ $validateValue=$_REQUEST['fieldValue']; $validateId=$_REQUEST['fieldId']; $validateError= "This username is already taken"; $validateSuccess= "This username is available"; /* RETURN VALUE */ $arrayToJs = array(); $arrayToJs[0] = $validateId; if($validateValue =="duncan"){ // validate?? $arrayToJs[1] = true; // RETURN TRUE echo json_encode($arrayToJs); // RETURN ARRAY WITH success }else{ for($x=0;$x<1000000;$x++){ if($x == 990000){ $arrayToJs[1] = false; echo json_encode($arrayToJs); // RETURN ARRAY WITH ERROR } } } ?> ajaxValidateFieldUser.php <?php /* RECEIVE VALUE */ $validateValue=$_REQUEST['fieldValue']; $validateId=$_REQUEST['fieldId']; $validateError= "This username is already taken"; $validateSuccess= "This username is available"; /* RETURN VALUE */ $arrayToJs = array(); $arrayToJs[0] = $validateId; if($validateValue =="karnius"){ // validate?? $arrayToJs[1] = true; // RETURN TRUE echo json_encode($arrayToJs); // RETURN ARRAY WITH success }else{ for($x=0;$x<1000000;$x++){ if($x == 990000){ $arrayToJs[1] = false; echo json_encode($arrayToJs); // RETURN ARRAY WITH ERROR } } } ?> What I'm trying to understand is the correlation between the 'validation engine' file and the other two files. In these examples the validation is carried out on the 'User Name' and 'First Name' but would it be possible to actually add the field format criteria to these files i.e. field length etc, rather than having this in the HTML page. My apologies if I've not been particularly clear and fro the lengthy post, but I just wondered whether you may be able to break things down into 'layman's' terms. Many thanks and kind regards
  10. Hi ChristianF, thank you for this, although I have to admit that most of it has gone way over my head. It looks like it's something I need to look at. Many thanks and kind regards
  11. Hi ChristianF, thank you very much for taking the time to reply to my post. I am very new to this, so I've obviously made some errors. Could you perhaps elaborate how I may achieve this on the 'server' rather than the 'client' side. Many thanks and kind regards
  12. I wonder whether someone may be able to help me please. Using this http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ and this http://net.tutsplus.com/tutorials/javascript-ajax/building-a-sleek-ajax-signup-form/ tutorials, I've put together this http://www.mapmyfinds.co.uk/chris/test2.php page which performs 'field' validation, then, upon the 'Save' button being clicked by the user, displays a AJAX status message telling the user whether the record has been saved or not. The problem I'm having is that although the fields are correctly validated i.e. if the fields are blank, the correct validation error messages are displayed on screen, the AJAX message says that the 'Record has been saved' and the record is added to a mySQL database, so in essence creating a blank record. I'm having great difficulty in joining the 'Validation' and the 'Record Saved' message. I've run this through JavaScript Console and unfortunately there are no errors shown, so I have to be honest and say that I'm really not sure where the problem lies. This is the code which activates the AJAX message: <script type="text/javascript"> jQuery(document).ready(function(){ // binds form submission and fields to the validation engine jQuery("#addlocation").validationEngine(); }) </script> <script type="text/javascript"> $(document).ready(function(){ $('#addlocation').submit(function(){ //check the form is not currently submitting if($(this).data('formstatus') !== 'submitting'){ //setup variables var form = $(this), formData = form.serialize(), formUrl = form.attr('action'), formMethod = form.attr('method'), responseMsg = $('#saverecordresponse'); //add status data to form form.data('formstatus','submitting'); //show response message - waiting responseMsg.hide() .addClass('response-waiting') .text('Please Wait...') .fadeIn(200); //send data to server for validation $.ajax({ url: formUrl, type: formMethod, data: formData, success:function(data){ //setup variables var responseData = jQuery.parseJSON(data), klass = ''; //response conditional switch(responseData.status){ case 'error': klass = 'response-error'; break; case 'success': klass = 'response-success'; break; } //show reponse message responseMsg.fadeOut(200,function(){ $(this).removeClass('response-waiting') .addClass(klass) .text(responseData.message) .fadeIn(200,function(){ //set timeout to hide response message setTimeout(function(){ responseMsg.fadeOut(300,function(){ $(this).removeClass(klass); form.data('formstatus','idle'); }); },2000) setTimeout(function() { $('body').fadeOut(400, function(){ location.reload(); setTimeout(function(){ $('body').fadeIn(400); }, 500); window.scrollTo(x-coord, y-coord); }); }, 2000); }); }); } }); } //prevent form from submitting return false; }); }); </script> and the following code is the PHP script which saves the record. <?php $userid = $_POST['userid']; $locationname = $_POST['locationname']; $returnedaddress = $_POST['returnedaddress']; $osgb36lat = $_POST['osgb36lat']; $osgb36lon = $_POST['osgb36lon']; $nameofcontact = $_POST['nameofcontact']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $address3 = $_POST['address3']; $address4 = $_POST['address4']; $address5 = $_POST['address5']; $telephonenumber = $_POST['telephonenumber']; $query = mysql_query("INSERT INTO `table` (userid, locationname, returnedaddress, osgb36lat, osgb36lon, nameofcontact, address1, address2, address3, address4, address5, telephonenumber) VALUES ('$userid', '$locationname', '$returnedaddress', '$osgb36lat', '$osgb36lon', '$nameofcontact', '$address1', '$address2', '$address3', '$address4', '$address5', '$telephonenumber')"); if($query){ //if insert is successful $status = "success"; $message = "Location Saved!"; } else { //if insert fails $status = "error"; $message = "There was a problem in saving the record. Please try again!"; } //return json response $data = array( 'status' => $status, 'message' => $message ); echo json_encode($data); exit; ?> I just wondered whether someone could have a look at this please and let me know where I'm going wrong? Many thanks and kind regards
  13. Hi @jazzman1, I don't know what to say. This works like a dream. I can't really express how grateful I am. Thank you so much for all your help, time and trouble, it's so greatly appreciated. Many thanks, all the best and kind regards
  14. Hello, I wonder whether someone may be able to help me please with a problem I've been working on for a number of days which I just can't solve. The extract of code below shows part of a script which I use to successfully create a table of 'location' records pertinent to the current user. <form name="delete" id="delete" class="delete"> <input type="hidden" name="lid" id="lid" value="<?php echo $theID ?>" /> <input type="submit" value="Delete Record"/> </form> The problem I'm having is around the `deletion a `location record`. Originating here http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/, upon clicking the `delete` button, the 'Delete Confirmation' message appears on screen and the user can select `Yes` or `No`. If the user selects `Yes`, the `lid` value should be passed to the jQuery AJAX script below and onto a 'deletion' PHP script. <script type="text/javascript"> $('.delete').submit(function(e){ e.preventDefault(); var elem = $(this).closest('.delete'); console.log($(this).serialize()); $.confirm({ 'title' : 'Delete Confirmation', 'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?', 'buttons' : { 'Yes' : { 'class' : 'blue', 'action': function(){ //elem.slideUp(); $.ajax({ url: 'deletelocation.php', type: 'POST', data: $(this).serialize(), success: function(response) { console.log('success', response); }, error: function() { console.log('error') } }); } }, 'No' : { 'class' : 'gray', 'action': function(){} // Nothing to do in this case. You can as well omit the action property. } } }); }); </script> and this is my`deletelocation.php` script called in the above code: <?php $lid = $_POST['lid']; $query = mysql_query("DELETE FROM table WHERE locationid='$lid'"); ?> The problem I'm having is that I cannot find a way to pass the value from the form through the AJAX script and delete the record. The 'Delete Confirmation message' correctly appears on screen, but when I select yes the record is not deleted. In JS Console I receive the following message: lid=5 success So I do know that it is picking up the correct 'lid' value but it's just not passing it through to delete script. I just wondered whether someone could possibly take a look at this please and let me know where I'm going wrong. Many thanks and kind regards
  15. Hi, thank your for your continued help with this. I have tried incorporating the js , but unfortunately this doesn't solve my problem. I think the issue lies with the link between the button and the JS function, I just need to try and figure how to link them together. Many thanks and kind regards
  16. Hi @Ryflex, thank you for taking the time to reply to my post. My apologies as I should have made this clear in my original post. All the other scripts, including the one you have highlighted are included in the header section of my page as external scripts The script you refer to, and I'm happy to be proven wrong, deals with how the buttons on the confirmation message appear and behave, rather than using a button click to make the confirmation message appear. Once again many thanks and kind regards
  17. Hi, I wonder whether someone may be able to help me please. Firstly, my apologies if this isn't the right forum to add this post to. Because my problem relates to both JavaScript and AJAX I wasn't quite sure where to post it. The extract of code below creates a table of 'Location' records, pertinent to the current user. echo "<tr>\n"; $theID = $row['locationid']; echo " <td style='text-align: Center'>{$row['locationname']}</td>\n"; echo " <td style='text-align: Left'>{$row['returnedaddress']}</td>\n"; echo " <td style='text-align: Center'>{$row['totalfinds']}</td>\n"; echo " <form action= locationsaction.php method= 'post'><input type='hidden' name='lid' value=$theID/> <td><input type= 'submit' name= 'type' value= 'Details'/></td> <td><input type= 'submit' name= 'type' value= 'Images'/></td> <td><input type= 'submit' name= 'type' value= 'Add Finds'/></td> <td><input type= 'submit' name= 'type' value= 'View Finds'/></td> <td><input type= 'submit' name= 'type' value= 'Delete' id= 'delete'/></td></form>\n"; echo "</tr>\n"; You'll see that of the code there are 5 buttons which appear on each row of the table. Clicking on any of these navigates the user to different screens, but all linked back to the main 'Location' record via a 'lid' variable. The function of navigating the user to the correct page is fulfilled by the 'locationsaction.php' script which is shown below: <?php session_start(); $_SESSION['lid'] = $_POST['lid']; if (isset($_POST['type'])) { $urls = array( 'Details' => 'viewlocation.php', 'Add Finds' => 'addfinds.php', 'Images' => 'addimages.php', 'View Finds' => 'locationfinds.php', 'Delete' => 'deletelocation.php' ); $url = $urls[$_POST['type']]; header("Location: " . $url); } ?> I'm now trying to add a 'Confirmation' message which will appear when the user selects 'Delete', the source of which can be found in the 'script.js' code from the link below. http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/ I admit that I am very new to JavaScript, but this is what I've managed to put together so far. <script type="text/javascript"> $('.item #delete').click(function () { var elem = $(this).closest('.item'); $.confirm({ 'title': 'Delete Confirmation', 'message': 'Delete?', 'buttons': { 'Yes': { 'class': 'blue', 'action': function () { //elem.slideUp(); $.ajax({ url: 'locationsaction.php', type: 'post', data: { lid: "VALUE", type: 'Delete' //you need to add the type here! }, }); } }, 'No': { 'class': 'gray', 'action': function () {} // Nothing to do in this case. You can as well omit the action property. } } }); </script> The problem I'm having is that I don't know how to tie up the button click with JavaScript code. At the moment upon clicking 'Delete' the record is deleted without the 'Confirmation' message. I've run this through JavaScript console and there are no errors shown. I just wondered whether someone could possibly take a look at this please and let me know where I'm going wrong. Many thanks and kind regards
  18. Hi, thank you very much for this. I think I understand what you're saying. I'll take this away and start to work with it. Kind regards
  19. Hi, thank you for taking the time to reply to my post. I'm very sorry but I'm relatively new to PHP, could you perhaps explain a little more about the array. For additional information I have added the 'locationsaction.php' script which is called when the button is clicked. <?php session_start(); $_SESSION['lid'] = $_POST['lid']; if (isset($_POST['type'])) { $urls = array( 'View Details' => 'viewlocation.php' ); $url = $urls[$_POST['type']]; header("Location: " . $url); } ?> Many thanks and kind regards
  20. I wonder whether someone may be able to help me please. I'm using the code below to create a table which lists location records for the current user. <form name="locationsconsole" id="locationsconsole" method="post" action="locationsaction.php"> <table width="865"> <tr> <th width="22"></th> <th width="236"><div align="left">Location Name</div></th> <th width="244"><div align="left">Location Address</div></th> <th width="71"></th> </tr> <?php $query = "SELECT l.*, COUNT(f.locationid) totalfinds FROM detectinglocations l LEFT JOIN finds f ON f.locationid = l.locationid WHERE l.userid = '$idnum' GROUP BY l.locationname"; $result = mysql_query($query) or die('error'); while($obj=mysql_fetch_object($result)) { ?> <tr> <td><input type="hidden" name="lid" value="<?php echo $obj->locationid;?>"/></td> <td><?php echo $obj->locationname;?></td> <td><?php echo $obj->returnedaddress;?></td> <td><input name="type" type="submit" value="View Details"/></td> </tr> <?php } ?> </table> </form> You'll see from the code that on each row there is a button which takes the user to another page via 'locationsaction.php'. There are currently 3 location records in the table which is correct, and when the button is clicked the user is taken to the correct screen. However, the problem I'm having, is that no matter which row button I select, the record retrieved is always related to the last location record and I just can't work out what the problem is. I've been working in this for sometime, and I just can't seem to find a solution. I do know that the query is working OK because I've tested this independently. I just wondered whether someone could take a look at this please and let me know where I'm gong wrong. Many thanks and kind regards
  21. Hi @scootash, I just wanted to let you know that I've been able to solve this. The problem was how I had set my form up to work with the data that was being through in my PHP script. Although I need to sort out the formatting, this is my solution. <table width="732" border="0"> <tr> <th width="17"></th> <th width="62"><div align="center">Location Name</div></th> <th width="120"><div align="left">Location Address</div></th> <th width="81"><div align="center">No. Of Finds Made </div></th> <th width="86"></th> <th width="72"></th> <th width="84"></th> <th width="769"></th> </tr> <?php include("admin/link.php"); include("admin/opendb.php"); $query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname"; $result = mysql_query($query) or die('error'); $num = mysql_num_rows($result); mysql_close($connect); $i=0; while ($i < $num) { $lid=mysql_result($result,$i,"locationid"); $lname=mysql_result($result,$i,"locationname"); $laddress=mysql_result($result,$i,"returnedaddress"); include("admin/link.php"); include("admin/opendb.php"); $fquery = "SELECT COUNT(*) num FROM table WHERE locationid = '$lid'"; $fcount = mysql_query($fquery) or die('error'); $row = mysql_fetch_assoc($fcount); $findscount = $row['num']; mysql_close($connect); ?> <form name="mylocationsconsole" id="mylocationsconsole" method="post" action="locationsaction.php"/> <tr> <td><input type="hidden" name="lid" value="<?=$lid?>" /></td> <td><div align="center"><?php echo $lname;?></div></td> <td><div align="left"><?php echo $laddress;?></div></td> <td><div align="center"><?php echo $findscount?></div></td> <td><div align="center"><input name="type" type="submit" value="View Details"/></div></td> <td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td> <td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td> <td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td> </tr> <tr> <th colspan="8"><br/><hr width="100%"></th></tr> </table> </form> <?php $i++; } if ($num == 0) { echo"<tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr>"; } ?> </table> Thank you very much for all your time and trouble. All the best and kind regards
  22. Hi @scootstah, thank you for replying to my post. No all the pages don't have session start. However this hasn't changed since when the pages worked. Kind regards
  23. I wonder whether someone may be able to help me please. I'm using the form shown below to create a list of 'Locations' taken from a mySQL database. Then, via four form buttons, users can navigate to four separate screens all linked to back to the main Location record. <form name="mylocationsconsole" id="mylocationsconsole" method="post" action="locationsaction.php"> <?php include("admin/link.php"); include("admin/opendb.php"); $query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname"; $result = mysql_query($query) or die('error'); $num = mysql_numrows($result); mysql_close($connect); $i=0; while ($i < $num) { $lid=mysql_result($result,$i,"locationid"); $lname=mysql_result($result,$i,"locationname"); $laddress=mysql_result($result,$i,"returnedaddress"); include("admin/link.php"); include("admin/opendb.php"); $fquery = "SELECT COUNT(*) num FROM table WHERE locationid = '$lid'"; $fcount = mysql_query($fquery) or die('error'); $row = mysql_fetch_assoc($fcount); $findscount = $row['num']; ?> <br /> <table width="1325" border="0"> <tr> <th width="17"></th> <th width="171"><div align="center">Location Name</div></th> <th width="278"><div align="left">Location Address</div></th> <th width="142"><div align="center">No. Of Finds Made </div></th> <th width="94"></th> <th width="76"></th> <th width="84"></th> <th width="429"></th> </tr> <tr> <td><input type="hidden" name="lid" value="<?=$lid?>" /></td> <td><div align="center"><?php echo $lname;?></div></td> <td><div align="left"><?php echo $laddress;?></div></td> <td><div align="center"><?php echo $findscount?></div></td> <td><div align="center"><input name="type" type="submit" value="View Details"/></div></td> <td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td> <td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td> <td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td> </tr> <tr> <th colspan="8"><br/><hr width="100%"></th></tr> </table> <?php $i++; } if ($num == 0) { echo"<tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr>"; } ?> </form> This code below is the script called by the above form when one of the four form buttons is selected. locationsaction.php <?php session_start(); $_SESSION['lid'] = $_POST['lid']; if (isset($_POST['type'])) { $urls = array( 'View Details' => 'viewlocation.php', 'Add Finds' => 'addfinds.php', 'Add Images' => 'addimages.php', 'View Location Finds' => 'locationfinds.php' ); $url = $urls[$_POST['type']]; header("Location: " . $url); } ?> All of the four receiving pages then have this at the top of each page to capture the variable. All of this was working fine up until two days ago, but the problem I now have is, irrespective of the number of locations in the list, the buttons take me to the correct screens but it is always for the last `Location` record in the list. I've rebuilt the pages which I think could be the problem but I still can't get this to work. I just wondered whether someone may be able to look at this please and let me know where I'm going wrong, or perhaps suggest a better way of doing this. Many thanks and kind regards
  24. Hi, thank you very much for taking the time to reply to my post and for the help. I've managed to overcome the problems I had with a solution which in some respects is not too disimilar to your suggestion. The main problem was the 'delete.php' file, and working this through with a family member who's a bit of a whizz, I found that the 'image' value actually pulled through the whole URL rather than just the filename. So I came up with the following: gallery.php // send the AJAX request $.ajax({ url : 'delete.php', type : 'post', data : { image : img.attr('src'), userid: "VALUE", locationid: "VALUE"}, success : function(){ img.parent().fadeOut('slow'); delete.php <?php session_start(); if (!empty($_POST)) { $originalimage = $_POST['image']; if (file_exists($originalimage)) { unlink($originalimage); } } $path_parts = pathinfo($originalimage); $dir = $path_parts['dirname']; $basename = $path_parts['basename']; ?> <?php $newimage = $basename; $dom = new DomDocument(); $dom->load('UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/' . 'files.xml'); $root = $dom->documentElement; $images = $root->getElementsByTagName("file"); $length = $images->length; //Iterate backwards by decrementing the loop counter for ($i=$length-1;$i>=0;$i--) { $p = $images->item($i); $pid = $p->getAttribute("name"); if ($pid == $newimage) { $parent = $p->parentNode; $parent->removeChild($p); } } $dom->save('UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/' . 'files.xml'); ?>
  25. I wonder whether someone may be able to help me please. The code below is a script which creates a gallery of images. <?php session_start(); $_SESSION['userid']=$_POST['userid']; $_SESSION['locationid']=$_POST['locationid']; ?> <?php $galleryPath = 'UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/'; $absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR; $descriptions = new DOMDocument('1.0'); $descriptions->load($absGalleryPath . 'files.xml'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=0.3"> <title>Galleria Twelve Theme</title> <style> /* Demo styles */ html,body{background:#eee;margin:0;} .content{color:#777;font:12px/1.4 "helvetica neue",arial,sans-serif;width:820px;margin:20px auto;} h1{font-size:12px;font-weight:normal;color:#222;margin:0;} p{margin:0 0 20px} a {color:#22BCB9;text-decoration:underline;} .cred{margin-top:20px;font-size:11px;} /* This rule is read by Galleria to define the gallery height: */ #galleria{height:420px;} </style> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery-ui-1.8.19.custom.min.js"></script> <script src="galleria/galleria-1.2.7.min.js"></script> <script src="galleria/themes/twelve/galleria.twelve.min.js"></script> <script src="galleria/plugins/history/galleria.history.min.js"></script> <link rel="stylesheet" href="galleria/themes/twelve/galleria.twelve.css"> <style> .galleria-thumbnails .btn-delete { display: block; /* Or just use a div instead of a span*/ position: absolute; bottom : 0px; /*align at the bottom*/ width: 80px; height: 17px; cursor: pointer; background: url(trash8.gif) no-repeat bottom; } </style> <script type="text/javascript"> Galleria.ready(function() { this.$('thumblink').click(); $(".galleria-image").append( "<span class='btn-delete ui-icon ui-icon-trash'></span>"); $(".btn-delete").live("click", function(){ var img = $(this).closest(".galleria-image").find("img"); // send the AJAX request $.ajax({ url : 'delete.php', type : 'post', data : { image : img.attr('src') }, success : function(){ alert('Deleting image... '); img.parent().fadeOut('slow'); } }); return false; }); }); </script> </head> <body> <ul id="navigation"> <li class="left"> <div align="center"><a href="javascript:document.viewimages.submit()" class="style2">← Add Images</a></div> </li> </ul> <form id="viewimages" name="viewimages" class="page" action="index.php" method="post"> <input name="userid" type="hidden" value="<?php echo $_SESSION['userid']; ?>"> <input name="locationid" type="hidden" value="<?php echo $_SESSION['locationid']; ?>"></form> <div class="content"> <h1>Galleria Twelve Theme</h1> <p>Demonstrating a simple example.</p> <!-- Adding gallery images. We use resized thumbnails here for better performance, but it’s not necessary --> <div id="galleria"> <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) : $xmlFile = $descriptions->documentElement->childNodes->item($i); $name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8'); $description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8'); $source = $galleryPath . rawurlencode($xmlFile->getAttribute('source')); ?> <a href="<?php echo $source; ?>"><img data-title="<b>Image Name: </b> <?php echo $name; ?>" data-description="<b>Description:</b> <?php echo $description; ?>" src="<?php echo $source; ?>"></a> <?php endfor; ?> </body> </html> The problem I'm having lies in the section of code which starts: <script type="text/javascript"> Galleria.ready(function() { this.$('thumblink').click(); This section deals with the deletion of each image, capturing the onlclick, loading the 'delete.php' file for the actual deltion of the physical image from the server. This 'delete.php' files is as follows: <?php session_start(); $_SESSION['userid']=$_POST['userid']; $_SESSION['locationid']=$_POST['locationid']; if (!empty($_POST)) { $image = $_POST['image']; if (file_exists($image)) { unlink($image); } } ?> What I'm trying to do, and having great difficulty in doing is passing the value of the 'userid' and 'locationid' fields to the 'delete.php' script, as these will be used to create a file path so that XML file can be loaded and changed. I've tried using adding 'json' as the 'data type', then added the variable names at the end of the 'data:' line, all without success, but I'm not sure whether the issue is in the sending of the values from my gallery page or the receipt of the information in 'delete.php'. I just wondered whether someone could perhaps have a look at this please and provide guidance on the correct way to send and receive this information.
×
×
  • 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.