Jump to content

Getting multiple inputs from a form?


simonp

Recommended Posts

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.