Hello
I'm building my first module and I'm stuck with my 'edit' form.
I create a Holidays period with 2 dates (beginning day-finishing day). It looks like this:
------------------------------------------
Holidays management
Starting day Ending day Operations
1/10/2011 5/10/2011 edit delete
2/11/2011 5/11/2011 edit delete
Add a Holidays period
------------------------------------------
I've succeeded to create my 'add' form.
Looking through the uc_attributes module I similarly built a menu item
function cart_scheduler_menu() {
...
// menu edit Holiday period
$items['admin/store/Cart_scheduler/Holidays/%id/edit'] = array(
'title' => 'Edit Holiday Period',
'description' => 'cart_scheduler settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('cart_scheduler_holidays_add_form'),
'access arguments' => array('administer Cart Scheduler'),
'type' => MENU_CALLBACK,
);
// menu add Holiday period
$items['admin/store/Cart_scheduler/Holidays/add'] = array(
'title' => 'Add a new Holidays Period',
'description' => 'cart_scheduler settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('cart_scheduler_holidays_add_form'),
'access arguments' => array('administer Cart Scheduler'),
'type' => MENU_NORMAL_ITEM,
);
...
}
and defined those 2 links 'edit' - 'delete' on each row of my table like this:
function cart_scheduler_holidays_page(){
$holidays= db_query("SELECT a.* ....
while ($data = db_fetch_object($holidays)){
$ops = array(
l(t('edit'), 'admin/store/Cart_scheduler/Holidays/'. $data->id .'/edit'),
l(t('delete'), 'admin/store/Cart_scheduler/Holidays/'. $data->id .'/delete')
}
}...
and my add-edit form is:
function cart_scheduler_holidays_add_form(&$form_state,$holidays =NULL) {
if (!empty($holidays)) {
$form['id'] = array('#type' => 'hidden', '#value' => $holidays->id);
drupal_set_title(t('Edit holidays: %ide', array('%ide' => $holidays->id)));
}
$form['starting_day'] = array(
'#type' => 'textfield',
'#title' => t('Beginning day'),
'#description' => t('Beginning day'),
'#default_value' => !empty($holidays)? $holidays->starting_day : 1,
'#required' => TRUE,
);
etc
}
But when I'm clicking on edit it sucks ! It stays on same page .
I'm pretty newbie in Drupal Dev and I dont understand how 'page arguments' works.
in uc_attribute module, this params displays :
$items['admin/store/attributes/add'] = array(
...
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_attribute_form'),
$items['admin/store/attributes/%uc_attribute/edit'] = array (
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_attribute_form', 3),
What is this little '3' ? Is it in relation with the fact that the same form called, switch in edit mode rather than add mode ? It seems that is no test against it in the
function uc_attribute_form($form_state, $attribute = NULL)
I've strictly copy their code but mine sucks!
Did I miss some param, something else ?
Didnt find any help nowhere about those '%, form, edit, add' and so on...
:-)
Comments
I've seen that the 3 stands
I've seen that the 3 stands for the % !
So it should be
Well, but it still sucks.
I've also tried to add a '&' at $form_state :
function cart_scheduler_holidays_add_form(&$form_state,
but nada from rien of nothing works.
To be more precise, my function cart_scheduler_holidays_add_form is never called, as I've got a dpm() at the entrance which is never displayed...
Artatum
www.ixxi-mobility.com
What is this little '3' ?
Path component, counted 0,1,2,3...
0 = admin
1 = store
etc.
In case of
admin/store/Cart_scheduler/Holidays/%id/edit, %id is indeed 4.Actually, I'm at the moment
Actually, I'm at the moment solving a pretty similar task in this sandbox module. It has a table of 'existing entries', 'Add' form above it (I don't think it deserves a separate page), 'Delete' buttons on every row, and right now I'm about to get some more coffee and add edit links.
Could you see any reason in
Could you see any reason in my code why my form isn't called ?
Artatum
www.ixxi-mobility.com
$items['admin/store/Cart_sche
$items['admin/store/Cart_scheduler/Holidays/%id/edit'] = array(:- %id wildcard assumes you have id_load() function somewhere around (see this); I usually do simply
whatever/%/editwhich simply passes whatever is in place of % to the page callback function.'page arguments' => array('cart_scheduler_holidays_add_form'),- here it will probably be:
'page arguments' => array('cart_scheduler_holidays_add_form', 4),regardless of whether you're passing a simple argument or a wildcard.I LOVE YOU DRAVE Gee. It's
I LOVE YOU DRAVE
Gee. It's been about 8h I was suffering!
Thank you so much, you saved my life.
Do you want to marry me ?
Artatum
www.ixxi-mobility.com
LOL, I'm old, straight and
LOL, I'm old, straight and never quite understood French humour. :D
On a side note, I just uploaded new update for my Comment whitelist module – some tricks in it might be useful for you, like creating multiple buttons with one form function and passing values around behind the scenes with
'#type' => 'hidden',.I'm gonna check it out
I'm gonna check it out soon.
But at last could you tell me how I can get the index of a select list in a form ?
I display a list of monthes but would like to record the int index of the choice, not the string 'january'
is it
$form_state['values']['starting_month']['index']
:-(
or ...?
PS How do you know I'm French ?
Is it my accent ?
PPS I dont find Comment whitelist module ?
Artatum
www.ixxi-mobility.com
Define the form like
Define the form like this:
Strings are used for labels, but values are numeric. (well, actually both are strings, but it's PHP :)
PS: Name + timezone used in your code (the other thread)
PPS: here it is: http://drupal.org/sandbox/DraveRobber/1174150; (doesn't a link appear on my profile page?)
if you navigate to View commits -> (last commit id – 9550803 in this case) -> snapshot, you can get the module in .tar.gz without messing with git.
I see for the form. But my
I see for the form. But my problem is when writing the form in db, in _submit.
How can I retrieve the index of the month selected?
is it simply $form_state['values']['month'] ?
aint this returning the string?
Artatum
www.ixxi-mobility.com
No, this returns the key.
No, this returns the key.
Cool.
Cool.
I have also this request to formulate :
How display form items inline ?
Artatum
www.ixxi-mobility.com
AFAIK it's done at CSS level,
AFAIK it's done at CSS level, at least for labels.
Ok. My module is pretty out
Ok.
My module is pretty out now.
Thank you again for your precious helping hand ;-)
A.
Artatum
www.ixxi-mobility.com
Hello DR (I dunno which one
Hello DR
(I dunno which one is your first name : (Drave === Dave ? || Robber === Robert ? ) ;-)
Could you give me your advice for the best IDE for Drupal ? (I need mainly breakpoints, step-by-step, syntax completion...)
I'm wondering if you use Zend Studio, or Quickstart etc ? (i've tried to set up both, but none is working :-(
And also, do you know way for searching only in the dev forum ?
Artatum
www.ixxi-mobility.com
– none of these :) – haven't
– none of these :)
– haven't ever been using any of these – I write in gedit, the built-in text editor of Ubuntu, and test on localhost; but then, I'm old enough to have written HTML in notepad, too;
– no, and I don't think there is a simple way.
Not much use of me on Monday morning. :D
Where do you write?
Where do you write?
Artatum
www.ixxi-mobility.com
This:
This: http://en.wikipedia.org/wiki/Gedit
(I didn't know it has a Windows port, too)
I meant where do you live
I meant where do you live ?
lol
Artatum
www.ixxi-mobility.com
Riga, Latvia (the latter part
Riga, Latvia (the latter part is in my profile, and this is a small country anyway).