0

I am trying to setup a form to post the data to a php file which will then make an API call, I am pretty close I think any help appreciated.

When I have been doing testing the form seems to post to the php file however nothing seems to happen from then on. I was going to try and print out the data string to see if that is correct ??

The only part which is missing is the first part of the url which I have but cannot post on here

here is my html code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
label, input, textarea { display: block; float: left; width: 150px; margin: 5px; }
label { clear: left; text-align: right; }
input[type="submit"] { width: 60px; margin: 10px 0 0 165px; clear: left; }
</style>
</head>
<body>
<h2>New Account Creation</h2>
<form action="sonian.php" method="post">
<label>User name (required)</label> <input type="text" name="username" value="" />
<label>Password</label> <input type="text" name="password" value="" />
<label>First Name</label> <input type="text" name="first_name" value="" />
<label>Last Name</label> <input type="text" name="last_name" value="" />
<label>Email</label> <input type="text" name="email" value="" />
<label>Address Line 1</label> <input type="text" name="address1" value="" />
<label>Address Line 2</label> <input type="text" name="address2" value="" />
<label>City</label> <input type="text" name="city" value="" />
<label>County</label> <input type="text" name="state" value="" />
<label>Postcode</label> <input type="text" name="zip" value="" />
<label>Phone Number</label> <input type="text" name="phone" value="" />
<label>Sub Domain</label> <input type="text" name="sub_domain" value="" />
<label>Account Name</label> <input type="text" name="name" value="" />
<label>Number of Users</label> <input type="text" name="number_of_users" value="" />
<label>Account Type</label> <input type="text" name="organization_type_id" value="" />
<div class="field required clear">

<label class="_">Account type</label>
<select id="account_organization_type_id" name="account[organization_type_id]"><option value="1500">Commercial</option>
<option value="1501">Non-Profit</option>
<option value="1502">Education</option>
<option value="1503">Government</option></select>
</div>
<div class="field clear">
<label class="inline"><input name="account[uses_exchange]" type="hidden" value="0" /><input id="account_uses_exchange" name="account[uses_exchange]" type="checkbox" value="1" />&nbsp;Exchange
</label>
<label class="inline"><input name="account[uses_groupwise]" type="hidden" value="0" /><input id="account_uses_groupwise" name="account[uses_groupwise]" type="checkbox" value="1" />&nbsp;GroupWise
</label>
<label class="inline"><input name="account[uses_notes]" type="hidden" value="0" /><input id="account_uses_notes" name="account[uses_notes]" type="checkbox" value="1" />&nbsp;Noteworthy
</label>
<label class="inline"><input name="account[uses_zimbra]" type="hidden" value="0" /><input id="account_uses_zimbra" name="account[uses_zimbra]" type="checkbox" value="1" />&nbsp;Zimbra
</label>

 IMail Server

</label>
<label class="inline"><input name="account[uses_scalix]" type="hidden" value="0" /><input id="account_uses_scalix" name="account[uses_scalix]" type="checkbox" value="1" />&nbsp;Scalix
</label>
<label class="inline"><input name="account[uses_gmail]" type="hidden" value="0" /><input id="account_uses_gmail" name="account[uses_gmail]" type="checkbox" value="1" />&nbsp;Gmail Apps
</label>
<label class="inline"><input name="account[uses_sunone]" type="hidden" value="0" /><input id="account_uses_sunone" name="account[uses_sunone]" type="checkbox" value="1" />&nbsp;SunONE
</label>
<label class="inline"><input name="account[uses_hosted_exchange]" type="hidden" value="0" /><input id="account_uses_hosted_exchange" name="account[uses_hosted_exchange]" type="checkbox" value="1" />&nbsp;Hosted Exchange
</label>
<label class="inline"><input name="account[uses_kerio]" type="hidden" value="0" /><input id="account_uses_kerio" name="account[uses_kerio]" type="checkbox" value="1" />&nbsp;Kerio
</label>
<label class="inline"><input name="account[uses_other]" type="hidden" value="0" /><input id="account_uses_other" name="account[uses_other]" type="checkbox" value="1" />&nbsp;Other
</label>
</div>
<input type="submit" value="Save" />
</form>
</body>
</html>

And here is the php code

    <?php
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {
    $strPost = "";
    //create string with form POST data
    $strPost = "Username=" . urlencode($_POST['username'])
    . "&Password=" . urlencode($_POST['password'])
    . "&First Name=" . urlencode($_POST['first_name'])
    . "&Last Name=" . urlencode($_POST['last_name'])
    . "&Email=" . urlencode($_POST['email'])
    . "&Address Line 1=" . urlencode($_POST['address1'])
    . "&Address Line 2=" . urlencode($_POST['address2'])
    . "&City=" . urlencode($_POST['city'])
    . "&County=" . urlencode($_POST['state'])
    . "&Postcode=" . urlencode($_POST['zip'])
    . "&Phone Number=" . urlencode($_POST['phone'])
    . "&Sub Domain=" . urlencode($_POST['sub_domain'])
    . "&Account Name=" . urlencode($_POST['name'])
    . "&Number of Users=" . urlencode($_POST['number_of_users'])
    . "&Account Type=" . urlencode($_POST['organization_type_id'])
    . "&Email System=" . urlencode($_POST['uses_exchange']);
    //set POST URL
    $url = "https://url/api/accounts.xml";
    //intialize cURL and send POST data
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost);
    @curl_setopt($ch, CURLOPT_URL, $url);
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    @curl_exec($ch);
    @curl_close($ch);
    }
    ?>
4

1 に答える 1

0

形がおかしいと思います。

同じ行に、隣のチェックボックスと同じ名前の非表示の入力があります。

<input name="account[uses_exchange]" type="hidden" value="0" />
<input id="account_uses_exchange" name="account[uses_exchange]" type="checkbox" value="1" />&nbsp;Exchange

PHPファイルはどのようにそれを理解できますか?

また、php処理ではvarがあります

. "&Email System=" . urlencode($_POST['uses_exchange']);

しかし、あなたはこのものの名前を配列値として送信していると思います。

 name="account[uses_exchange]"

したがって、非表示の値を使用するか、チェック ボックスの配列を使用するかを決定する必要があると思います。

次に、php 処理の反対側で配列をループします。

 foreach($_POST['account'] as $k => $v)
    echo "<br>$k => $v";

プロデュース:

organization_type_id => 1500
uses_exchange => 1
uses_groupwise => 1
uses_notes => 1
uses_zimbra => 1
uses_scalix => 1
uses_gmail => 1
uses_sunone => 1
uses_hosted_exchange => 1
uses_kerio => 1
uses_other => 1
于 2013-03-27T20:29:34.530 に答える