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

Enable Code in Admin Only Fields?


  1. epsd
    Member

    Just installed under SSL and what a relief it is to have a program like this! Anyway, I have some variables that are being passed from page to page in sessions. I modded the app so that it sees this session data. Works fine. Now, I'd like to get that session data (just a username for example) into an admin only field. In hand coded forms, I'd simply do a php echo of the variable in the value.

    However, machforms just displays the code and not the variable. I realize that this is for security purposes. Is there a way that I can turn off some of this security for the admin only fields? I'm running in a secure environment so I'm not too concerned about it...

    Posted 16 years ago #
  2. yuniar

    Hmm..I'm afraid it won't be as simple as turning off a feature.

    You will need to modify the specific function which display the fields.
    All of them are placed in includes/view-functions.php

    Ok, let say we have a form with form_id = 12 and a 'Single Line Text' field which is set to 'admin only' and has element name element_3.

    To get your session variable into that field. Edit display_text() function. Around line 29 you will find this code:

    //check for populated value, if exist, use it instead default_value
    if(!empty($element->populated_value['element_'.$element->id]['default_value'])){
    	$element->default_value = $element->populated_value['element_'.$element->id]['default_value'];
    }


    Right under that block of code, add this code:

    if(($_REQUEST['id'] == 12) && ($element->id == 3)){
    	$element->default_value = $_SESSION['your_session_var'];
    }


    That should set the default value for that particular 'admin only' field to be the same as your session variable.

    I hope I'm being clear for you.
    Please feel free to ask any question you might have.


    MachForm Founder

    Posted 16 years ago #
  3. epsd
    Member

    sounds easy enough. how do I determine the element name? Is it just what I've named it or is it from my database? Thanks for your help!!

    Posted 16 years ago #
  4. yuniar

    Simply right click on your form and view source.
    The element name would be the actual HTML element name.


    MachForm Founder

    Posted 16 years ago #
  5. epsd
    Member

    I'm using the code in regular fields and it now works fine, however, it doesn't work in admin only fields... I have installed the updated bug-fix for admin only fields (which has fixed most of the bug, except for the above for some reason).

    Posted 16 years ago #
  6. yuniar

    Hmm..what doesn't work? The 'admin only' field shows blank value?
    It seems tricky to continue in the forum.

    Could you please mail me the following:
    - includes/view-functions.php file
    - your machform URL
    - your machform username + password

    Send them to yuniar [at] appnitro.com
    I'll take a look.


    MachForm Founder

    Posted 16 years ago #
  7. epsd
    Member

    Sorry, I was out for the weekend...The field contains the value (i.e., I can see it on-screen), but it doesn't get posted to the database (or sent in an email) when the field is set to admin only. It works fine (i.e., is sent to the DB) when the field is set as 'everyone'.

    I can't give you the URL as it is on a secured intranet... I can send you the view-functions.php file if you'd like.

    Posted 16 years ago #
  8. yuniar

    Hmm..that's weird, if the field contains the value already, it should be posted to the database. Can you send me the HTML code of this form?

    Send me your view-functions.php file too, or any other modified files.


    MachForm Founder

    Posted 16 years ago #
  9. epsd
    Member

    I'll send it first thing in the morning. It does send the value when the field is set to 'view by everyone' just not when admin only.

    Posted 16 years ago #
  10. yuniar

    ok got it. I've replied back.


    MachForm Founder

    Posted 16 years ago #
  11. vern1271
    Member

    OK, I followed the steps above. I have a hidden field(element_06) in form 13. Here is the code I'm using in view-functions.php:

    //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'];
    }
    if(($_REQUEST['id'] == 13) && ($element->id == 6)){
    $element->default_value = $_SESSION['form_data']['element_1'];
    }

    As you can see I'm trying to pre-populate element_06 from a session variable set from the previous form (element_01), but it's not working for me

    I know the session is working... I checked it using <?php print_r($_SESSION['form_data']); ?>.

    Posted 15 years ago #
  12. yuniar

    Is element_6 an admin-only field?

    If so, you need to be logged in to your machform admin panel first.


    MachForm Founder

    Posted 15 years ago #
  13. vern1271
    Member

    No, I hid the field using CSS using display:none;.

    Posted 15 years ago #
  14. yuniar

    Hmm... can you send me the two URL to your forms?
    Also send me your view-functions.php file

    I'll check and test it.
    Please mail to: customer.service [at] appnitro.com


    MachForm Founder

    Posted 15 years ago #
  15. vern1271
    Member

    OK, sent. Thanks!

    Posted 15 years ago #

RSS feed for this topic

Reply