eZ Community » Forums » Developer » Create object with php - checkbox...
expandshrink

Create object with php - checkbox problem

Create object with php - checkbox problem

Friday 13 January 2012 11:04:44 am - 3 replies

Hello everybody.

I have a little problem for create an object in php. I'm following this tuto. I have a class which have a checkbox attribute and I don't know how to store the attribute.

In a first time I recover the post paramaters in php.

$http = eZHTTPTool::instance ()
 
if( $http->hasVariable('name') )     $value = $http->variable ('name');
if( $http->hasVariable('editor1') ) {
 $editeur1 = $http->variable ('editor1');
<span style="font-size: 14px;"> </span>$XMLContent = $editeur1;$parser = new eZOEInputParser();
$document = $parser->process($XMLContent);
 
}
 
if( $http->hasVariable('checkbox') )     $checkbox = $http->variable ('checkbox');

After that I create the object with the "createAndPublishPublishObject" function

I prepare the parameters :

$user = eZUser::currentUser();
$params = array();
$params['class_identifier'] = 'commentaire';
$params['creator_id'] = $user->attribute( 'contentobject_id' );
$params['parent_node_id'] = 60;
$params['section_id'] = 1;

 

And I create the object

 $attributesData = array ( ) ;
 
$attributesData ['checkbox'] = $checkbox;
$attributesData['sujet'] = $value ;
$attributesData ['messagexml'] = eZXMLTextType::domString( $document );
$params['attributes'] = $attributesData;
$contentObject = eZContentFunctions::createAndPublishObject( $params );

After that I can see the object in the admin interface, but the checkbox is not stored.

The $checkbox return "ON".

I guess there is a small handling to be made.

Thanks a lot.

Romain

Modified on Friday 13 January 2012 11:59:30 am by Romain Bremaud

Friday 13 January 2012 11:18:22 am

Hello Romain,

I can tell you this is a problem only with your code, what we call a 'usage' error. Others can't say they have meet 'this problem' because you have not really described any problem only a result.

But I see many problems with your source code example you have shared right off the bat.

Now I can't tell what your input for your checkbox (ezboolean datatype) attribute really is because of your incomplete source code example. Normally this should be simply a 1 or a 0.

 

Any chance you could share your real / complete source code instead of this incomplete example?

Further you are missing a lot of params which are required by 'eZContentFunctions::createAndPublishObject' in your example as well.

I would suggest re-reading the article if this is your real source code (not psudo example code; not the same) as again your missing key params to create a node which are covered in the articles text and examples specifically.

 

Could you share more detail about what your specific error your getting instead of your published node?

 

Have you reviewed the applicable to and from string documentation which governs this attribute content format in this use case?

http://ezpedia.org/ez/simple_fromstring_and_tostring_interface_for_attributes

 

I hope this helps ...

 

Cheers,

Heath

Modified on Friday 13 January 2012 11:31:44 am by // Heath

Friday 13 January 2012 12:16:27 pm

Thanks Heath.

I'm sorry for my bad description of my problem. I have reissue my topic. 

My problem was I don't know what results I should pass for a checkbox attribute. I store your link in my favorites. I will try with "1 or 0". 

I'm so sorry for the disturbance. I must be more careful next time. 

Romain

Thursday 19 January 2012 8:53:05 am

It works when I passed 0 or 1. Thanks for your help.

Romain

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from