I have create a new content type and added new form items using CCK. I need to customise the layout of the form which I've partially managed using css and moving items around and adding custom markup in the form_alter hook. However, this still isn't enough as the weightings don't appear to be doing exactly what I want them to do.
Is there a way I can do this using a theme.tpl.php file?
Thanks
Steve
once in a time I was in the same situation and found a quite easy solution.
I needed a highly customized registration form and form_alter was a mess. So I used a template for the form and printed each field into the html output.
First register a new template for the form in template.php of you theme.
<?php
function your-theme-name_theme() {
return array(
'user_register' => array(
'arguments' => array('form' => NULL),
'template' => 'user-register',
),
);
}
?>
Now add a new template to your theme. In my case "user_register.tpl.php". Add the following lines to it, so that the form still works.
<?php
print drupal_render($form['form_build_id']);
print drupal_render($form['form_id']);
print drupal_render($form['form_token']);
?>
From there on you can add as much html as you want and put the form fields where ever you need them. Here are examples for the gender and birthday field. As you can see you have to use the internal CCK names.
<?php print drupal_render($form['field_profile_gender']); ?>
<?php print drupal_render($form['field_profile_birthday']); ?>
I have not tested this for any other form than user_register, but I guess it should work as long as the template name equals the name of the form.
I hope this will help you.
Regards
Mike
Related
I created a model in SugarCRM and I need to print the details view. But this must be printed with a different layout.
It must have the company logo for example, if I just wanted do print the bean information, the default print would be sufficient, but I need something closer to a report, because this info will be given to the costumer.
I would like to know if there is a way to create a printing template, and if there is, how can I create one?
Thanks for your help, if you need more information please comment.
rfnpinto
Even in SugarCRM CE you can leverage the included Sugarpdf class, which is an extension of TCPDF.
If you have SugarCRM Professional you can find examples of this in the Quotes module. If not, you're flying blind, so I can give you the gist of it.
Using the Contacts module as an example, create /custom/modules/Contacts/views/view.sugarpdf.php with contents like the following:
<?php
require_once('include/MVC/View/views/view.sugarpdf.php');
/**
* this defines the view that will drive which PDF Template we use
*/
class CustomContactsViewSugarpdf extends ViewSugarpdf{
public function display(){
$this->sugarpdfBean->process();
$this->sugarpdfBean->Output($this->sugarpdfBean->fileName,'D');
sugar_die('');
}
}
Create /custom/modules/Contacts/sugarpdf/sugarpdf.pdfout.php with contents like the following:
$contact = BeanFactory::getBean($_REQUEST['record_id']);
if(empty($contact->id)){
sugar_die('Could not load contact record');
}
$name_str = "<p><strong>Name: {$contact->name}</strong></p>";
$this->writeHTML($name_str);
$this->drawLine();
}
function buildFileName(){
$this->fileName = 'ContactPDFOut.pdf';
}
}
From there, you can print a PDF document per your format if you hit the URI index.php?module=Contacts&action=sugarpdf&sugarpdf=pdfout&record_id=1234
Once that's working in the way you want, you can add a button the Contacts Detailview to access that URI more easily. Dig into /custom/modules/Contacts/metadata/detailviewdefs.php and find the existing buttons array. It'll look something like this:
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES'
Just enhance this with your own button and hidden input
'buttons'=>array('EDIT', 'DUPLICATE', 'DELETE', 'FIND_DUPLICATES',array(
'sugar_html'=>array(
'type' => 'submit',
'value' => '(Wrongfully Hardcoded Label) Print PDf',
'htmlOptions'=>array(onclick => 'this.form.action.value=\'sugarpdf\';this.form.sugarpdf.value=\'pdfout\'')
)
)
...
The hidden array should be part of $viewdefs['Meetings']['DetailView']['templateMeta']['form'] and defined like so:
'hidden' => array('<input type="hidden" name="sugarpdf">'),
I haven't tested this recently but this is the general idea of adding custom Print PDF abilities to any particular screen within SugarCRM. TCPDF options are pretty extensive and forming the template just right is going to be very tedious, but I think once the "plumbing" is working here you'll figure that bit out, but feel free to ask followup questions.
I'm trying to add a plain text node in a custom drupal form. The purpose is to only dispay some static text.
The problem is - im not aware of any such way to do it.
I have used 'description' but that HAS to be attached to a form element.
Is there any way to simply display some text as part of a form?
Eg:
The following will test your ability on so and so. . . .
etc...
Any thoughts?
You should be able to add text using the markup form element.
Description: Generate generic markup for display inside forms.
Example from the documentation:
$form['contact_information'] = array(
'#markup' => variable_get('contact_form_information',
t('You can leave us a message using the contact form
below.')),
);
Im trying to preserve the user inputs from dynamic menu dropdown lists - I have an number of drowpdowns and a user input text field , when the user submits the form after selecting the options from the dropdowns.
I would like to be able to preserve the last choices made so the user does not have to reselect the options again when re posting the form with another value in the text field, i would also like this to work on errors as well ?
Im using ZF to validate the form.
i have tried the follwing code in the value attr of the option:
<option value="<?php if ($_POST && errors) {
echo htmlentities($_POST['CategoryID'], ENT_COMPAT, 'UTF-8');
}?>">Main Category</option>
But does not seem to work ?
I have a static options "Main Category" ect. which is what the form defaults to after submiting
can anyone help me on this one ??
Thanks in advance
I would highly recommend using Zend_Form. If that is not possible, I would next use Zend_View Helpers to build your HTML manually. Then you can use the formSelect in your view like this:
echo $this->formSelect('CategoryId', $selected, $attribs, array(
'main' => 'Main Category'
// ... other options
));
Where $selected variable equals to one of the following: posted value(s), default value(s), or is null and $attribs variable is simply attributes for the select element.
I am developing symfony based web application. I have many Models (Laptop, Netbook, Ipad,Tablet.... all these models inherited from Product model).Based on these models I also have Forms (LaptopForm, NetbookForm...so on).
In my action class I get Model name and assign it to template :
$modelForm = $this->modelName.'Form';
$this->form = new $modelForm();
Then in my template I do that <?php echo $form ?> ..There is no problem it prints all fields and labels in html table.
But my problem is that I want to divide template in to 2 parts. General and special fieldset.In general fields set i want to display Product model fields(name,price...).But Special field set changes according to product type. How I can handle this special fields set?Can someone give a clue or source please?
Thanks in advance!
You can manage it manually, in your specialized form class (not alter the base class).
Perhaps, with the use of sfWidgetFormSchema :
http://www.symfony-project.org/forms/1_4/en/A-Widgets#chapter_a_sfwidgetformschema
You have to name the widget 'general' and 'special', for a stanhdard re-use in form template, like this :
<?php echo $form['general'] ?>
<?php echo $form['special'] ?>
I've created custom form using FAPI for my site. And I place each control at specific location base on template provided by the designer. For instance -
<div id="myform">
<span>Enter Your Name : </span> <?php print drupal_render($form['name']); ?>
<span>Gender : </span><?php print drupal_render($form['gender_radio']); ?>
....
</div>
<?php print drupal_render($form['submit']); ?>
Here's my question - How do I enclose all the elements inside form tag? Is hardcoding the form tag inside the template file right way to do in drupal? or is it better to create in hook_form? But doing so would require me to add closing form tag at the end manually. Any suggestion would be highly appreciated.
Drupal - 6.x
It sounds like maybe you read about building individual fields, but skipped over some basic concepts of FAPI. In short, if you call the form with drupal_get_form(), you get the form container (and many of the benefits of using FAPI, e.g. tokens, validation, etc.) automatically. To handle the markup that goes around your form elements, you can then use #prefix, #suffix, and markup elements.
You can assemble the whole form from the outside in like you're doing, but there are few cases in which that would really be worthwhile. If you really want to do that, you basically want to copy what drupal_get_form() does to get the form wrapper added in a way that will work with FAPI.