Obfuscate Form Fields Name And Id.
Posted 29 January 2013 - 04:35 AM
TIP: use captcha
Posted 06 February 2013 - 02:55 AM
I'm not really for obfuscating. But in some scenarios i find it better to have form field names like "query" instead of "SearchForm[query]". Consider such a search form which you want to submit via GET. So you want your search results to be shown under a nicer URL like: ...?query=myQueryString. As a workaround i now render custom form fields. But then i can't use the gimmicks of CActiveForm.
I'm not asking for changing the default which is fine for most cases. I just want more freedom for the experienced developer who knows what he is doing.
So the question is: Will there be a way in 2.0 to modify the way, Yii generates form input names?
Posted 06 February 2013 - 03:46 AM
<?php $form = $this->beginWidget('CActiveForm', ...) ?> <?php echo $form->textField($model, 'query'); ?>
Gives me a input field with name "query" instead of "SearchForm[query]"?
Posted 06 February 2013 - 09:15 AM
This way the OP could also create obfuscated form inputs if he wants to. This is really an advanced feature, though. The developer must understand the consequences (e.g. problems if he submits several models from 1 form).
Posted 06 February 2013 - 09:39 AM
Posted 06 February 2013 - 10:16 AM
Still i disagree with the final conclusion. In my opinion we should not worship MVC as the golden calf if there's good reason to lessen the strict paradigm slightly. I'd say that this is such a case: the framework forces me to do things the Yii way. If i don't (=use my custom form inputs) i can't use many features anymore (e.g. clientside and AJAX based validation). If this can be solved with a minor break in MVC i can't see, why we should not. This is just an unneccesary restriction.
Posted 06 February 2013 - 01:25 PM
I think, if I understand you correctly, you'd need:
- A class for the HTML elements that create attributeName names, instead of Model[attributename] names
- A class/method then you can use to do something like $model->attributes = MikeCAF::transformGetsOfModel('modelName');
Posted 07 February 2013 - 09:05 AM