Hello,
I am trying to develop module that prints out a certificate.
What I have so far is a custom form (using the form API) containing a few settings like certificate title, certificate date and certificate recipient name.
I want to be run some PHP to generate a style table (the certificate) containing the input values i.e. the actual certificate print below the input form page instead a saving a node and then redirecting the user to the saved node. I think it would be more usable (and less admin for me) to display both the certificate settings and certificate display on the same page. Finally I want my users to be able to print the resulting certificate using some javascript.
Any help would be greatly appreciated.
Cheers,
J.
Comments
You dont need any javascript
You dont need any javascript for printing output in drupal. If you just press ctrl+p, you can see the resulting output. You just define which content need to be printed and you can even set a print button in the form and that will call a javascript [drupal_add_js(drupal_get_path('module', 'modulename') .'/js_file_name.js');] file to popup the window, which can be printed.
function printPopUp()
{
var strURL = getCurURL();
var strQS=strURL;
var array=strQS.split('#');
if(array.length==2)
{
strQS =array[0]+'&popup=1';
}
else
{
strQS =strQS+'?&popup=1';
}
objWin = window.open(strQS,'name','height=275,width=600,scrollbars=yes');
if(objWin && objWin.focus)
{
objWin.focus()
}
else
{
}
return true;
}
As you can see this is pure javascript code not drupal's(need to change it to drupal standards).
For certificate and form in same page,
here in this link below, i have given a sample code to list details.
http://drupal.org/node/227103
same in here in case of filter from create your input form, then in case of showing result list you can show your certificate.
You can use two methods to pass values to cretificate
one through submission and another by ajax.
By submit
values of certificate can be saved in session and set to each variable.
By ajax
core drupal support ajax. but i don't know how to use ajax in drupal standards. so not going to make a comment on that( others wise you can use id of each form to pass values to
Hope this will help
Cheers.
Sessions
Hello,
Sorry for not responding sooner to your very helpful post.
I like the use of sessions in your example, however is there a more robust way of passing variables to functions in Drupal without resorting to the dreaded Global variable? I.e. I have a validate function that checks user input and if fields are empty it alerts the user, however if the fields are filled in I then call a function to generate a certificate. The only way I can find to pass variables between these functions is to declare them as Global variables.
I know I will probably get heckled for this post but I really don't see an easy way of extracting variables from POST without setting Global variables or retrieving the $_POST variable for each input field, the $_POST variables would need sanitising before display which would add to the overhead of the module.
Any ideas or short-cuts to pass sanitised variables between functions??
Justin.
$_POST is not the best way.
$_POST is not the best way. most of the core modules use the session method. Easy to implement too. You can use post method i will work too. (ps lately got lots of work, late to reply).
Hope this will help.
Cheers.
Sessions
I think my problem with sessions is that they are slightly flimsy and I would really like to just hold the data within the functions and run a white list against the input.
I will try out a few options.
Any other ideas would be greatly appreciated.
Cheers naveenpl!
Justin.
If your content is that much
If your content is that much higher then you need to save them in some table. then pass the id of the table through $_POST method, (ID must be encoded with some algorithm and post them then decode the id and retrieve the content from table. OR check "mysql views" it may come in handy.
Hope this will help
Cheers.
D8+ solution https://www
D8+ solution https://www.jaypan.com/tutorial/drupal-form-api-ajax-form-and-results-sa...
Contact me to contract me for D7 -> D10/11 migrations.