How to call user registration form in php - php

I am trying to call the default joomla user registration form through a custom module with link. I created a popup box and i would like to show the user login and user registration inside that popup box. I just need the call for the forms. Thanks

You can use the getInstance() method of JForm where the first parameter is the name form (arbitrary) and the second parameter is the absolute path to the xml containing the form (in joomla forms are created with xml files).
<?php
/* #var $form JForm */
$form = JForm::getInstance('formName', JPATH_BASE . '/components/com_users/models/forms/registration.xml');
foreach ($form->getFieldset() as $field) {
echo JText::_($field->label);
echo $field->input;
}
?>
Hope this helps :)
Stoyan

The custom module should be published to a component if you want to be able to access it. You can achieve this with com_content and the {loadposition } code.
Once you have your module in a component, you need to figure out a link to it, it could be:
http://example.com/index.php?option=com_content&view=article&id=115
of a sef-url if you define a menu item.
To invoke just the component (thus the module's) output, add
&tmpl=component
to the url, this will tell Joomla to only render the component and not the full template

Related

CakePhp: add a customized URL in $content_for_layout

I am working in cakephp application.
Here all the calls happening with Ajax. So user wants to keep one button or link, when user click on the link it will show one with contains help info of that page. I'm able load div with right content. But dynamically I'm not able to display one link (Show Help) on the page dynamically.
The reason for the "Show Help" link dynamic is based on which page loads I have to pass value to JavaScript function.
Plz help me how to add this link in $content_for_layout so that it will display dynamically in all the pages.
Step1: This is the code to create helper. Put the following code in app/views/helpers/LinkHelper.php
class LinkHelper extends AppHelper {
var $helpers = array('Html');
function showHelp() {
$url = '';//create your url dynamically here
$title = 'Show Help';
return $this->Html->link($title, $url, array('class' => 'help'));
}
}
Step2: Load the Link Helper in layout
$HelpLink = $this->Helpers->load('Link');
Step3: Call showHelp method of LinkHelper where Show Help link to be shown.
echo $HelpLink->showHelp();

Add custom code into Drupal 7 webform

I'm looking to add a custom captcha input into a Drupal Webform. The captcha I wish to use isn't available as a plugin so I want to hook the form as it is output and then add my captcha presentation script.
I already know how to catch a form with <theme>_form_alter(). What I'm not so sure of is how I can inject elements into the form at a certain point. If anyone knows of how to achieve this it would be useful.
You could add your script with a preventDefault on the form submit. Do your client-side validation then submit the form. Adding your javascript would be as follows:
/**
* Implements hook_form_alter().
*/
function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
dpm($form_id);
if ($form_id == 'YOUR_FORM_ID_HERE') { // Example Form ID: webform_client_form_23
$form['#attached']['js'][] = drupal_get_path('module', 'MODULENAME') . 'path/to/example_file.js';
// OR
drupal_add_js(drupal_get_path('module', 'MODULENAME') . 'path/to/example_file.js');
}
}
You can do it with ease by overriding the default form creation. Create a file in your template folder for your webform say its webform-form-22.tpl.php..
Use the $form variable which is available by default. Place the form elements from the $form variable and place your custom captcha according to your requirement anywhere in the form, and validate in the hook custom_module_webform_submission_insert..

Drupal 7 - how to add another button to a webform?

