1

I have Channel with fields A,B,C,D,E

I have a Safecracker form that contains input elements for channel fields A,B,C

I have an extension with the callback method

public function foo($safecracker_object)
{
  ...
}

which has the hook

safecracker_submit_entry_start

Given these data, what I want to do inside the callback function is to add channel fields D and E data manually so that in the end, what is being sent are the fields A,B,C,D,E.

Is there something in the safecracker object that enables me to add those data? I have tried using

public function form_hidden($name, $value = '')

and

public function form_attribute($name, $value = '')

in safecracker object and it did not work.

2
  • The form_hidden() and form_attribute() functions are for outputting HTML form elements, not for accessing values of a posted form, just FYI. – Derek Hogue Jan 2 '13 at 13:23
  • @DerekHogue Ok, if that is so, then it makes sense. – developarvin Jan 3 '13 at 1:32
2

I've very little experience with Safecracker but can you not simply manipulate the $_POST elements? The hook is called before any entry data is processed so I can't see why that wouldn't work.

public function safecracker_submit_entry_start()
{
    $_POST['news_body'] = 'Test';
}
4
  • I tried manipulating $_POST but it did not the updated the respective Channel fields. – developarvin Jan 3 '13 at 1:33
  • Are you sure that your variable names matched the field names that Safecracker generates? I checked the Safecracker source and it does access $_POST vars shortly after calling the safecracker_submit_entry_start hook. To aid with debugging you could try adjusting the value of one of the fields that's already present on the form rather than injecting a new one. If that works it's likely that you have a mismatched field name. – Dom Stubbs Jan 3 '13 at 9:35
  • my keys to the $_POST array are the short names of the fields in the channels – developarvin Jan 4 '13 at 4:13
  • I've just created a dummy extension and updating $_POST vars does seem to work. I've updated my answer with the exact code that I'm using. So long as you are using simple input/textarea fields and the fields are within the fieldset assigned to the entry's channel I can't see why this wouldn't work. – Dom Stubbs Jan 4 '13 at 11:31
0

The nice thing about safecracker is that modifying channel entries will actually trigger the channel module hooks :)

One of them might be of more use?

http://ellislab.com/expressionengine/user-guide/development/extension_hooks/api/channel_entries/

1
  • Thank you for contributing. Can you be more specific in your answer? Is there a specific hook you are suggesting be used? – Anna_MediaGirl Jan 17 '13 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.