Hi Guys/Gals,
I'm a student in DCU struggling to get the last parts of my 3rd year project in place. Here is a link to the test area of my site that I am having problems with (http://www.redbrick.dcu.ie/~dano/drupal/?q=examples/test_form). You shouldn't need a login for now. The problem is in my .inc file, I cant seem to use the "insert into" command properly with the AHAH submit button I have. The query instead inserts a row of blank values because of what I can only assume is me not referencing the textfield values properly. I'm sure its something simple that I'm just not seeing at this late stage in code, I would really appreciate any help as my submission deadline is late tomorrow. Here is a pastebin of my code. (http://pastebin.com/Z9KQ5aqk).
Thanks you for your time :)
Comments
Does the submit button have
Does the submit button have to be ahah too or just the 'add more' button? It'd be better to use a non-ahah submit button and use a submit form handler instead. That way you could also avail of the form validation handlers too if you wanted.
Ignoring that, you are getting empty values in your table because you are inserting a variable ($node->Iname) which doesn't exist. Not sure where you got $node from but it's not a node form by the looks of it (difficult to tell without seeing full code, but that's the incorrect definition of it if it is) and it's not a variable passed into or set in that function either.
You're already checking the correct place for the value of the submit button ($form_state['values']['op']) so you know how to access the form values already - $form_state['values'] array.
Hope that helps.
Thanks
Hey Stella,
Thanks so much, completely switched on the idea bulb there and have it working in full swing! :D
Damien
Trouble in Insert Paradise again
Hi, sorry to be clogging the forums with my questions. Below are two snippets of code, the first one works, however the second one is the one I am interested in. The second allows a user to create multiple boxes to insert an input into but I'm having trouble referencing the multiple inputs.
EXAMPLE ONE
after submit is clicked
EXAMPLE TWO
// The element name needs to be different for each textfield, otherwise we will only get one value after the form is submitted.
$form['Iname']['Iname'. $i] = array(
'#type' => 'textfield',
'#title' => t('Ingredient'),
'#size' => 36,
'#default_value' => $form_state['values']['Iname']['Iname'. $i],
);
after submit is clicked
When I make $Ingred = $form_state['values']['Iname'], the insert works but only gives me the first item in the array. The addition of the 3rd array that expands with the addition of boxes should act as a marker to each new textfield but its not, it returns blanks rows (I've tried a for loop around the insert as well).
I am also wondering is there a way to manually assign and NID, VID and UID without creating a node?
again sorry for being a pain.
Trouble in Insert Paradise again
Hi, sorry to be clogging the forums with my questions. Below are two snippets of code, the first one works, however the second one is the one I am interested in. The second allows a user to create multiple boxes to insert an input into but I'm having trouble referencing the multiple inputs.
EXAMPLE ONE
after submit is clicked
EXAMPLE TWO
// The element name needs to be different for each textfield, otherwise we will only get one value after the form is submitted.
$form['Iname']['Iname'. $i] = array(
'#type' => 'textfield',
'#title' => t('Ingredient'),
'#size' => 36,
'#default_value' => $form_state['values']['Iname']['Iname'. $i],
);
after submit is clicked
When I make $Ingred = $form_state['values']['Iname'], the insert works but only gives me the first item in the array. The addition of the 3rd array that expands with the addition of boxes should act as a marker to each new textfield but its not, it returns blanks rows (I've tried a for loop around the insert as well).
I am also wondering is there a way to manually assign and NID, VID and UID without creating a node?
again sorry for being a pain.
Solved Main Problem
Apologies again, the multiple textfield problem was solved. I would still like to know if it is possible to set NID and the like manually.
No, you really shouldn't be
No, you really shouldn't be setting the nid or vid manually. You can alter the uid by changing the user in the 'authored by' textfield which you see in the 'authoring information' collapsed fieldset if you have the 'administer nodes' permission (this permission is only for trusted users!)