By svergeylen on
I was wondering if anybody can help to get other parameters to the theme_name_form function ?
Example : I fill the form variable with the item I want. I call the theme_name_form which render the form correctly.
How can I have another variable which come from name_form into my theme_name_form() ??
This is what I tried :
in the .module file (hook_theme) :
'macommande_formulaire' => array(
'arguments' => array('commandes' => array(), 'total_commandes' => null ),
'file' => 'macommande.page.php')
and in macommande.Page.php
function theme_macommande_formulaire($form) {
if ($total_commandes) output.= "Yess :-) ";
And I can't access to the value of $total_commandes... :-(
I assume the second function doesn't know at all about my variable $total_commandes... but how can I pass this value (without a static variable of course ;-) )
Thanks !
Comments
I think the arguments that
I think the arguments that you set in hook_theme are passed to the theme function.
Your function should thus be:
Correct me if I'm wrong!
Good luck,
Thijs
I get still a problem
Thanks for your response !
If I add the parameters in the description of the function like this :
I get this error : Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')' in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line
It seems that Drupa doesn'ot want me to use "=>" in the declaration ???
If I remove the initialisation of the parameter in the function :
Then, I get this error :
* warning: Missing argument 2 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 3 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 4 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 5 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 6 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
* warning: Missing argument 7 for theme_macommande_formulaire() in /media/Donnees/www/Sandwichs/sites/all/modules/sandwichs/macommande.page.php on line 235.
no more on a white screen, but in the messages from drupal (drupal_set_message). It seems that these variables are not initialize but how can I solve this ?? ;-)
Thanks for helping !
Stéphane
When theming forms, you can
When theming forms, you can only pass the $form variable to the theme function. Any extra data needs to be added to the form element, and can then be accessed in the theme function.
Contact me to contract me for D7 -> D10/11 migrations.
OK, thank you for your help
OK, thank you for your precise answer. I tought it was like this but because I come from a template with a lot of array of variables, I was wondering if it was possible.
Do you know if I can add an array to your #value of 'id' or of I can only add a string ?
Thanks,
Stéphane
Honestly, testing it on your
Honestly, testing it on your own would be faster than waiting for me to reply.
But the answer is yes, you can pass an array.
Contact me to contract me for D7 -> D10/11 migrations.