This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
new password field
Started 15 years ago by souda | 13 posts |
-
Hi,
I have two questions:
(1) I would like to add a new field type to the form which is not available in the form editor. This field is supposed to be password, so it should have type="password" in the final form (entry replaced with dots when typed). And also, I would like it to have a unique field name in the table created for the form (I'm going to use it later, so it would be easier if it had a unique name). Could you please give me some advice where to start and which scripts to modify?
(2) Is it possible to add additional validations for certain fields? For example, if I have a password field (see above) I would like to have a second password field next to the first one so a user is asked to retype the password. Then these two fields should match before the form is submited.
Thanks a lot in advance...
Posted 15 years ago # -
I'm afraid it would be quite difficult to add a new field type. It requires a lot of code across multiple files.
I suggest to just hack the current function which display the text field to display password field based on certain condition.
You need to modify "includes/view-functions.php" file, at the top you will find "display_text()" function. Adjust this function to display as password field.
Regarding additional validation, if you need to compare two fields, you need to modify "process_form()" function in "includes/post-functions.php".
Add the code which do the checking there.
You can access the value of your form fields by using the "$input" array. Try dumping the content of this array to see what inside of it.MachForm Founder
Posted 15 years ago # -
Yuniar, Thanks for this great form builder! Nice work (-:
It would be great to have a password field added to the forms. I read that about 11 months ago you had added this to the feature requests here: http://www.appnitro.com/forums/topic/password-field?replies=3
What is the time line for adding this feature to your product?
Posted 15 years ago # -
Thanks a lot for the pointers! I have already modified display_text() function, it displays an input field as a password field if its title is "Password" or "password". That takes care of the issue for now. As to the additional validation, I'll see if I can manage to make it work in process_form().
Thanks again, and congratulations on a very nice piece of software.
Posted 15 years ago # -
Can you share how you did that souda?
Posted 15 years ago # -
I would like to set the <input type = "password" name="passwd"> but I am not sure how to code based on the condition of the name of the field being set to password, here is the code that I think I have to change can someone help?
//Single Line Text
function display_text($element){//check for error
$error_class = '';
$error_message = '';
$span_required = '';
$guidelines = '';if(!empty($element->is_error)){
$error_class = 'class="error"';
$error_message = "<p class=\"error\">{$element->error_message}</p>";
}//check for required
if($element->is_required){
$span_required = "<span id=\"required_{$element->id}\" class=\"required\">*</span>";
}//check for guidelines
if(!empty($element->guidelines)){
$guidelines = "<p class=\"guidelines\" id=\"guide_{$element->id}\"><small>{$element->guidelines}</small></p>";
}//check for populated value, if exist, use it instead default_value
if(isset($element->populated_value['element_'.$element->id]['default_value'])){
$element->default_value = $element->populated_value['element_'.$element->id]['default_value'];
}Posted 14 years ago # -
there is already a password field, for each form you create,
Posted 14 years ago # -
Hi just got this and WOW, its amazing,
But I to need a password field on the form that users can add a password to and have the text obscured from sight.Just to be clear, I know I can password protect an entire form, but I want to just have one of the fields in a form obscured as a password box should be.
I am told its a "simple hack" but if someone could post the steps and code needed I would be very grateful.
Thanks in advance,
Ed
Posted 13 years ago # -
Hi Ed,
It's quite simple indeed.
Let's take a look an example with this form:
http://www.appnitro.com/forms/view.php?id=40The form above is having id number = 40
Our goal is to change the "My Password Field" textbox into a password field.First, right click on that form and view the HTML source of the form.
You'll see that "My Password Field" is having this code:<input id="element_1" name="element_1" class="element text medium" type="text" value="" />
this means that the field is having element id = 1
Now, you need to edit your "includes/view-functions.php" file.
Search around line 40 for this block of code:$element_markup = <<<EOT <li id="li_{$element->id}" {$error_class}> <label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label> <div> <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" /> </div>{$guidelines} {$error_message} </li> EOT;
You need to change it to become like this:
$field_type = 'text'; if($_REQUEST['id'] == 40 and $element->id == 1){ $field_type = 'password'; } $element_markup = <<<EOT <li id="li_{$element->id}" {$error_class}> <label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label> <div> <input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="{$field_type}" value="{$element->default_value}" /> </div>{$guidelines} {$error_message} </li> EOT;
Just make sure to change the form id number and element id number above with your own id numbers.
MachForm Founder
Posted 13 years ago # -
AWESOME!
Worked first time!MachForms is better than I could have possibly hoped!
I keep thinking of different ways to use it. You rock!
Posted 13 years ago # -
Quick follow up question if I may...
What if I want to run this on multiple forms? How would I change the code so it wasent just doing it with the one field on the one form?
Posted 13 years ago # -
It's pretty easy. Each form would have its own id number and the text field also having its own id number. All we need to do is to add the conditions.
So let say you have three forms, you can change this code:
if($_REQUEST['id'] == 40 and $element->id == 1){ $field_type = 'password'; }
to become like this:
if( ($_REQUEST['id'] == 40 and $element->id == 1) or ($_REQUEST['id'] == 41 and $element->id == 3) or ($_REQUEST['id'] == 42 and $element->id == 4) ){ $field_type = 'password'; }
simply change the above form id number and element id number based on your own forms.
MachForm Founder
Posted 13 years ago # -
Awesome, thanks. :)
Posted 13 years ago #
Reply
You must log in to post.