simonp Posted February 10, 2009 Share Posted February 10, 2009 Hi, At the moment I have a simple textbox on an HTML form and I get the content in a PHP file like so: <input name="domain" type="text" value="testdomain.co.uk" /> <?PHP //Get input $domain = $_POST['domain']; ?> But I would like to be able to have a textarea where multiple entries can be made eg: testdomain1.co.uk testdomain2.co.uk testdomain3.co.uk etc How would I get that input into my PHP script so I could do this: $arrayofdomainentries[] = array( // first element 'domain' => $domain, ); $arrayofdomainentries[] = array( // second element 'domain' => 'xxxx.xxx', ); $arrayofdomainentries[] = array( // third element 'domain' => 'xxxx.xxx', ); and so on! I'm sure this quite simple but I've never dealt with multiples before (I think they're call arrays?!) Cheers Simon Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/ Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 explode at the linebreak character "\n" <?php $domain = $_POST['domain']; $arrayofdomains = explode("\n", $_POST['domain']); ?> Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-758910 Share on other sites More sharing options...
simonp Posted February 10, 2009 Author Share Posted February 10, 2009 Sorry, I think I probably confused things by cutting down my code. There's a whole load of other things that have to go inside each: $arrayofdomainentries[] = array( // first element 'domain' => $domain, 'language' => 'en', 'somethingelse' => 'xx', 'somethingelse' => 'xx', ); How would I do it now?! Cheers Simon Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-758929 Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 <?php $domain = $_POST['domain']; $arrayofdomains = explode("\n", $_POST['domain']); $arrayofdomainentries = array(); foreach ($arrayofdomains as $domain) { $arrayofdomainentries[] = array( // first element 'domain' => $domain, 'language' => 'en', 'somethingelse' => 'xx', 'somethingelse' => 'xx' ); } ?> That should work, not sure how you determine the somethingelse's but yea. Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-758931 Share on other sites More sharing options...
simonp Posted February 10, 2009 Author Share Posted February 10, 2009 Hi premiso - that worked brilliant (don't worry about the somethingelses!) Only problem is, each line has a space appended to the end and that's failing the next step. How can I get rid of that space? Cheers simon Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-758934 Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 trim ? Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-758937 Share on other sites More sharing options...
simonp Posted February 10, 2009 Author Share Posted February 10, 2009 hmm - thanks for your help - but I still can't get it working properly. Here's the whole script - can you see what might be wrong?! It works if I uncomment out the arrays but not if I use the foreach statment. <?PHP $domain = $_POST['domain']; $arrayofdomains = explode("\n", $_POST['domain']); $signkey = 'xxxx'; $partnerid = 'xxxx'; // Include the NuSOAP library. require_once('lib/nusoap.php'); // Create a new client by providing the endpoint to the constructor. $client = new soapclient('https://api.sedo.com/api/sedointerface.php'); // Send the data with UTF-8 encoding. $client->soap_defencoding = 'UTF-8'; // Dont convert the recieved data in ISO. $client->decode_utf8 = false; // Check for errors $error = $client->getError(); if ($error){echo $error;} $arrayofdomainentries = array(); foreach ($arrayofdomains as $domain) { $arrayofdomainentries[] = array( // first element 'domain' => $domain, 'category' => array('x'), 'forsale' => x, 'price' => 'xxx.00', 'minprice' => 'xxx.00', 'fixedprice' => x, 'currency' => x, 'domainlanguage' => 'en' ); } //$arrayofdomainentries[] = array( // first element // 'domain' => 'testdomain1.co.uk', // 'category' => array('x'), // 'forsale' => x, // 'price' => 'xxx.00', // 'minprice' => 'xxx.00', // 'fixedprice' => x, // 'currency' => x, // 'domainlanguage' => 'en' // ); //$arrayofdomainentries[] = array( // first element // 'domain' => 'testdomain2.co.uk', // 'category' => array('x'), // 'forsale' => x, // 'price' => 'xxx.00', // 'minprice' => 'xxx.00', // 'fixedprice' => x, // 'currency' => x, // 'domainlanguage' => 'en' // ); //$arrayofdomainentries[] = array( // second element // 'domain' => 'testdomain3.co.uk', // 'category' => array('x'), // 'forsale' => x, // 'price' => 'xxx.00', // 'minprice' => 'xxx.00', // 'fixedprice' => x, // 'currency' => x, // 'domainlanguage' => 'en' // ); // Set the values for the array $params = array('username' => 'xxxxx', 'password' => 'xxxxx', 'domainentry' => $arrayofdomainentries, 'partnerid' => $partnerid, 'signkey' => $signkey ); // Call the SOAP method $result = $client->call('DomainInsert', array('name' => $params), 'urn:SedoInterface'); // Check for a fault if ($client->fault) { // Error Code echo "Faultcode: ".$result['faultcode']."<br>"; // Error description echo "Faultstring: ".$result['faultstring']."<br>"; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo $err; } else { // Display the result echo "<table border=1>"; echo "<tr><td>Domain</td><td>Status</td><td>Message</td></tr>"; for($i = 0; $i<count($result); $i++) { echo "<tr><td>".$result[$i]['domain']."</td><td>".$result[$i]['status']."</td><td>".$result[$i]['message']."</td></tr>"; } echo "</table>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-759001 Share on other sites More sharing options...
premiso Posted February 10, 2009 Share Posted February 10, 2009 Only problem is, each line has a space appended to the end and that's failing the next step. Ok, which line are you talking about? The domain lines? If the domains have an extra space in them, this should fix that: foreach ($arrayofdomains as $domain) { $arrayofdomainentries[] = array( // first element 'domain' => trim($domain), 'category' => array('x'), 'forsale' => x, 'price' => 'xxx.00', 'minprice' => 'xxx.00', 'fixedprice' => x, 'currency' => x, 'domainlanguage' => 'en' ); } I guess I am confused about what is not working. Link to comment https://forums.phpfreaks.com/topic/144626-getting-multiple-inputs-from-a-form/#findComment-759006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.