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
READ ONLY field
Started 15 years ago by startagl | 8 posts |
-
I would like to have a read only field. This information will be passed into the form via a POST. It does not have to be a field as long as I can show it on the form.
Posted 15 years ago # -
Can you explain a bit more? read only field with a fixed default value?
Or do you want to display a plain text?
MachForm Founder
Posted 15 years ago # -
I would like to send data into the form from a link www.mylink.com?data=mydata
I then want to display mydata on the form but not allow the user to change the data. Thus is it read only, view only, display only. - Thx
Posted 15 years ago # -
You might want to check this thread:
http://www.appnitro.com/forums/topic/dynamic-content-php?replies=23MachForm Founder
Posted 15 years ago # -
Awesome. That works great. The further submissions by others makes it more universal. Terrific. Thank you.
Posted 15 years ago # -
After better review the post at http://www.appnitro.com/forums/topic/dynamic-content-php?replies=23 only gets me half way there. It allows me to accept data passed into the form but it does not make the field readonly.
How do I set a field to READONLY i.e. <INPUT NAME="realname" VALUE="Hi There" READONLY>
I am not opposed to using the Default Value field to trigger the READONLY option. For example I have done the following for GUID.
In include/view-functions.php after line 1682 as directed in other posts. I have added the following code.
$is_guid = strpos($element[$j]->default_value, 'GUID');
if ($is_guid !== false) {
$guid_token = md5(uniqid(mt_rand(), true));
$element[$j]->default_value = $guid_token;
}
What this does is look at the default_value of the field and if it is set to GUID a guid token will be generated and assigned to the field as the default value. Given that I am using strpos to inspect the default_value I can use something like GUID_RO to not only set the field as a guid but also as READONLY.I just do not know where to change machForm so that I can insert the READONLY attribute into the html markup.
I hope this makes sense.
Posted 15 years ago # -
You can modify that same file to put the attribute.
For example, to add the attribute to the single line text field, you will need to modify "display_text()" function.
search around line 40 and you'll see the HTML markup for the text field:
$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 can insert the read only attribute there.
Other fields has their own respective "display_xxx()" function. So you will need to modify each of them, based on the field type.
MachForm Founder
Posted 15 years ago # -
To close out this thread the following is how I added READONLY attribute to the machForm script. Make the changes as noted below. Depending on the changes you may have already made to your code the line numbers may be wrong, in that case just look for the code.
line 11, change
function display_text($element){-to-
function display_text($element, $ro_value = ''){
line 43, change
<input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" />-to-
<input id="element_{$element->id}" name="element_{$element->id}" class="element text {$element->size}" type="text" value="{$element->default_value}" $ro_value />
line 1683, add
//APS - following lines will make a field READONLY if the default_value field has RO
$is_guid = strpos($element[$j]->default_value, 'RO');
if ($is_guid !== false) {
$ro_value = "READONLY";
}
//APS - doneline 1742, change
$all_element_markup .= call_user_func('display_'.$element_data->type,$element_data);-to-
$all_element_markup .= call_user_func('display_'.$element_data->type,$element_data,$ro_value);
line 2080, change
$all_element_markup .= call_user_func('display_'.$element_data->type,$element_data);-to-
$all_element_markup .= call_user_func('display_'.$element_data->type,$element_data,$ro_value);
------------------------------ END OF CHANGES
HOW TO USE:
In the default value option of the form design put RO as the defalut value. To assign a default value and use the RO hack you need to add code after you have inspected the RO value to strip out the RO part of the default value.
Hope this makes sense. Maybe the next version of machForm will have this as an option instead of a hack. -Thanks-
Posted 15 years ago #
Reply
You must log in to post.