adamjblakey Posted July 20, 2007 Share Posted July 20, 2007 Hi, What i am trying to do is when i press the check address button i want it to return the entries and automatically enter them in the relevant text field so e.g. you enter postcode and number and press enter the town and street etc get field in. What i cannot do at the moment though is get these value returned so i can echo them out in the right text field. It only returns all the values as one variable. This is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Registration Form</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> var AdminResponse = ""; function parseResponse(){ var nMessage = document.getElementById('echoMsg'); nMessage.style.display = ""; nMessage.innerHTML = AdminResponse; } function registerUser(){ var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); AdminRequest.onreadystatechange = function() { if (AdminRequest.readyState == 4) { if (AdminRequest.status == 200) { AdminResponse = AdminRequest.responseText; parseResponse(); } else { alert('Error lookup.php File '+ AdminRequest.statusText); } } } var nForm = document.forms[0]; var infoStr = "housenumber=" + nForm['housenumber'].value; infoStr += "&postcode=" + nForm['postcode'].value; AdminRequest.open("POST", "lookup.php", true); AdminRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded"); AdminRequest.send(infoStr); } function validate(nForm){ document.getElementById('echoMsg').style.display = 'none'; for (i=0; i<nForm.length; i++) { if (nForm[i].value == "") { alert('Please complete all fields'); return false; } } registerUser(); } </script> </head> <body> <div id='echoMsg' style='display:none'></div> <form action=""> <fieldset> <legend>Personal Information</legend> <label>House No : <input type='text' size='15' name='housenumber' class='formField'></label> <label>Postcode: <input type='text' size='15' name='postcode' class='formField'></label> <input type='button' name='submit' value="Submit" class='submitBtn' onClick="validate(this.form)"> </fieldset> </form> </body> </html> <?php include ("includes/top.php"); $postcode = str_replace( ' ', '', $_POST['postcode'] ); $ch = curl_init("http://postcodeloopup.php?postcode=$postcode"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $value = curl_exec($ch); preg_match_all('/<(Street|Locality|Town|TVRegion|Latitude|Longitude)>([^<]+)<\/\\1>/', $value, $matches); $street .= $matches[2][0]; $town .= $matches[2][1]; $region .= $matches[2][2]; $latitude .= $matches[2][3]; $longitude .= $matches[2][4]; $message = "House Number - " . $_POST['housenumber'] . "<br>"; $message .= "Postcode - " . $postcode. "<br>"; $message .= "Street - " . $street. "<br>"; $message .= "Town - " . $town. "<br>"; $message .= "Region - " . $region. "<br>"; $message .= "Latitude - " . $latitude. "<br>"; $message .= "Longitude - " . $longitude. "<br>"; echo stripslashes($message); ?> Cheers, Adam Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 20, 2007 Share Posted July 20, 2007 echo out the raw result from your curl request... look at that result and check that the method used to extract the relevant data is correct... Quote Link to comment Share on other sites More sharing options...
chigley Posted July 20, 2007 Share Posted July 20, 2007 http://postcodeloopup.php?postcode=$postcode That can't be right? Quote Link to comment Share on other sites More sharing options...
adamjblakey Posted July 20, 2007 Author Share Posted July 20, 2007 How would i echo the raw result in the main form? no it is not right.. i am using a postcode service of my own so i put a different url. Quote Link to comment Share on other sites More sharing options...
chigley Posted July 20, 2007 Share Posted July 20, 2007 $value = curl_exec($ch); echo $value; To see the output Quote Link to comment Share on other sites More sharing options...
adamjblakey Posted July 20, 2007 Author Share Posted July 20, 2007 Well this is what i have done it the lookup.php form $street .= $matches[2][0]; $town .= $matches[2][1]; $region .= $matches[2][2]; $latitude .= $matches[2][3]; $longitude .= $matches[2][4]; But i need to return the value back to the next page. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 20, 2007 Share Posted July 20, 2007 straight after $value = curl_exec($ch); put echo $value; or print_r($value) should be echo!!!! Quote Link to comment Share on other sites More sharing options...
adamjblakey Posted July 24, 2007 Author Share Posted July 24, 2007 Thanks for your replys i think i know what i need to do but i don't know how to do it. What i think i have to do is explode the results that are returned but i don't know how to do this. This is what i have done with the results: $message = $_POST['housenumber'] . "^"; $message .= $postcode. "^"; $message .= $street. "^"; $message .= $town. "^"; $message .= $region. "^"; $message .= $latitude. "^"; $message .= $longitude. "^"; echo stripslashes($message); And when this is returned to the main page i think i need to explode the results in this javascript function but don't how? function parseResponse(){ var nMessage = document.getElementById('echoMsg'); nMessage.style.display = ""; nMessage.innerHTML = AdminResponse; } example here: coolmove4u(dot)com/design/posttest.php Can anyone help me what i am supposed to do here? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.