Modifying individual field form inputs (CSS, Placeholder, etc) Drupal 7 registration form preprocess - forms

I'm attempting to preprocess CSS and placeholder etc to the form inputs for the Registration Form. I'm manually rendering each field input on the registration form.
The following code works fine for email or password, but not 'custom fields'.
$form['account']['mail']['#attributes']['placeholder'] = t('Email address');
$form['account']['mail']['#attributes']['class'][] = 'email-input';
$form['account']['mail']['#title_display'] = "invisible";
$form['account']['mail']['#description'] = t('');
When I apply the same to the custom fields, it won't apply.
I have looked through the user module and printed avialable varibles
$form['field_first_name']['#attributes']['placeholder'] = t('First Name');
$form['field_first_name']['#attributes']['class'][] = 'first-name-input';
$form['field_first_name']['#title_display'] = "invisible";
$form['field_first_name']['#description'] = t('');
I found multiple mentions of field_first_name in the variable print out, but I'm unable to modify the text inputs directly.

Related

Django - Modelform with override password field : initial value not visible (and not saved) in Based UpdateView

I use a form for handling FTP/SFTP (files) accesses. They can be sometimes updated.
My password field is a Charfield (not required) in my model but I wan't to hide it on updates. I use Bcrypt when saving it.
For this I followed the example here for adding the PasswordInput() widget to my field. I use Crispy so my form in my template is just displayed with {% crispy form %}.
class FlowStockAutoForm(forms.ModelForm):
class Meta:
model = FlowStockAuto
exclude = ['fl_st_auto_report_cross_import', ]
fl_st_auto_pwd = forms.CharField(widget=forms.PasswordInput,
label="Password",
required=False, help_text="BlaBla")
def __init__(self, *args, **kwargs):
super(FlowStockAutoForm, self).__init__(*args, **kwargs)
pwd = self.instance.fl_st_auto_pwd
self.fields['fl_st_auto_pwd'].initial = pwd
In Django Doc, it's recommended to set an initial value with init (as done above) but when the password widget is active, on my update template, the field remains empty. So if I just wanna update another field, when I save, password is saved blank. It's ok when the Password Widget is off.
I would like it to be prefilled but "blurred" and check when saving if its value has changed.
What do I miss ?
Visibly almost duplicated question
had to change from
fl_st_auto_pwd = forms.CharField(widget=forms.PasswordInput,
label="Password",
required=False, help_text="BlaBla")
to
fl_st_auto_pwd = forms.CharField(
widget=forms.PasswordInput(render_value=True))
by adding render_value=True
I also had to remove
label="Password", required=False, help_text="BlaBla"
and replace it with
self.fields['fl_st_auto_pwd'].label = 'Password'
self.fields['fl_st_auto_pwd'].help_text = 'BlaBla'

TYPO3: Special tt_contenttype. Modify content before output

Can I create a "special" type of tt_content, so text is beeing processed in some custom ways before outputtet?
In my case I would like to add ###MY_MARKER### somewhere in header and/or bodytext and have it replaced by the right words for the given page.
eg:
When visiting this page: mypage.com/?marker=test
Header in tt_content: "Welcome to ###MY_MARKER##, enjoy
Output in browser: "Welcome to TEST, enjoy"
I CAN do it by making a custom plugin. Question is more if I can reuse normal tt_contant for the same purpose
Yes, you can easily extend the tt_content by adding your own TCA configuration to the typo3conf/extTables.php file:
t3lib_div::loadTCA('tt_content');
$TCA['tt_content']['columns']['CType']['config']['items']['user_my_type'] = array(
0 => 'My custom content',
1 => 'user_my_type',
2 => 'i/tt_content.gif',
);
$TCA['tt_content']['ctrl']['typeicon_classes']['user_my_type'] = 'mimetypes-x-content-text';
$TCA['tt_content']['ctrl']['typeicons']['user_my_type'] = 'tt_content.gif';
/* In the following either copy, insert and modify configuration from some other
content elemenet (you can find it in the ADMIN TOOLS -> Configuration - $TCA)... */
$TCA['tt_content']['types']['user_my_type']['showitem'] = '';
/* ...or assign it some other configuration so that it's exactly the same
as some other content type and stays the same after some update of TYPO3: */
$TCA['tt_content']['types']['user_my_type']['showitem'] = $TCA['tt_content']['types']['text']['showitem'];
After that, just set in your Typoscript template how the element is supposed to be rendered:
tt_content.user_my_type = COA
tt_content.user_my_type {
10 = TEMPLATE
10 {
template = TEXT
template.field = header
marks {
MY_MARKER = TEXT
MY_MARKER.value = TEST
}
}
20 = TEMPLATE
20 {
template = TEXT
template {
field = bodytext
required = 1
parseFunc = < lib.parseFunc_RTE
}
marks < tt_content.user_my_type.10.marks
}
}
NOTES
The Typoscript rendering is just a simplified example. You might want to add other standard configuration like in other elements, e.g. the one that adds edit icons for frontend display.
The marker in my example can be populated by the value of a GET paramater in the URL as you wanted but this would have nasty security implications. You would certainly need very good validation of that input.

On a HTML Edit form, what is a good approach to have both reset and remember the posted values features?

