0

I'm developing a site that it will use Services for the CRUD operations and ANGULARJS for the comunication frontend <-> backend.

Now when I want to insert a new content of content type FOO I will don't use the standard form (node/add/FOO), but one of my HTML form, this because, like I said, I will use Services to store the new content.

So, is there a way (or a module) that permit me to send this form to Drupal for only validating it and give back a ok/error code? In this last case I need to receive back errors and the wrong fields.

Thanks. M.

3
  • I think you should more inforamtion. There can be multiple ways to solve it...
    – xurshid29
    Commented Sep 10, 2014 at 16:35
  • xurshid29: how can I can give you more information if I have ask to know if this is possible ?
    – ZioBudda
    Commented Sep 10, 2014 at 21:12
  • of course this is possible..
    – xurshid29
    Commented Sep 11, 2014 at 5:14

1 Answer 1

0

What about this approach (these are just my thoughts)? So, create a rout which gets request and builds $form_state and calls drupal_form_submit function, actual form looks something like this:

function myForm($form, &$form_state)
{
  ....
  $form['submit'] = array(
    '#type' => 'submit',
    '#submit' => array(),
    '#validate' => array('myFormValidation')
  );
  ....
}

function myFormValidation($form, &$form_state)
{
  $error = false;
  if (SOME_CONDITION) {
    $error = true;
  }

  ...

  if (!$error) {
   drupal_json_output(array('ok'));
   exit;
  }
  else {
   drupal_json_output(array('error'));
   exit;
  }
}

EDIT:

I don't have an expirience with Drupal's Services module or its RESTFul services, but I usually develope my REST projects (usually backend system for IOS apps) in symfony, I think I understand how all this stuff work:), So when I wrote about a rout I meant that this will be some menu item (with hook_menu):

$items['check-my-external-post-data'] = array(
  'page callback' => 'some_callback',
  ...
);
...

function some_callback()
{
  ...
  // $values - from $_POST request
  $form_state = array();
  foreach ($values as $key => $value) {
    $form_state['values'][$key] = $value;
  }
  ...
  drupal_form_submit('myForm', $form_state);
}

I've never tested this kind of things, but it should work (there are too many tutorials about REST APIs, request handling, and so on.. which can help OP if something goes wrong)

2
  • "create a rout which gets request" - this part confuses me. Your code looks like the good way to do what OP wants, but could your explanations be clearer?
    – Mołot
    Commented Sep 10, 2014 at 7:54
  • @Mołot I added some additional info to my answer..
    – xurshid29
    Commented Sep 10, 2014 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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