Jump to content

barbs75

Members
  • Posts

    97
  • Joined

  • Last visited

    Never

Everything posted by barbs75

  1. Hi, Yes, i didn't post all my code, just the code related to the problem really. I do have a div called bedrooms! i do actually have the code working in another instance, on the same page, where it is activated when a user selects number of bedrooms from a drop down box. This then generates the number of bedrooms needed. What i'm trying to do is have a 'edit property' function, where the user can go through the steps again and edit the property they had entered. So trying to make all the data appear when they go to the page, hence trying to run this script......do you get me?!? hope its all clear can anyone spot any other errors anywhere? cheers Craig
  2. Hey lemmin, cheers for getting back to me. Well, i used that clone script from someone else on another forum, it does seem rather complex i must admit!! But it worked rather well, and i'm not too skilled javaScript yet, so i left it as that..... I do not get an error when the script is run, the alerts pop up, so the function is being called, but nothing is happening. It might not be finding the 'bedrooms' div correctly i feel, so it might be doing all the code, but can't find the div to place it in?!?! cheers Craig
  3. Hey guys, I have a javascript function which is cloning fields on a php form that i have on my site, this function is as follows: <script type="text/javascript"> /*<![CDATA[*/ function create_fields(nr,roomType){ alert(roomType); var root=document.getElementById(roomType); var allB=[], allD=root.getElementsByTagName('div'), i=0, d; // set the collection of the elements with className=inputfield while(d=allD[i++]){ d.className=='inputfield'?allB[allB.length]=d:null; } //removes all the elements, except the first for(var j=allB.length-1;j>=1;j--){ allB[j].parentNode.removeChild(allB[j]); } if(nr==1){return}//stops if a single bedroom is selected var clone;//the clone var tags={'label':['for'],'input':['id','name'],'textarea':['id','name'],'p':[null]} var obj, o, m, a, c; for(var k=2;k<nr+1;k++){ clone=allB[0].cloneNode(true); for(p in tags){ obj=clone.getElementsByTagName(p);m=0; while(o=obj[m++]){ for(var q=0;q<tags[p].length;q++){ if(p=='p'&&o.className=='largeblack'){ c=o.getElementsByTagName('strong')[0].firstChild; c.nodeValue=c.nodeValue.replace(/_1/,'_'+k); } else if(p!='p'){ a=o.getAttribute(tags[p][q]); o.setAttribute(tags[p][q],a.replace(/1/,k)); } } } } root.appendChild(clone); } } /*]]>*/ </script> What i am trying to do is call this function within my page, which is shown below: <SCRIPT LANGUAGE='javascript'> create_fields('3','bedrooms'); </SCRIPT> What the function does is clone my bedroom field, the code of which is shown below: <div class="inputfield"> <p class="largeblack"><strong>Bedroom_1</strong></p> <div class="dimensions"> <label class="room" for="bedrooms[1][]">Dimensions:<br/> <span class="textSmallGreen">(in feet)</span> </label> <input class="open" name="bedrooms[1][]" id="bedrooms[1][]" type="text" size="5" value="" /> x <input class="open" name="bedrooms[1][]" id="bedrooms[1][]" type="text" size="5" value="" /> </div> <div class="descriptionHolder"> <label class="room" style="width:90px;" for="bedrooms[1][]">Description:<br/> <span class="textSmallGreen">(max. 100 words)</span> </label> <textarea class="open" name="bedrooms[1][]" id="bedrooms[1][]" size="100" cols="35" rows="5">Enter your description here..... </textarea> </div> </div> </div> It then finds the 'bedrooms' div and places the cloned html into that div. When the script is run though, it doesn't do anything. I have placed alerts within the javascript function to test if it is actually calling the function, and it is. I really can't figure out where i am going wrong, can anyone help me out? see where i could be going wrong? cheers guys, appreciate it Craig
  4. ahh crap!!! Sorry man, i'm just SO used to going into PHP forums i completely forgot!! I will move it pronto! Craig
  5. Hey guys, I have a javascript function which is cloning fields on a php form that i have on my site, this function is as follows: <script type="text/javascript"> /*<![CDATA[*/ function create_fields(nr,roomType){ alert(roomType); var root=document.getElementById(roomType); var allB=[], allD=root.getElementsByTagName('div'), i=0, d; // set the collection of the elements with className=inputfield while(d=allD[i++]){ d.className=='inputfield'?allB[allB.length]=d:null; } //removes all the elements, except the first for(var j=allB.length-1;j>=1;j--){ allB[j].parentNode.removeChild(allB[j]); } if(nr==1){return}//stops if a single bedroom is selected var clone;//the clone var tags={'label':['for'],'input':['id','name'],'textarea':['id','name'],'p':[null]} var obj, o, m, a, c; for(var k=2;k<nr+1;k++){ clone=allB[0].cloneNode(true); for(p in tags){ obj=clone.getElementsByTagName(p);m=0; while(o=obj[m++]){ for(var q=0;q<tags[p].length;q++){ if(p=='p'&&o.className=='largeblack'){ c=o.getElementsByTagName('strong')[0].firstChild; c.nodeValue=c.nodeValue.replace(/_1/,'_'+k); } else if(p!='p'){ a=o.getAttribute(tags[p][q]); o.setAttribute(tags[p][q],a.replace(/1/,k)); } } } } root.appendChild(clone); } } /*]]>*/ </script> What i am trying to do is call this function within my page, which is shown below: <SCRIPT LANGUAGE='javascript'> create_fields('3','bedrooms'); </SCRIPT> What the function does is clone my bedroom field, the code of which is shown below: <div class="inputfield"> <p class="largeblack"><strong>Bedroom_1</strong></p> <div class="dimensions"> <label class="room" for="bedrooms[1][]">Dimensions:<br/> <span class="textSmallGreen">(in feet)</span> </label> <input class="open" name="bedrooms[1][]" id="bedrooms[1][]" type="text" size="5" value="" /> x <input class="open" name="bedrooms[1][]" id="bedrooms[1][]" type="text" size="5" value="" /> </div> <div class="descriptionHolder"> <label class="room" style="width:90px;" for="bedrooms[1][]">Description:<br/> <span class="textSmallGreen">(max. 100 words)</span> </label> <textarea class="open" name="bedrooms[1][]" id="bedrooms[1][]" size="100" cols="35" rows="5">Enter your description here..... </textarea> </div> </div> </div> It then finds the 'bedrooms' div and places the cloned html into that div. When the script is run though, it doesn't do anything. I have placed alerts within the javascript function to test if it is actually calling the function, and it is. I really can't figure out where i am going wrong, can anyone help me out? see where i could be going wrong? cheers guys, appreciate it Craig
  6. hey guys, Thanks for your reply, its a bit of a no-brainer to be honest, but I have never had to jump back through directories before!! So cheers for the help! Cheers Craig
  7. hey guys, I'm having a slight problem to do with directories..... i have my login script within a folder called 'function' so when the login page is called, it goes: /function/login.php so when i try redirecting to a page not in this directory it can't find it, because it isn't the same directory as the login script, say if i was trying to redirect to index.php it would do the following: /function/index.php does anyone know how i go back through a directory?? cheers for your help guys Craig
  8. hey guys, cheers for your overwhelming response!! you were all a great help thankyou!! I'm having a slight problem now to do with directories.... i have my login script within a folder called 'function' so when the login page is called, it goes: /function/login.php so when i try redirecting to a page not in this directory it can't find it, because it isn't the same directory as the login script, say if i was trying to redirect to index.php it would do the following: /function/index.php does anyone know how i go back through a directory?? cheers for your help guys Craig
  9. Hey guys, The problem i am having is with navigating back to a previous page in php... What i am trying to do is, when a user tries to go to a certain page, they have to be logged in, otherwise they can't access it. So what i do is check that the user is logged on, if they are not then they are directed to my login page where they can log in. But in my script i have a header which directs them to the profile page, but i dont want them to go there, i want them to be directed back to the page that they were TYRING to access.... I really can't figure out how to do this.....searched google and stuff too, but nothing comes up in the example i am trying to do.. Can anyone give me insight on how to do this?? cheers Craig
  10. hey phpzone, i have solved the problem, i did some reading on php.net and found out how to count the amount of elements in the $_POST['extraroom'] array, which i could then assign to my for loop to loop through each first dimensional element, and then place each element of that into my database fields!! problem solved! just needed to find a way to count the array elements, i didnt realise that yo could do this with $_POST, but i guess its just like any other array!! cheers for your insight and help!! Craig
  11. hi wolphie, cheers for your reply, looking at my example, you wouldn't know how i could refer to the variable 'count' in my javascript 'generate_room()' function, by applying ajax?? never really touched on ajax before..... or of you know your php, can i place a count on a button, to increment every time it is clicked? because that would solve my problem.... for example: <img style="float:right;" src="Images/addRoom.png" alt="add another room" onclick="<?php echo 'generate_room();';$clickCount++;?>" /> would that call my javascript function and then increment a counter everytime the image is clicked?? cheers Craig
  12. hey phpzone! right if you go to the url:http://www.go4home.co.uk/upload_stage2.php you can see the page, and you will see the button that i have been talking of a little way down the page do you have the web developer toolbar in your browser? if you dont, i recommend!! if you do, use the information option and display id & class details to see whats being produced when the button is clicked!! if you can help further that will be great!! one question, can you refer to a variable in a javascript function via php?? cause if i can, then i could be able to do what i want to do... cheers for your help dude Craig
  13. Hey guys, I'm really stuck with this, can't figure out how i go about doing this..... here's my problem. I have a form, which when submitted, sends all form data to a php processing script, which sends data to my database(mysql) and validates all entered data. The problem i am having is with a certain set of my input fields from my form... I have a button which has javascript assigned, which when they click a button, an extra room(with new input fields) are displayed on screen. The javascript is shown below: <script type="text/javascript"> var count = 0; function generate_room(){ count += 1; var num = count; document.getElementById('rooms').appendChild(create_inputfield(num)); document.getElementById('deleteRoom').style.visibility = 'visible'; return count; } //function to create inputfield div and all xhtml content inside function create_inputfield(num){ //create xhtml for inputfield element declaration var inputfield = document.createElement('div'); var divClassName = 'inputfield';//set classname inputfield.className = divClassName;//add class and class name to inputfield var inputfieldContent = '<p class="largeblue"><strong>Added Room '+num+'</strong></p><label class="room" for="extraroom_name_'+num+'">Type:</label><select class="fade" name="roomType" id="extraroom['+num+'][]"><option class="fade">--Please Select--</option><option class="fade" value="study">Study</option><option class="fade" value="games">Games Room</option><option class="fade" value="Reception">Reception</option><option class="fade" value="conservatory">Conservatory</option></select><br /><br />';//variable containing xhtml content inputfield.innerHTML = inputfieldContent;//adds xhtml content to inputfield inputfield.appendChild(create_dimensiondiv(num));//adds on element created by function inputfield.appendChild(create_descriptionHolder(num));//adds on element created by function return inputfield;//return variable inputfield } //function to create dimensions div function create_dimensiondiv(num){ var dimensiondiv = document.createElement('div'); var divClassName = 'dimensions'; dimensiondiv.className = divClassName; dimensiondiv.innerHTML = '<label class="room" for="extraroom['+num+'][]">Dimensions:</label><input class="fade" name="extraroom_width_'+num+'" id="extraroom['+num+'][]" type="text" size="5" value="" /> x <input class="fade" name="extraroom['+num+'][]" id="extraroom['+num+'][]" type="text" size="5" value="" />'; return dimensiondiv; } //function to create descriptionHolder div function create_descriptionHolder(num){ var descriptionHolder = document.createElement('div'); var divClassName = 'descriptionHolder'; descriptionHolder.className = divClassName; descriptionHolder.innerHTML = '<label class="room" for="extraroom['+num+'][]">Description:</label><textarea name="extraroom['+num+'][]" id="extraroom['+num+'][]" cols="35" rows="5">Enter your description here.....</textarea>'; return descriptionHolder; } function remove_room(theClass) { var allPageTags = document.getElementById('rooms').getElementsByTagName("*"); for(var i=allPageTags.length-1;i>=0;i--){ if(allPageTags[i].className==theClass){ allPageTags[i].parentNode.removeChild(allPageTags[i]);break } } } </script> This code generates input names of 'extraroom[0][]' with the first array key incrementing depending on how many times the add room button is clicked. For example, if the user wants to add 3 rooms, (they click the button 3 times), the following array would be created: extraroom[0][width,length,description] extraroom[1][width,length,description] extraroom[2][width,length,description] now i am having problems with iterating through these post data using foreach, i can't use standard for loop, as i dont know how long the array is going to be, so not efficient to just run the loop for a certain amount times...... the code i have at the moment is..... foreach($_POST['extraroom'] as $key){ mysql_query("INSERT INTO rooms (house_id,user_id,room_name,room_width,room_length,description) VALUES ('$house_id','$user_id','".$_POST['extraroom'][$key][0]."','".$_POST['extraroom'][$key][1]."','".$_POST['extraroom'][$key][2]."','".$_POST['extraroom'][$key][3]."')"); } The first few table entries work fine, ie the house_id,user_id, but then i am struggling to refer to each of the elements i have for each extra room...... would anyone know how i go about doing this at all, really stumped cheers Craig
  14. Hey littledragon, the variable $no_of_bed is stored earlier on in my form processing script, which is taken from POST data from my form, here's the script for the processing page: <?php //turn on sessions session_start(); header("Cache-control: private"); //checking if user is logged in, if not send them to login screen if (!$_SESSION['username']) { include("login_form.php"); exit(); } //include database connections and email functions include('database.php'); include('email_fns.php'); //input username session info into variable $username = $_SESSION['username']; $detailserrorcount = 0; $detailserrorarray = array(); $detailsdataarray = array(); //load data from SESSION data $username = $_SESSION['username']; $user_id = $_SESSION['user_id']; //load posted data from form into local variables //load in house general info $property_type = $_POST['propertyType']; $status = $_POST['status']; $price = $_POST['price']; $no_of_bed = $_POST['noofbed']; $no_of_bath = $_POST['noofbath']; //laod in default room information //living room $livingroom_width = $_POST['livingroom_width']; $livingroom_length = $_POST['livingroom_length']; $livingroom_desc = $_POST['livingroom_desc']; //dining room $diningroom_width = $_POST['diningroom_width']; $diningroom_length = $_POST['diningroom_length']; $diningroom_desc = $_POST['diningroom_desc']; $bedroom_width = array(); $bedroom_length = array(); $bedroom_desc = array(); //load in bedrooms information for($i=1;$i<=$no_of_bed;$i++){ $bedroom_width[$i] = $_POST['bedroom_width_'.$i]; $bedroom_length[$i] = $_POST['bedroom_length_'.$i]; $bedroom_desc[$i] = $_POST['bedroom_desc_'.$i]; } echo 'the value of bedroom_width_1 variable is'. $bedroom_width_1; ?> cheers Craig
  15. Hey guys, I'm having a little problem with my form... What i have is some javascript which allows a user to click to 'add a room' onto my submit page which creates this HTML for each added room: <div class="inputfield"> <p class="largeblue"><strong>Bedroom_1</strong></p> <div class="dimensions"> <label class="room" for="bedroom_width_1">Dimensions:</label> <input class="fade" name="bedroom_width_1" id="bedroom_width_1" type="text" size="5" value="" /> x <input class="fade" name="bedroom_length_1" id="bedroom_length_1" type="text" size="5" value="" /> </div> <div class="descriptionHolder"> <label class="room" for="bedroom_desc_1">Description:</label> <textarea name="bedroom_desc_1" id="bedroom_desc_1" cols="35" rows="5">Enter your description here..... </textarea> </div> </div> When they add more rooms, the number at the end for the 'id' values for each input/textarea, are incremented, so if the user added 2 rooms, the HTML for the input fields for 'bedroom_width' would be as follows: <input class="fade" name="bedroom_width_1" id="bedroom_width_1" type="text" size="5" value="" /> x <input class="fade" name="bedroom_length_1" id="bedroom_length_1" type="text" size="5" value="" /> <input class="fade" name="bedroom_width_2" id="bedroom_width_2" type="text" size="5" value="" /> x <input class="fade" name="bedroom_length_2" id="bedroom_length_2" type="text" size="5" value="" /> Now, what i am struggling with is how to process this data in these post data to then validate, and enter into my database. I dont really know how i would do this?? i have tried doing this using an array to store the widths, heights and descriptions for each room. Here is the code i came up with: $bedroom_width = array(); $bedroom_length = array(); $bedroom_desc = array(); //load in bedrooms information for($i=1;$i<=$no_of_bed;$i++){ $bedroom_width[$i] = $_POST['bedroom_width_'.$i]; $bedroom_length[$i] = $_POST['bedroom_length_'.$i]; $bedroom_desc[$i] = $_POST['bedroom_desc_'.$i]; } but when i use an echo to see the value of one of the array elements, there is nothing there! The technique that i have used for referencing to the post data, i have seen used for a SESSION variable, but it is not working here!! any idea how i would go about doing this? or is there something wrong with my code?? i really can't find any examples of this kind of thing on the net, but surely there must be a simple way of doing this?? cheers guys Craig
  16. Hey guys, Wasn't sure which forum to post this in, so i went with this one!!! Right, what i'm trying to do is have one of those features on a form, where you can click a button saying 'is your billing address the same as your home address?' and then if you click on it, it copies the data into the fields for you. I have a page on my user profile system, where the user can update their home address, which is then stored in my database, and stored in php $_SESSION data. I then have a house upload page, where the user can upload a house to sell, where they have to enter the address of the house they are selling, the house might not be teh same as their home address, or it might be. So i want to give the option of clicking a button to copy the session variables into the fields automatically if their billing address is the same. Is Javascript teh best way to do this? and can javascript read in the data from the php sessions and put them in the text fields??? I'm sure this is a really simple procedure, it is quite a common function on forms that i have seen on the web, if anyone can help me out, or know any examples etc, any help will be welcomed!! cheers guys Craig
  17. Hey guys, Right, what i'm trying to do is have one of those features on a form, where you can click a button saying 'is your billing address the same as your home address?' and then if you click on it, it copies the data into the fields for you. I have a page on my user profile system, where the user can update their home address, which is then stored in my database, and stored in php $_SESSION data. I then have a house upload page, where the user can upload a house to sell, where they have to enter the address of the house they are selling, the house might not be teh same as their home address, or it might be. So i want to give the option of clicking a button to copy the session variables into the fields automatically if their billing address is the same. Is Javascript teh best way to do this? and can javascript read in the data from the php sessions and put them in the text fields??? I'm sure this is a really simple procedure, it is quite a common function on forms that i have seen on the web, if anyone can help me out, or know any examples etc, any help will be welcomed!! cheers guys Craig
  18. Hey guys, Right, i have an issue regarding generating xhtml dynamically, depending on the value selected from a dropdown menu. This is the XHTML of the inputfield that i have: <div class="inputfield"> <label class="title" for="noofbed">No. of Bedrooms:</label> <select class="fade" name="noofbed" id="noofbed" onchange="create_fields(this.value)"> <option class="fade" value="select">--Please Select--</option> <option class="fade" value="1">One</option> <option class="fade" value="2">Two</option> <option class="fade" value="3">Three</option> <option class="fade" value="4">Four</option> <option class="fade" value="5">Five</option> <option class="fade" value="6">Six</option> </select> </div> When the value of the dropdown box is changed, it calls the function 'create_fields(bedrooms)', the javascript of which is shown below: //function to create bedroom fields needed function create_fields(bedrooms){ //loops through each bedroom until all bedrooms are processed for(var i=1; i<=bedrooms; i++){ document.getElementById('bedrooms').appendChild(create_inputfield(i));//find submitCustomerForm and add inputfield } } the function above uses the following javascript functions: //function to create inputfield div and all xhtml content inside function create_inputfield(num){ //create xhtml for inputfield element declaration var inputfield = document.createElement('div'); var divClassName = 'inputfield';//set classname inputfield.setAttribute('class',divClassName);//add class and class name to inputfield var inputfieldContent = '<p class="largeblue"><strong>Bedroom '+num+'</strong></p>';//variable containing xhtml content inputfield.innerHTML = inputfieldContent;//adds xhtml content to inputfield inputfield.appendChild(create_dimensiondiv(num));//adds on element created by function inputfield.appendChild(create_descriptionHolder(num));//adds on element created by function return inputfield;//return variable inputfield } //function to create dimensions div function create_dimensiondiv(num){ var dimensiondiv = document.createElement('div'); var divClassName = 'dimensions'; dimensiondiv.setAttribute('class', divClassName); dimensiondiv.innerHTML = '<label class="room" for="bedroom'+num+'_width">Dimensions:</label><input class="fade" name="bedroom'+num+'_width" id="bedroom'+num+'_width" type="text" size="5" value="" /> x <input class="fade" name="bedroom'+num+'_length" id="bedroom'+num+'_length" type="text" size="5" value="" />'; return dimensiondiv; } //function to create descriptionHolder div function create_descriptionHolder(num){ var descriptionHolder = document.createElement('div'); var divClassName = 'descriptionHolder'; descriptionHolder.setAttribute('class', divClassName); descriptionHolder.innerHTML = '<label class="room" for="bedroom'+num+'_desc">Description:</label><textarea name="bedroom'+num+'_desc" id="bedroom'+num+'_desc" cols="35" rows="5">Enter your description here.....</textarea>'; return descriptionHolder; } The XHTML code that is reproduced for each bedroom that is selected is as follows: <div class="inputfield"> <p class="largeblue"><strong>Dining Room</strong></p> <div class="dimensions"> <label class="room" for="diningroom_width">Dimensions:</label> <input class="fade" name="diningroom_width" id="diningroom_width" type="text" size="5" value="" /> x <input class="fade" name="diningroom_length" id="diningroom_length" type="text" size="5" value="" /> </div> <div class="descriptionHolder"> <label class="room" for="diningroom_desc">Description:</label> <textarea name="diningroom_desc" id="diningroom_desc" cols="35" rows="5">Enter your description here.....</textarea> </div> </div> This all works fine, however the issue i am having, is with removing the fields. I want to be able to do this on the fly when the user selects the number of bedrooms from the dropdown. For example, if a user selects 3 bedrooms from the dropdown, 3 inputfield divs are created with all the content. But if the user then accidentally makes a boobie, and didn't mean to put in 3, but 2, then when they select '2 bedrooms' from the dropdown, the previous content for 3 bedrooms gets removed and then the 'create_fields()' function is executed. How would i go about doing this? i had an idea where i would add a function called 'remove_fields()', the javascript of which is shown below: function remove_fields(bedrooms){ for(var i=1; i<=bedrooms; i++){ //var b = document.getElementById('bedrooms'); var oldb = document.getElementByClass('inputfield'); removeChild(oldb); } } This function is called within 'create_fields()' function, before the for loop is executed to generate the fields, this is shown in the code below: //function to create bedroom fields needed function create_fields(bedrooms){ //first remove previous inputfields if there are any document.getElementById('bedrooms').removeChild(remove_fields(bedrooms));//<------INSERTED LINE TO REMOVE FIELDS //loops through each bedroom until all bedrooms are processed for(var i=1; i<=bedrooms; i++){ document.getElementById('bedrooms').appendChild(create_inputfield(i));//find submitCustomerForm and add inputfield } } This doesn't work however, when the code is executed, even the fields that should be generated aren't added, i have looked on google with examples of how to do this, but what i have tried to thsu far, just doesn't work!! the url for the working page is at http://www.go4home.co.uk/upload_stage2.php If someone can see any errors in my code, or give me some pointers of how to this, that would be great cheers guys Craig
  19. Hey wrongmove, cheers for your reply dude!! I started doing it a different way, as shown below: <script type="text/javascript"> function addElement()//function to add a textfield to the form { var selectednumber=document.getElementById("noofbed").value; if(selectednumber!="select") { var ni = document.getElementById('submitCustomerForm'); var numi = document.getElementById('noofbed'); var num = document.getElementById('noofbed').value; var myCounter = 1; //numi.value = num; var newdiv = document.createElement('div'); var divClassName = 'inputfield'; newdiv.setAttribute('class',divClassName); //while loop to cycle through depending on number of bedrooms while(myCounter < num) { ni.appendChild(newdiv); //var ni2 = document.getElementByClass('divClassName'); //now add textfield to inputfield div //var newinput = document.createElement('input'); //var inputClassName = 'fade'; //newinput.setAttribute('class',inputClassName); //ni2.appendChild(newinput); var fieldDisplay = '<p class="largeblue"><strong>Bedroom '+myCounter+'</strong></p><div class="dimensions"><label class="room" for="bedroom'+myCounter+'_width">Dimensions:</label><input class="fade" name="bedroom'+myCounter+'_width" id="bedroom'+myCounter+'_width" type="text" size="5" value="" /> x <input class="fade" name="bedroom'+myCounter+'_length" id="bedroom'+myCounter+'_length" type="text" size="5" value="" /></div><div class="descriptionHolder"><label class="room" for="bedroom'+myCounter+'_desc">Description:</label><textarea name="bedroom'+myCounter+'_desc" id="bedroom'+myCounter+'_desc" cols="35" rows="5">Enter your description here.....</textarea></div><p class="largeblue"><strong>Counter is '+myCounter+'</strong></p>'; newdiv.innerHTML = fieldDisplay; myCounter++; } } } </script> what i'm trying to do is, if a user clicks 3 bedrooms, then 3 of the divs that are created from the variable fieldDisplay using innerHTML should appear. I can get one to appear, and the bedroom number appears fine, but only one displays, when obviously for 3 bedrooms i want three to appear? would you know how i can do that with the technique that i have used? or would i have to use something like what you have done in the example you have given me?? if you want to see the page, hit this link, use the number of bedrooms drop down box and you will see what i mean, it might be easier to see it with your own eyes!! http://www.go4home.co.uk/upload_stage2.php cheers mate, hope you can help me!!! Craig
  20. Hey guys, What i want to achieve is to create additional text fields on my submission form, depending on the value that is selected from a drop down box. In this case it is for submitting house details. So when a user selects number of bedrooms, input text fields for dimensions and description appear for each bedroom that house has according the number selected from the dropdown. This has to be done using javaScript, which i'm not too familiar with, i'm more experiences with php. I am trying to integrate this function within a php page, and i'm using dreamweaver cs3 as my coding tool (only using coding screen and no other tools) the pseudo code for the functionality i need is: drop down box select 2 bedrooms output generated bedroom 1: dimensions:----- x ----- description: blah blah blah........... can anyone give me any insight in how to go about doing this? i have searched this forum, but failed to find any threads related to this, also have googled, but can only find really complicated versions which i just cant grasp, or you have to pay to subscribe to view the tutorials, PAIN!!! cheers Craig
  21. Hey guys, I have checked in google and on this forum for answers to my question but haven't found anything regarding validating each step of a multipage form, hence my post! I wonder if anyone can help me, or rather provide me with advice.... I am trying to create a multipage form, which so far i have done a basic one which i have done using my php cookbook by O'Reilly which is a very basic version, without any validations or anything.... My multipage has 3 steps: Step1: user details - takes users name, email etc Step 2: House details - Takes users address, house type, no of rooms, descriptions of rooms etc Step 3: Image upload - Allows user to upload 3 images max to display (using my original file upload script) As i said, my basic multipage form works, storing all posted values into sessions which can then be outputted at the end in a review page, which will be at the end of the form. In previous forms i have created, i always have an html form, which when posted or submitted, has an action of a separate php script which processes the form and validates it, sends email, updates database etc, and all errors are then stored in sessions and appear back on the form page until there are no errors displayed and then a success page is shown.... so the code i have taken from my cookbook doesn't seem to be able to allow me to validate EACH STEP of the form? it can validate at the end, when the user reviews and then the form is processed all in one go. But i want to be able to validate form entries at each step, rather than in one go. For example if a user leaves their 'town' field empty, an error message will be displayed before going to the next step... If you see the code i have done so fare below: <?php //Figure out what stage to use if (($_SERVER['REQUEST_METHOD'] == 'GET') || (! isset($_POST['stage']))) { $stage = 1; } else { $stage = (int) $_POST['stage']; } //Save any submitted data if ($stage > 1) { foreach ($_POST as $key => $value) { $_SESSION[$key] = $value; } } if ($stage ==1) {?> <div id="submitCustomerForm"> <FORM ACTION='<?php echo $_SERVER['SCRIPT_NAME'] ?>' method='post'> <h7>Your details</h7> <br /> <div id="inputfield"> <label class="textleft" for="forename">forename:</label> <input class="fade" name="forename" type=text size="30" align="right" maxlength="15" id="forename" value="<?php echo $_SESSION['forename']?>"> </div> <div id="inputfield"> <label class="textleft" for="surname">surname:</label> <input class="fade" name="surname" type=text size="30" maxlength="15" id="surname" align="right" value="<?php echo $_SESSION['surname']?>"> </div> <div id="inputfield"> <label class="textleft" for="email">email:</label> <input class="fade" name="email" type=text size="30" maxlength="30" align="right" id="email" value="<?php echo $_SESSION['email']?>"> </div> <br /> <h7>Your property Address</h7> <br /> <div id="inputfield"> <label class="textleft" for="address1">Address Line 1:</label> <input class="fade" name="address1" type=text size="30" maxlength="30" id="address1" value="<?php echo $_SESSION['address1'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="address2">Address Line 2:</label> <input class="fade" name="address2" type=text size="30" maxlength="30" id="address2" value="<?php echo $_SESSION['address2'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="town">Town/City:</label> <input class="fade" name="town" type=text size="30" maxlength="30" id="town" value="<?php echo $_SESSION['town'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="county">County:</label> <input class="fade" name="county" type=text size="30" maxlength="30" id="county" value="<?php echo $_SESSION['county'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="postcode">Post Code:<span class="asterix">*</span></label> <input class="fade" name="postcode" type=text size="30" maxlength="30" id="postcode" value="<?php echo $_SESSION['postcode'];?>" /> </div> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input name="Next" class="submit" type="image" align ="right" src="Images/updateButton.png" /> </FORM> </div> <?php } else if ($stage == 2) { ?> <div id="submitCustomerForm"> <FORM ENCTYPE="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <div id="divinputfile"> <input name="userfile" type="file" size="30" id="userfile" onchange="document.getElementById('fakeuserfile').value = this.value;"/> <div id="fakeinputfile"><input name="fakeuserfile" type="text" id="fakeuserfile" /></div> </div> <br /> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input type="image" src="Images/upload.png" align="right" name="Send File" /> <br /> <br /> </FORM> </div> <?php } else if ($stage == 3) {?> <p class="largeblue"> hello there <?php echo $_SESSION['forename']; echo $_SESSION['surname'];?> <br /> the first line of your address is: <?php echo $_SESSION['address1'];?> <br /> the second line of your address is: <?php echo $_SESSION['address2'];?> </p> <?php } ?> For the 'form action' it uses meaning that the form reloads the page, upon which the stage number has changed and therefore loads next step. Where as normally, i have the path for my process script which would handle validation etc and then send them to a success screen or back to the form displaying errors. I propose a few ideas that i could do to get around this, which i just wanted to get a bit of insight on, as to which way of going about this is the right one!! My first idea would be to treat each step of the form as a separate form almost. Doing a form as i normally do, where the form is on one page, then the completed form is sent to a processing page, which processes the entries, sends user back to the form page with errors if there are any, or if it is all ok, increase the 'stage number' in a session and then use a header to go to next page(the next step of the form. at the top of each page is a check to whether the stage number is the same as the step number of the form. OR would i put all my validation in one page, with all the steps of the form as i have at the moment? OR is there a way to send each step of the form to a process script, which then sends the user back to the original form displaying errors if there are any or then moves them to the next step?? Just a little confused with which method to do this, i dont want to start working on it and find out i have done it completely the wrong way!! any help would be greatly received, thanks guys!! Craig
  22. solved, found another example, taken from the following url: http://www.phpit.net/code/valid-email/ checks for domain present!
  23. Hi guys, i have adapted the email validation system that is shown in the 'php cookbook' by O'Reilly, which uses rules from RFC 2822. This example is created by Cal Henderson. Now the function works fine, until i enter an email address without a domain for example: without the '.com' on the end, and the function accepts this email address as valid, when it surely shouldn't?? You can see the code that i used from the following link: http://code.iamcal.com/php/rfc822 the code that i have written into my system is as follows: <?php # # RFC(2)822 Email Parser # # By Cal Henderson <cal@iamcal.com> # This code is licensed under a Creative Commons Attribution-ShareAlike 2.5 License # http://creativecommons.org/licenses/by-sa/2.5/ # # $Revision: 1.1 $ # ################################################################################## function is_valid_email_address($email){ #################################################################################### # # NO-WS-CTL = %d1-8 / ; US-ASCII control characters # %d11 / ; that do not include the # %d12 / ; carriage return, line feed, # %d14-31 / ; and white space characters # %d127 # ALPHA = %x41-5A / %x61-7A ; A-Z / a-z # DIGIT = %x30-39 $no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]"; $alpha = "[\\x41-\\x5a\\x61-\\x7a]"; $digit = "[\\x30-\\x39]"; $cr = "\\x0d"; $lf = "\\x0a"; $crlf = "($cr$lf)"; #################################################################################### # # obs-char = %d0-9 / %d11 / ; %d0-127 except CR and # %d12 / %d14-127 ; LF # obs-text = *LF *CR *(obs-char *LF *CR) # text = %d1-9 / ; Characters excluding CR and LF # %d11 / # %d12 / # %d14-127 / # obs-text # obs-qp = "\" (%d0-127) # quoted-pair = ("\" text) / obs-qp $obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]"; $obs_text = "($lf*$cr*($obs_char$lf*$cr*)*)"; $text = "([\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|$obs_text)"; $obs_qp = "(\\x5c[\\x00-\\x7f])"; $quoted_pair = "(\\x5c$text|$obs_qp)"; #################################################################################### # # obs-FWS = 1*WSP *(CRLF 1*WSP) # FWS = ([*WSP CRLF] 1*WSP) / ; Folding white space # obs-FWS # ctext = NO-WS-CTL / ; Non white space controls # %d33-39 / ; The rest of the US-ASCII # %d42-91 / ; characters not including "(", # %d93-126 ; ")", or "\" # ccontent = ctext / quoted-pair / comment # comment = "(" *([FWS] ccontent) [FWS] ")" # CFWS = *([FWS] comment) (([FWS] comment) / FWS) # # note: we translate ccontent only partially to avoid an infinite loop # instead, we'll recursively strip comments before processing the input # $wsp = "[\\x20\\x09]"; $obs_fws = "($wsp+($crlf$wsp+)*)"; $fws = "((($wsp*$crlf)?$wsp+)|$obs_fws)"; $ctext = "($no_ws_ctl|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])"; $ccontent = "($ctext|$quoted_pair)"; $comment = "(\\x28($fws?$ccontent)*$fws?\\x29)"; $cfws = "(($fws?$comment)*($fws?$comment|$fws))"; $cfws = "$fws*"; #################################################################################### # # atext = ALPHA / DIGIT / ; Any character except controls, # "!" / "#" / ; SP, and specials. # "$" / "%" / ; Used for atoms # "&" / "'" / # "*" / "+" / # "-" / "/" / # "=" / "?" / # "^" / "_" / # "`" / "{" / # "|" / "}" / # "~" # atom = [CFWS] 1*atext [CFWS] $atext = "($alpha|$digit|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])"; $atom = "($cfws?$atext+$cfws?)"; #################################################################################### # # qtext = NO-WS-CTL / ; Non white space controls # %d33 / ; The rest of the US-ASCII # %d35-91 / ; characters not including "\" # %d93-126 ; or the quote character # qcontent = qtext / quoted-pair # quoted-string = [CFWS] # DQUOTE *([FWS] qcontent) [FWS] DQUOTE # [CFWS] # word = atom / quoted-string $qtext = "($no_ws_ctl|[\\x21\\x23-\\x5b\\x5d-\\x7e])"; $qcontent = "($qtext|$quoted_pair)"; $quoted_string = "($cfws?\\x22($fws?$qcontent)*$fws?\\x22$cfws?)"; $word = "($atom|$quoted_string)"; #################################################################################### # # obs-local-part = word *("." word) # obs-domain = atom *("." atom) $obs_local_part = "($word(\\x2e$word)*)"; $obs_domain = "($atom(\\x2e$atom)*)"; #################################################################################### # # dot-atom-text = 1*atext *("." 1*atext) # dot-atom = [CFWS] dot-atom-text [CFWS] $dot_atom_text = "($atext+(\\x2e$atext+)*)"; $dot_atom = "($cfws?$dot_atom_text$cfws?)"; #################################################################################### # # domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] # dcontent = dtext / quoted-pair # dtext = NO-WS-CTL / ; Non white space controls # # %d33-90 / ; The rest of the US-ASCII # %d94-126 ; characters not including "[", # ; "]", or "\" $dtext = "($no_ws_ctl|[\\x21-\\x5a\\x5e-\\x7e])"; $dcontent = "($dtext|$quoted_pair)"; $domain_literal = "($cfws?\\x5b($fws?$dcontent)*$fws?\\x5d$cfws?)"; #################################################################################### # # local-part = dot-atom / quoted-string / obs-local-part # domain = dot-atom / domain-literal / obs-domain # addr-spec = local-part "@" domain $local_part = "($dot_atom|$quoted_string|$obs_local_part)"; $domain = "($dot_atom|$domain_literal|$obs_domain)"; $addr_spec = "($local_part\\x40$domain)"; # # we need to strip comments first (repeat until we can't find any more) # $done = 0; while(!$done){ $new = preg_replace("!$comment!", '', $email); if (strlen($new) == strlen($email)){ $done = 1; } $email = $new; } # # now match what's left # return preg_match("!^$addr_spec$!", $email) ? 1 : 0; } ?> anyone see where this could be going wrong? cheers Craig
  24. Hi Guys, i have an email validation system on my register script, which checks that the email that the user enters is valid, below is the code that i have used, saw this on a tutorial, and it works for missing '@' in the email and other 'junky' character entries if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ if($email){ $errorarray['email'] = "The email you have entered is not valid, please try again"; } } However, with this validation, i was able to enter and hence missing the extension on the end, which is obviously no good! Is there something missing from this code for it to do that? or should i avoid this technique all together and go with the normal longer function seen in php books etc Just wandering as the technique i have used is shorter and if i can use this, then its obviously more efficient! cheers Craig
×
×
  • 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.