I have a form which has both server side and client side validation.
It is an edit form, so the original user values are originally pre-populated.
e.g. The original pre-populated values are:
username = yeo
surname = yang
phonenumber = 11-12345
Now, the user edits to the below and submits.
e.g. The edited submitted values are:
username = yeoNew
surname = yangNew
phonenumber = 12-1111
This gets submitted to the serverside and fails the serverside validation because the phonenumber starting with 12 is not allowed.
Anyway, so the form is displayed back to the user as
e.g. The redisplayed form values are:
username = yeoNew
surname = yangNew
phonenumber = 12-1111
This is because my form allows the user to remember their submitted values.
At this stage, I'd like to allow the user to have the ability to reset the form values to the original values using clientside javascript. This is like a reset feature.
e.g. The reset button will restore the form values to:
username = yeo
surname = yang
phonenumber = 11-12345
The reason for this reset feature is that I want the user to have the option to edit the phonenumber again from the original values.
My question is:
What is a good way to keep track of the original values within the HTML so that I can restore it with javascript?
I'm thinking a new attribute called orig='' within the form elements which will store this value.
Is that a good idea?
Any other approaches?
thanks
I would use the HTML5 local storage.
See http://www.w3schools.com/html/html5_webstorage.asp
Using jquery I would do it this way:
<script type="text/javascript">
function load() {
if (localStorage["username"]) {
$('#username').val(localStorage["username"]);
}
if (localStorage["surname"]) {
$('#surname').val(localStorage["surname"]);
}
if (localStorage["phone"]) {
$('#phone').val(localStorage["phone"]);
}
}
function save() {
localStorage["username"] = $('#username ').val();
localStorage["surname"] = $('#surname').val();
localStorage["phone"] = $('#phone').val();
}
</script>

Contactform 7 Placeholder Validation

I'm using Contactform 7 for Wordpress. I've edited the text.php and textarea.php to enable the use of placeholders. That works fine.
But, the validation isn't working for some input fields, 'cause the validation thinks the placeholder is the actual text being validated. And yes, ofcourse that validates true 'cause it's not empty.
My input fields with placeholders are as follows:
Your name
Your e-mailadress
Your telephone number
and so on.
In contactform 7's scripts.js I want the validation to check if the input isn't the same as the placeholder. So if the input value is the same as the placeholder value, do the CF7's error validation.
Any idea?
In scripts.js of the contactform 7 plugin folder
Change this:
var submit = form.find('input:submit');
if (! submit.length) return;
with this:
var submit = form.find('input:submit');
if (! submit.length || submit == this.find('[placeholder]').wpcf7Placeholder()) return;

How to populate zend form field using session?

I am using sessions to populate a multi select box with options in my Zend application.
The user selects one or more options and fills in other fields on the form and then submits. If the user didn't select all of the options in the multi select then the form is displayed again but the multi select only has the options that the user did not select the last time. This process goes on until there are no more options from the multi select left to process.
Here is the code I use to get rid of the options that have already been processed so that they are not used to populate the multi select box:
if($form_successful){
// TODO remove $post['keyword_names'] (i.e. already processed) from $keyword_names (that come from $_SESSION)
$keyword_names = array_diff($keyword_names, $post['keyword_names']);
print_r($keyword_names);
if(is_array($keyword_names) && !empty($keyword_names)){
// save updated $keyword_names into $_SESSION['workflow1']
$session = new Zend_Session_Namespace('workflow1');
$session->keyword_names = $keyword_names;
// set flag to false so that we display form again
$form_successful = false;
}else{ // all keywords have been assigned
// go to next step
$this->_redirect('/workflow-1/step-'.($step+1).'/');
}
}
print_r($keyword_names); displays the correct options, however when the form is loaded when the user submits, the multi select displays the options that were there from the begining ie the options the user has just selected and submitted are not being taken out of the multi select, it is only when the user submits the form again then the multi select box updates.
Appreciate the help.
Solved the issue by making use of URL parameters. Here is the code (might differ a lot from what I posted first because some big changes were made):
// after successful form submission
if($form_successful){
// remove $post['keyword_names'] (i.e. already processed) from $keyword_names (that come from $_SESSION)
$keyword_names = array_diff($keyword_names, $post['keyword_names']);
// save remaining $keyword_names into $_SESSION['workflow1']
$session = new Zend_Session_Namespace('workflow1');
$session->keyword_names = $keyword_names;
if(is_array($keyword_names) && !empty($keyword_names)){
// redirect to the same step again - to ensure that the form will reflect (in select lists) newly created AdGroup and/or Campaign
// GET parameteres ($params_array) provide a way to remember user's choice
$params_array = array();
if(!empty($post['match_type_id'])){
$params_array['match_type_id'] = $post['match_type_id'];
}
if(!empty($post['with_permutations'])){
$params_array['with_permutations'] = $post['with_permutations'];
}
if(!empty($ad_group_id)){
$params_array['ad_group_id'] = $ad_group_id;
}
$this_step_url = UrlUtils::assemble('', $this->getRequest()->getActionName(), $this->getRequest()->getControllerName(), $this->getRequest()->getModuleName(), $params_array);
$this->_redirect($this_step_url);
}else{ // all keywords have been assigned
// go to next step
$this->_redirect('/workflow-1/step-'.($step+1).'/');
}
}
So you don't have any code about Zend_Form object here. How do you populate the form element? If you post your class code which extends Zend_Form (or any other code dials with your form) then I may help. But in any case you can populate your multiselectbox with setMultiOptions() method or addMultiOption() for each item in multiselectbox.