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

Session Variable as Default Value in Admin Only Fields?


  1. walags
    Member

    I am posting to get more information from a previous thread. http://www.appnitro.com/forums/topic/enable-code-in-admin-only-fields?replies=10

    To automatically assign a value of a text field to that of a system variable you said to add the following 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'];
    }

    * My if statement is not being entered. I have changed the request id to that of my form and I can't get through it. I put an echo statement before and inside and can verify that.
    * My form will only have 1 test field anyway so I am ok with just setting the default value to always be my session variable.
    * When the field is public the variable gets passed with no problems and enters the database.
    * When the field is private the value does not get saved in the database.

    Is there any other fixes or ways about passing a sessions variable as the default value in an admin text field?

    Posted 16 years ago #
  2. walags
    Member

    Well I took of all but one of those problems by inserting the form via the standard iframe rather than php. When I have a regular public field everything works like a champ.

    However once I make that an admin field it does not record that data.

    Advice?

    Posted 16 years ago #
  3. yuniar

    Sorry, after re-reading my post on that thread. I think I got something wrong.
    It won't work for admin field, since admin field can only be seen by admin only.

    Are you trying to do a hidden field and pass your session variable there?

    If so, I suggest to just use a normal field, not admin field, and then set the CSS of that field to hidden.

    This way, your users won't see the field, but you still get the value.
    Is this what you need?

    ---

    Regarding your usage of iframe instead of the php code.
    Try to use the PHP code again, but at the very beginning of you PHP file, add this line:

    <?php session_start(); ?>


    MachForm Founder

    Posted 16 years ago #
  4. walags
    Member

    Well that was easy hiding the field.

    As for using iframe instead of php code... I'm not sure how each of those interact with the view-functions but using the php code the custom if statement never gets entered

    Posted 16 years ago #
  5. yuniar

    Have you tried adding the code I posted above? and your if statement didn't processed?


    MachForm Founder

    Posted 16 years ago #
  6. walags
    Member

    Man I can't tell you how great this is working. I have two fields (username\email) which are hidden on my form and automatically filled in with session variables. User just fills out form and it automatically emails to them while I get to see who submitted it. I knew this is how I wanted to implement it, but didn't think it would be this easy.

    Posted 16 years ago #

RSS feed for this topic

Reply