damaya Posted June 17, 2010 Share Posted June 17, 2010 Hi guys, I am trying to figure out how to do something here in PHP... I have a form, with a box at the top where user can enter a domain name, under this box there is a submit button and then a bunch of boxes below the submit button for all the records related to that domain. I want a user to enter a domain, hit submit, PHP script looks up all records related to the domain, and then returns them back to main index.php and populates all the record fields below the submit button. Any guidance on how to do this would be appreciated. I can clarify further if needed, just let me know! Quote Link to comment Share on other sites More sharing options...
TOA Posted June 17, 2010 Share Posted June 17, 2010 if ($_SERVER['REQUEST_METHOD'] == "POST") { process } else { display } Like that? Quote Link to comment Share on other sites More sharing options...
TOA Posted June 17, 2010 Share Posted June 17, 2010 You can do it opposite too: if ($_SERVER['REQUEST_METHOD'] == "GET") { display } else { process } Quote Link to comment Share on other sites More sharing options...
damaya Posted June 17, 2010 Author Share Posted June 17, 2010 In index.php I have this: <form action="lookup.php" method="POST" class="form"> <label for="domain">Domain Name</label> <div class="domain_div"> <input name="domain" type="text" class="domain_tb" id="domain" value="domain" /> </div> <div class="button_div"> <input name="Submit" type="button" value="Look Up" class="buttons" /> </div> </form> Now, in my lookup.php file I have this: <?php ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); $domain = $_POST['domain']; // First let's check if domain is valid (exists) $ip = gethostbyname($domain); if($ip === $domain) { return ???; } // First get all records related to root domain // Get A Records First $dnsr = dns_get_record($domain, DNS_A ); for($i = 0; $i < count($dnsr); $i++){ echo $dnsr[$i]["host"].'<br>'; echo $dnsr[$i]["ip"].'<br>'; echo '<br>'; } ?> Now, how do I get everything from lookup.php back into index.php forms? Do I return it back in and handle it there? How to do that? Is there a better way to do this? Quote Link to comment Share on other sites More sharing options...
TOA Posted June 17, 2010 Share Posted June 17, 2010 If I understand you correctly, this is what you need to combine the two files into one. index.php(new) if ($_SERVER['REQUEST_METHOD'] == "GET") { code from index.php(old) } else { code from lookup.php } You could also do it with includes like this: if ($_SERVER['REQUEST_METHOD'] == "GET") { include_once("form.html"); // If form.html is a new file containing just your form } else { include_once("lookup.php"); } Hope that helps Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 17, 2010 Share Posted June 17, 2010 In the index.php page do something like this <?php if ($_SERVER['REQUEST_METHOD'] == "POST") { include('lookup.php'); } else { ?> <form action="lookup.php" method="POST" class="form"> <label for="domain">Domain Name</label> <div class="domain_div"> <input name="domain" type="text" class="domain_tb" id="domain" value="domain" /> </div> <div class="button_div"> <input name="Submit" type="button" value="Look Up" class="buttons" /> </div> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
damaya Posted June 17, 2010 Author Share Posted June 17, 2010 Ahhh, alright, I get that part now, but the part I am still lost on is how, after including lookup.php, do I use the values from lookup.php to populate my text fields? I am used to Perl, where I return a value (array, hash, scalar), and then use that value to populate the form... If it can validate the domain it returns TRUE + All records found. If not, it returns FALSE. Then, in index.php, If it returns TRUE it populates all text fields with the records, and if it returns FALSE it should have a box below that says something like "Sorry, unable to find domain." 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.