How do I create the widget automatically on PyroCMS? - php

I'd like to develop a module as an event with registration form. An event is actually a page module with slight modification by adding some fields such registration form url. When the controller return a view, I'd like the controller to return a registration form widget along with the event info (article) and a google maps widget.
Imagine a widget class:
<?php
class Registration_Form_Widget extends Widget{
......
}
My question is:
Is it possible to create widget dynamically (I mean the creation of widget instance is dynamic (not the content) such using new Registration_Form_Widget and bypass the parameter such the registration form url that has been stored to the database?
So far, I never see an example that show how to create widget instance dynamically with automatic increment id
thanks...

Nope, widgets are created whenever you create em.

Although it is obviously possible to achieve it with a bit of code.
There is no "magic function" to do that automatically, but you can look into the widget module files to understand what is done when a user create a widget in the admin CP. And then you could reproduce the behaviour yourself.

Related

Sylius add admin Page

I'm trying to create an extra admin page in Sylius. However, the documentation does not explain how to create a new admin page. The page I want to create is a subcategory page.
I did manage to create a new route and to create a new controller, but the template uses a lot of functions that are not included in my custom Controller.
Do I need to extend my custom controller with CreatePage or something?
If your page represents a CRUD operation on an entity, then this page will help you do a basic setup.

Can I create a custom WordPress registration form?

I want to have in WordPress two kind of registration forms. The default one for let's say visitors users and a custom one for some more privileged users. How can I make the custom one? I especially need the part with the roles, the custom reg form will have another role for the users that will register to it. How can I do that? I think I need something like(it's just a fabulation, don't know the real functions from WordPress)
Example:
//the following variables will be a part of the form that will stand above this function
add_user('$username','$mail','$location','$region','$role');
//where $role can be {1(subscribers),2(contrib.),3(authors),4(editor),5(admin)}
Can I do something like that?
You can use Gravity Forms to create your registration forms with the User Registration add-on and specify custom user meta (including roles.) If you would like to create a custom form without a plugin, you should not attempt to add users directly to the database, instead you should use the wp_create_user function. From the WordPress Codex:
The wp_create_user function allows you to insert a new user into the
WordPress database. It uses the $wpdb class to escape the variable
values, preparing it for insertion into the database. Then the PHP
compact() function is used to create an array with these values. To
create a user with additional parameters, use wp_insert_user().
You can install a webform module in wordpress. Selected an existing form and customize the fields as per your requirement.

yii widget render partial view of another controller

I need to create universal dialog widget for different modules in my yii-powered project, with form which will be auto serialized and passed to controller action for add/update operations.
Is it a good practice if I call render partial method in overloaded run() or init() method of my widget and pass him custom view path with html form (this form will be shown in modal dialog window after dialog-btn click action accordingly)?
My widget path:
/protected/components/widgets/DialogFormWidget.php
My forms path:
/protected/modules/module/controller/views/forms/submittable_html_form.php
go with
$this->renderPartial('application.modules.controllers.views.forms.submittable_html_form');
UPDATE :
in above code, $this refers to the controller, if you want to use controllers renderPartial from inside a widget, you have to access it like $this->controller->renderPartial (
Even you can use path to your view file to access it from other controller ($this->renderPartial('application.views.controller.view', []) , or path to any place where your view live on system), this is not good solution. Better solution is to create Yii widget so u can easy call it from all places because its controller independent. You will have also lot of benefits since with Yii widgets u have option to send some widget configuration parameters that can be used to customize widget and even load different views/style based on that parameters. Also you will have good place for custom functions that can help to add some business logic to your view and similar.
You can find some start point for this here (http://www.yiiframework.com/doc/guide/1.1/en/basics.view)

Using multiple form field widgets for the same field in Drupal

I would like to be able to use multiple form field widgets for the same field and to be able to switch it based on session data from the user. But I am not really sure how to accomplish this. This is for Drupal 6. Any ideas on how to accomplish this?
You might be able to accomplish this with one of the field access modules but to do it properly you'd probably need to create a custom widget. Your widgets can return existing widgets by calling their handles, so your widget would more or less be a wrapper that returns the correct widget call.
this tutorial gives a pretty good overview of widget creation in Drupal 6.
What I ended up doing was creating a second form field that uses the filefield upload widget and loaded it on the form alongside the Flash widget. Then I put JS on the page that detects if Flash is on the page and is of the correct version. If it is found then it hides the html/AJAX uploader. If it is not then it hides the Flash uploader.

How should I go about capturing a custom form in Magento that is stored with the order?

I am working on a module to add a new step called Rental into the Onepage Checkout module in magento. The problem is not adding a step it is the data capture.
I want to be able to take the custom form I have created and store it with the rest of the order information so when I click view order in the backend, it shows the information in the form as a seperate box.
Preferably I want to seperate the concerns by creating a standalone module.
How would you go about doing this? What would be your personal strategy for implementing this?
Firstly, it should all depend on what data 'Rental' would be. Could it fit/be appropriately placed inside a product's custom option? Or do you need to create a custom sales attribute to store the data in?
If you want the latter, you should use Magento Module Creator by SilkSoftware to create a module to implement sales attributes.
Also: a good thread / scenario in using sales attributes: Magento: Setting a custom attribute on the sales/order_shipment model
Secondly, is capturing the form data -- this is assuming you already have a block/form created and showing on the checkout page. I highly encourage you name the fields in the following semantic:
<input type="text" name="rental[text_data]" />
<input type="text" name="rental[text_data2]" />
Where text_data and text_data2 are your desired variable names.
An order is submitted / saved finally via a Controller action called saveOrderAction in Mage_Checkout_OnepageController or whatever Controller class you are using currently for your checkout page. Don't edit the corresponding PHP Class file for this found at app/code/core/Mage/Checkout/controllers/OnepageController.php ! Since you want to separate this into another module, you should try and rewrite this controller then so that your custom Controller class inside your module that extends the aforementioned base class (Mage_Checkout_OnepageController) should be used by Magento in its stead.
A good tutorial on rewriting controllers can be found here.
You can then do either of the two options from here:
1.) you could copy the entire saveOrderAction function and create routines to save Rental data there. if you followed the naming semantic I suggested, you should be able to retrieve the form data doing so:
<?php
// app/code/local/Namespace/Module/controllers/Checkout.php
class Namespace_Module_Checkout extends Mage_Checkout_OnepageController {
public function saveOrderAction() {
.....
$this->getOnepage()->getQuote()->save();
$rental = $this->getRequest->getParam('rental');
$text_data = $rental['text_data'];
$text_data = $rental['text_data2'];
someSaveRoutine($text_data, $text_data2);
//..or someSaveRoutine($rental);
.....
}
}
2.) secondly, you could replace the above code with a custom event dispatch
$rental = $this->getRequest->getParam('rental');
Mage::dispatchEvent('checkout_onepage_controller_saveorder', array('rental'=> $rental));
then make an appropriate observer to save your custom data somewhere.
I know this isn't much, but it's a start. I will look into editing this to elaborate more in the near future.

Categories