I was wondering, does anyone know how can I add another button to a webform in Drupal 7 in addition to the submit button? I tried looking through Google as well as asking this question at the Drupal forums, with no luck. Could anyone please help?
Webform is a drupal form and you can use hook_form_alter: Lets say you have a custom module called mymodule and your webform id is 'webform_client_form_XXXXX'. Then use the sample code below.
/**
* Implements hook_form_alter.
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
case 'webform_client_form_XXXXX':
$form['actions']['custom_submit'] = array(
'#type' => 'submit',
'#value' => t('Custom Button'),
'#submit' => array('mymodule_custom_submit'),
);
$form['#validate'][] = 'mymodule_custom_validate';
break;
}
}
/**
* Custom validation handler for your webform.
*/
function mymodule_custom_validate($form, &$form_state) {
// your validation code
}
/**
* Custom submit handler for your form
*/
function mymodule_custom_submit($form, &$form_state) {
// your submit handler code
}
UPDATE:
You would have to substitute instances of mymodule in the above code with yoru modules's name. Also i have modified the hook_form_alter a little. I suggest you move your submit button under $form['actions'], so it would appear next to the current submit button.
To Clear Cache:
visit /admin/config/development/performance and click on Clear all cache button.
To find the weform form-id:
This tutorial on net discuss about how to find the form id. Please note that the id used in the form tag will have '-' (hyphen), that has to be replaced with '_'(underscore) to get the form-id.
Another method is to print the $form_id variable in hook_form_alter ( the function which we have defined above ) and visit the webform page. If there are no other forms on that page the printed id would be the one that correspond to webform. If you enable devel module then it is easier to display debugging information using excellent krumo library.
/**
* Implements hook_form_alter.
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
// Below function would print out the form id in message area if devel module
// is enabled on the site.
dpm($form_id);
switch ($form_id) {
remove dpm( $form_id ); afterwards.
Knowing the webform id is easier than the methods described above. You only need to go to: content->webforms and place the mouse cursor over the edit option belonging to the webform you want the id.
Down the navigator screen the original path in the format node/id will appear. That node number is the XXX in webform_client_form_XXX.
You can use type Markup in webform. Theme the markup as it look a like the button same as your submit button.
and write JS for that. For e.g, you want to give reset button then onclick event should empty the values in those fields. Try this.
first create markup in webform for button then use java script for that when click on this it process request based on your requirement.

Problem with Auto Complete Concept in Symfony

I am working on a Symfony application that works mainly with form submissions and our team needed extreme customisation on validations therefore we chose to not use the forms helper and widgets. Now each form has an action method for submission and retrieval. In between one of those forms I need an auto fill but I don't know how I should send this to a new action method on the keyup event and return data from there. I am completely unable to return the data from there I have checked using Firebug. I have found articles that submit the whole form for a search auto fill. I can't do that because my auto fill field is not the only one on the form. It's a city field which I have to give suggestions on. I am expected to use the jQuery framework. Please help.
Moreover I don't understand the AJAX concept in Symfony very well. It would be really helpful if you could link me to some good articles.
Appreciate all the help.
Thanks a lot.
The main difference of response in Symfony for ajax request is the action wouldn't decorate the view (actionSucces.php) with the Layout (so it won't include the web debug toolbar either).
In your case, you can use the jQuery Autocomplete plugin (http://docs.jquery.com/Plugins/autocomplete) to produce your extreme customisation form :D
you can use slot to define your jQuery object definition in layout
<head>
<?php if (has_slot('head_script')): ?>
<?php include_slot('head_script') ?>
<?php endif ?>
</head>
define your jQuery Autocomplete in the extreme customisation form template
<?php slot('head_script') ?>
<?php echo javascript_tag('$(function{
$("#example").autocomplete("'.url_for('search/cities').'");
});') ?>
<?php echo form_tag('form/result') ?>
<?php echo tag('input', array('name'=>'example','id'=>'example'));
</form>
don't forget to include your jQuery and Autocomplete plugins, when user start typing a request sent to specified backend with a GET parameter q that contains the current value of the input box and a parameter "limit" with the value specified for the max option. (please refer to the doc :D )
now create action search/cities and use $request->getParameter('q') to populate the response
public function executeCities(sfWebRequest $request){
//process the $request->getParameter('q')
return $this->renderText("First Second Third Fourth");
}
cheers and happy new year :D

hook_form_FORM_ID_alter not called after 'Submit' or 'Preview' is clicked

In a custom module, I have the following (to add javascript to a particular form):
function mymodule_form_mynode_node_form_alter(&$form, $form_state) {
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/mymodule.js', 'module');
}
This function does get called the form is first loaded (i.e. browse to http://myserver.com/node/add/mynode) however this php function does not get called when the same form is reloaded after the form has been invalidated (i.e. missed a required field after clicking 'Submit' or 'Preview').
What do I need to do to have the javascript file added after 'Submit' or 'Preview' is clicked?
Thanks,
John
To solve your problem, you'll need to create a theme function for the form where you render the form and add the js file.
You form alter is only called when the form is build. As forms are cached between request, the same and already build form is used on submit and preview.
You need to unsure that your code is called each time the form is rendered. As pointed out by googletorp, one way to do it is to use a custom form rendering function. You can also do it by attaching a post or pre-rendering function to your form. Actually, the custom, pre or post rendering function doesn't need to be for the form itself and can be used on any form element. Preferably the one which behavior is altered by the JavaScript.

Categories