如何在注册小部件中设置自定义字段?

时间:2011-08-28 08:20:03

标签: php facebook registration

我正在使用here中的注册插件 我正在json_encode数组中设置一些自定义字段:

<?php
$fields = json_encode(array(
array('name' => 'name'),
array('name' => 'city', 'description' => 'City', 'type' => 'typeahead', 'categories'=>'city')
));
?>
<iframe src="https://www.facebook.com/plugins/registration.php?
         client_id=xxxxxxxxxxxxxxx&
         redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fecho%2F&
         fields=<?php echo urlencode($fields);?>"
    scrolling="auto"
    frameborder="no"
    style="border:none"
    allowTransparency="true"
    width="100%"
    height="330">
</iframe>

在facebook示例中,他们说你可以设置这样的东西,当你输入它时会给你一个'city','country','state_province'的提示:

 {'name':'live',       'description':'Best Place to Live',       'type':'typeahead', 'categories':['city','country','state_province']}

在我的情况下,我尝试这样做:

array('name' => 'city', 'description' => 'City', 'type' => 'typeahead', 'categories'=>'city')

但它不起作用。如果我得到那条线,插件工作正常,这意味着我没有正确设置。

我也尝试了这个,它不起作用:

array('name' => 'city', 'description' => 'City', 'type' => 'typeahead', 'categories':['city','country','state_province'])

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:2)

我认为你需要这样做:

array('name'=>'city', 'description'=>'City', 'type'=>'typeahead', 'categories'=>array('city', 'country', 'state_province'));

...来代替。这样:

'categories':['city','country','state_province']`

...是Javascript语法,在PHP中无效 - 会导致解析错误。 PHP中的等价物是

'categories'=>array('city', 'country', 'state_province')