0

Hello guys i am trying to add data to one of my tables... when the submit button is pressed. I have the following script:

function review_m_admin_settings_form($node){
    $form = array();

    $form['overview'] = array(
        '#markup' => t('This interface allow adminss to manage general content types and vote them up!'),
    );
    $form['select'] = array(
        '#type' => 'select',
        '#title' => 'Choose a content type!',
        '#options' => node_get_types('names'),
    );
    $form['mark'] = array(
        '#type' => 'textfield',
        '#title' => 'Give a mark to the content type(1 to 10)!',
        '#size' => 60,
        '#maxlength' => 2,
    );
    $form['text'] = array(
        '#type' => 'textarea',
        '#title' => 'leave a feedback!',
        '#cols' => 60,
        '#resizable' => FALSE,
        '#rows' => 5,
    );
    $form['created'] = array(
        '#type' => 'textfield',
        '#title' => 'Enter the date!',
        '#size' => 60,
        '#maxlength' => 10,
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Send review'),
        '#weight' => 10,
    );
    $form['action'] = $url;
    return $form;
}

this is my form.... i called the function with the _submit at the end .. but it doesn't work!

    function review_m_admin_settings_form_submit($form, &$form_state){
    if(!isset($node->text)){
        $node->text = '';
        }
        if(!isset($node->created)){
            $node->created = '';
        }
        db_query(
            'INSERT INTO {review_m} (rid, nid, uid, mark, text, created)'
            . "VALUES (%d, %d, %d, '%s', '%s')",
            $node->rid,
            $node->nid,
            $node->uid,
            $node->mark,
            $node->text,
            $node->created
        );
}

Help!

7
  • 2
    When you say it doesn't work, what happens? Do you get any error messages? Have you checked the watchdog at admin/reports/dblog? Mar 11, 2013 at 12:47
  • 2
    You have set form action to $form['action'] = $url but I dont see $url being declared anywhere in code that you have posted, can you post the complete code ? Or have you forgot to declare $url ?
    – GoodSp33d
    Mar 11, 2013 at 12:49
  • $node doesn't appear to be declared in _submit either. Mar 11, 2013 at 12:49
  • well i get to errors:
    – emcee22
    Mar 11, 2013 at 12:51
  • warning: Creating default object from empty value in D:\work\test\drupal\sites\all\modules\review_m\review_m.module on line 64.
    – emcee22
    Mar 11, 2013 at 12:52

1 Answer 1

1

You're trying to assign a value to an object property without declaring the object. Try this:

function review_m_admin_settings_form_submit($form, &$form_state){
    $node = new stdClass();

There's actually not any need to check if $node->text isset either because we know we haven't set it already.

You also need to pull your form values from the $form_state variable. For example:

$node->text = $form_state['values']['text']
0

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