Cake PHP Form Flexibilty - cakephp

I want to replicate the html that the cakephp form helper creates, so i can add to it and integrate it into my bootstrap front end. Basically the cakephp form helper isnt generating the html I need.
Someone else built the app using cake forms, and I dont want to rewrite the backend.
I thought it would simply be a case of including the correct input names, form classes etc, and building upon it. It seems however that even an exact copy/paste of the form html doesnt trigger the cakephp form errors.
It sends identical headers to cake,
http://pastebin.com/JZyCk6cv
so I can only assume that the cakephp form helper does some jiggery pokery when its constructed in the template, in order to trigger validation errors?

I think the best solution is to create a custom CakePHP-Helper. If you're using twitter-bootstrap i recommend this Helper, packed as a plugin:
https://github.com/loadsys/twitter-bootstrap-helper
Form validation should work, as it uses CakePHP's core form-helper to create inputs and labels.
Maybe you don't have to rewrite or edit much if you use search and replace (replace $this->Form->input by $this->TwitterBootstrap->input).

Related

Wagtail Form static fields & superuser-only page

I did not found any answer to this. So is there a way in Wagtail to have an AbstractEmailForm without AbstractFormField (for example, can I hard code them into AbstractEmailForm? I know that AbstractEmailField has some variables that Django requires). I just need to have a contact form only with email field, I dont need to set fields dynamically.
And the second question: How do I set permission for that form page so that only superuser can edit the form page?(And the translated version too? There are a lot of answers to this, but I don't actually understand how to do it with AbstractEmailForm).
Thanks a lot!
If you're hard-coding your form fields, then the Wagtail forms module doesn't really give you anything that you don't already get from Django's forms framework, and so you're better off using Django forms directly. The serve method on a Wagtail page is equivalent to a Django view function, so any form-processing logic that would normally go into a view function can be placed in serve.
There's an example of this here (but written for Wagtail 1.x, so imports will need adjusting): https://github.com/gasman/wagtail-form-example/commits/master

How to create a custom module from Webforms in Drupal 7

I have a form that I am aiming to submit to paypal payment.
I have tried several options like the Paypal API and the like but I can't seem to get the hang of it since the requirement of what I am doing is pretty simple.
Right now I have a form and I am using Webforms to build it. I am well aware that webforms has its default value for action attribute which is not so easy to alter.
Also, the names for the inputs appear to be something like:
name="submitted[last_name]"
To be direct, I would like to change the actions url of the webform and then the field names from to simply name="last_name"
Is there a simple way to do it? If there is, I would appreciate your suggestion.
Also, if what I assume based on my reading that it is not possible, I have read in this question (Using Hook_form_alter on webform submitted values) that I can create a custom module based on webform and make the changes there. The problem is that I am new to drupal and I am still trying to understand how to make things work and I have no idea how to start or create the custom module based on webforms. Is it just simply copying the whole files in webforms then replace all occurences of webforms to my custom module name?
You dont create a module from webforms, instead the usual practice is to hook in to specific form from another module.
Basicly you need 1 folder and 2 files in there, eg mymodule folder and mymodule.info + mymodule.module . Good place to place those would be sites/all/modules/custom/ under your installation directory.
Read the description about .info file at https://www.drupal.org/node/542202
You can connect to webforms in many ways but the standard way in most form tampering cases start with hook_form_alter. Your module could start with something like this
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id){
/* find and tamper with $form here
install devel and then uncomment the following */
//dpm($form);
}

ASP.net Web API: Include validation rules when retrieving models with Data Annotations

I'm currently building a Backbone.js/ASP.net MVC/Web API application and everything is going very smooth :)
When sending data to the server I know I can use ModelState and a ValidationFilter to validate there. However, when retrieving a model from the server, I'd like to include any validation rules that come from Data Annotations so that I can hook them into JQuery Validate or whatever I decide on. In ASP.net SPA you can call dataSource.getEntityValidationRules() from javascript to do exactly that.
I was wondering if there was a way to include these rules whenever I get a model with data annotations from Web API without the use of ASP.net SPA and its javascript libraries?
The benefit of backbone models is that those are are dynamic, so you can create a parser to read the validations form the server and add those validations to the backbone model in the way your pluggin need it, its kind of easy if you only use: required, minlength, max length and a regex but gets harder with ranges or some other kind of validations.
As I said plug those validation requires a some work to build this parser as I think there is no plugging or library for that.

CakePHP Ajax form - cloning form fields

Using cake 2.2. I currently have a form (built using the form helper) that allows users to add expense claims. Each claim consists of many expenses. So the form contains a row for each expense along with a button that uses jQuery to clone the first row of fields and insert them (with incremented ids/names). The problem is when the form is submitted and there is an error, the cloned fields disappears as the page refreshes (I guess because their not in the dom any more).
The values are still in $this->data so I guess I could manually rebuild them but if I made the form submit by ajax would it solve the problem? IE on error the cloned fields would still remain?
Thanks in advance
Things that are built from Javascript will not retain from one page-load to the next.
Either use Ajax (probably ideal), or build out the fields with PHP based on the supplied data.
Either way is fairly "normal" way of doing it.

DotNetNuke -- Inserting URL parameters in forms

We are migrating our website to DotNetNuke and are looking to replicate the functionality of our survey page. Currently, on the bottom of every e-mail we send through our CRM system, there is a link to a satisfaction survey along with some parameters to pre-populate some of the fields. So the URL looks something like like:
/survey.aspx?ticketID=1234&userName=John+Doe
I found the custom module "helferlein_Form" which seems okay for actually creating the form that the user fills in, but I don't see a way to pre-populate the fields. DotNetNuke does let you insert tokens(ex: [Date:now], [User:username]), but I don't see a way to grab individual parameters from the URL. Is there something I'm missing that will let me do that?
I'm not familiar with that module either, but I would strongly recommend using Xmod for customized forms that allow you to easily grab url parameters.
I'm not sure about the module you reference.
However, in my experience Dynamic Forms from Data Springs would fit the bill perfect. It has the ability to pre-fill and even run custom SQL queries to get data.
You should definitely try our My Tokens module.
It allows you to access the URL parameters using [Get:ticketID] or [QueryString:tickedID]. You can also build SQL tokens that use these parameters to return a list of items for example to populate a dropdown.
Also try our Action Form module which integrates very nice with My Tokens.
If you have a module you like and want to use you can always write a little javascript to grab the variables out of the URL and pre-populate your form fields using javascript.

Resources