Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi, KK,


submitting information from the admin panel is showing in DBF in the front end but conditional values are not updating from the frontend. Non Conditional fields are updating perfectly.
For superuser, DBF showing success without updating conditional fields
and for other admin user and registered user DBF showing error (of conditional field from employer) as following:
error.png
error.png (20.82 KiB) Viewed 1387 times

(All the tested user type is Candidate)

I am attaching users/index.php and edit_profile DBF.
users/index.php
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>

<cms:template clonable='1' title='Users' hidden='1'>

       <!-- THIS DISPLAY_IMG IS PERFECTLY WORKING WITH DBF -->
    <cms:editable
        name='display_img'
        label='Display Image'
        type='securefile'
        allowed_ext='png, jpg, jpeg'
        max_size='2048'
        crop='1'
        thumb_width='300'
        thumb_height='300'
        show_preview='1'
        use_thumb_for_preview='1'
        thumb_quality='100'
/>
<!-- PROFILE TYPE -->
    <cms:editable
        name="user_type"
        label="User Type"
        desc="Type of user"
        opt_values='Candidate | Employer'
        type='radio'
        required='1'
        order='20'
/>

<!-- EMPLOYER'S PROFILE START -->
<cms:func _into='user_type_cond' user_type=''>
        <cms:if user_type='Employer' >
            show
        <cms:else />
            hide
        </cms:if>
</cms:func>

<cms:editable type='text' name='job_free_posting' label='Free Job Posting Available' desc='No of Free Jobs that can be posted' order='30' not_active=user_type_cond  validator='non_negative_integer' required='1'>2</cms:editable>
<cms:editable type='text' name='job_quick_posting' label='Quick Posting Available' desc='No of Quick Jobs that can be posted' order='31' not_active=user_type_cond  validator='non_negative_integer' required='1'>0</cms:editable>


<cms:editable
        name="job_smart_posting"
        label="Smart Package Active"
        desc="Type of package"
        opt_values='No | Yes'
        type='radio'
        required='1'
        order='35'
        not_active=user_type_cond
/>
<cms:editable
        name="job_premium_posting"
        label="Premium Package Active"
        desc="Type of package"
        opt_values='No | Yes'
        type='radio'
        required='1'
        order='36'
        not_active=user_type_cond
/>

<!-- EMPLOYER'S PROFILE END-->

<!-- CANDIDATE'S PROFILE START (17 EDITABLES) -->
<cms:func _into='user_type_cond' user_type=''>
        <cms:if user_type='Candidate' >
            show
        <cms:else />
            hide
        </cms:if>
</cms:func>


<cms:editable type='text' name='c_phone' label='Phone Number' not_active=user_type_cond validator='non_negative_integer | exact_len=10' order='70'/>
<cms:editable type='text' name='c_address' label='Address' not_active=user_type_cond order='72'/>
<cms:editable type='text' name='c_age' label='Age' not_active=user_type_cond validator='non_negative_integer' order='73'/>
<cms:editable type='text' name='c_salary' label='Current Salary' not_active=user_type_cond validator='non_negative_integer' order='74' search_type='decimal'/>
<cms:editable type='text' name='c_dob' label='Date of Birth' not_active=user_type_cond  order='75' />
<cms:editable
    name='c_job_loc'
    type='relation'
    masterpage='job_loc.php'
    label='Preferred Job Location'
    no_guix='1'
    order='76'
    not_active=user_type_cond
    />
<cms:editable
    name='c_job_cat'
    type='relation'
    has='one'
    masterpage='job_cat.php'
    label='Job Category'
    not_active=user_type_cond
    no_guix='1'
    order='77'
/>
<cms:editable
    name='c_job_indus'
    type='relation'
    has='one'
    masterpage='job_indus.php'
    label='Job Industry'
    not_active=user_type_cond
    no_guix='1'
    order='78'
/>
<cms:editable
    name='c_job_posts'
    type='relation'
    has='one'
    masterpage='job_post.php'
    label='Job Level/Designation'
    not_active=user_type_cond
    no_guix='1'
    order='79'
/>
<cms:editable
    name="c_job_experience"
    label="Candidate Job Experience"
    desc="choose job experience"
    opt_values='Select Experience =- | Fresher | 0-1 Year | 1-2 Years  | 2-3 Years  | 3-4 Years  | 4-5 Years  | More than 5 Years'
    type='dropdown'
    order='80'
    not_active=user_type_cond
/>


<cms:editable
    name="c_gender"
    label="Candidate Gender"
    desc="choose job Gender"
    opt_values='Select Gender =- | Male | Female'
    type='dropdown'
    order='81'
    not_active=user_type_cond
/>



<cms:editable type='textarea' name='c_about' label='Candidate About' not_active=user_type_cond order='82' />
<cms:editable type='textarea' name='c_edu' label='Candidate Education' not_active=user_type_cond order='84' />
<cms:editable type='textarea' name='c_work' label='Candidate Work Experience' not_active=user_type_cond order='86' />
<cms:editable type='text' name='c_skill' label='Candidate Skills' not_active=user_type_cond order='88' />
<cms:editable type='textarea' name='c_special' label='Candidate Special Qualification' not_active=user_type_cond order='89' />



<cms:editable type='securefile' name='c_resume' label='Candidate CV' not_active=user_type_cond order='90'  allowed_ext='pdf, doc, docx'  max_size='4048'  />

<!-- CANDIDATE'S PROFILE END-->

</cms:template>

<?php COUCH::invoke(); ?>


edit_profile DBF
Code: Select all

<cms:set submit_success="<cms:get_flash 'submit_success' />" />

<cms:if submit_success>
   <div class="alert alert-success text-center">
      <h6 style='color:green'>Your profile has been successfully updated.</h6>
   </div>
</cms:if>
<cms:form
    masterpage='users/index.php'
    mode='edit'
    page_id=k_user_id
    enctype="multipart/form-data"
    method='post'
    anchor='0'
    name='edit_profile_form'
    class="dashboard-form">

    <cms:if k_success >
           
        <cms:db_persist_form
        c_job_loc=frm_selected_locations
        c_skill=frm_selected_skill_tags
       
        />

        <cms:if k_error>
         
          <div class="alert alert-danger">
            <strong>Could not edit your profile!</strong><br />
            The following error(s) occured while updating your profile:<br />

            <ul>
                <cms:each k_error>
                    <li>
                        <cms:show item />
                    </li>
                </cms:each>
            </ul>
        </div>
        <cms:else />       
       
          <cms:set_flash name='submit_success' value='1' />
          <cms:redirect "<cms:route_link 'edit_profile_view' masterpage='candidate-dashboard.php' />" />           
     

      </cms:if>
    </cms:if>

<div class="row mx-5 mb-5">
  <div class="dashboard-section upload-profile-photo  ">
    <div class="update-photo">
      <img class="image" src="<cms:show display_img_url />" alt="">
    </div>
<!-- DISPLAY IMG UPLOAD WORKING AS IT IS NOT AFFECTED BY CONDITION -->
    <div class="file-upload">           
      <cms:input type="bound" name='display_img' class="file-input"/>
    </div>
  </div>

    <div class="col-sm-6 align-baseline">
      <cms:input type='bound' name='c_resume' class="button" />
    </div>
</div>


    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="user-check"></i>Basic Info</h4>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Full Name</label>
        <div class="col-sm-9">
<!-- TITLE WORKING AS IT IS NOT AFFECTED BY CONDITION -->
          <cms:input type="bound" name='k_page_title' class="form-control" placeholder="Full Name" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Username</label>
        <div class="col-sm-9">
          <input type="text" class="form-control" placeholder="@<cms:show k_user_name />" disabled>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Email Address</label>
        <div class="col-sm-9">
          <input type="text" class="form-control" placeholder="<cms:show k_user_email /> " disabled>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Phone</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_phone' class="form-control" placeholder="9910878787"/>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Address</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_address' class="form-control" placeholder="Washington D.C"/>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Gender</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_gender' class="form-control" placeholder="Washington D.C"/>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Age</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_age' class="form-control" placeholder="24"/>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Date of Birth</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_dob' class="form-control" placeholder="25 March, 1990"/>
        </div>
      </div>
    </div>
    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="user-check"></i>Job Related Info</h4>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Job Category</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_job_cat' class="form-control" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Industry Expertise</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_job_indus' class="form-control" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Job Post/Designation</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_job_posts' class="form-control" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Experience</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_job_experience' class="form-control" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Current Salary</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_salary' class="form-control" />
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Preferred Locations</label>
        <div class="col-sm-9">
          <select class="form-control myselect2" multiple="multiple"></select>
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Skill Tags</label>
        <div class="col-sm-9">
          <select class="form-control myselect2-tags" multiple="multiple"></select>
        </div>
      </div>
    </div>
   
    <cms:input type='text' style='display: none;' name='selected_locations' id='selected_locations' value="<cms:show selected_locs/>" />
    <cms:input type='text' style='display: none;' name='selected_skill_tags' id='selected_skill_tags' value="<cms:show c_skill/>" />

    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="lock"></i>About Me</h4>
      <div class="form-group row">
        <div class="col-sm-12">
          <cms:input type="bound"  name='c_about' class="form-control" placeholder="Write your educatioin background" />
        </div>
      </div>
    </div>
    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="lock"></i>Education & Qualifications</h4>
      <div class="form-group row">
        <div class="col-sm-12">
          <cms:input type="bound"  name='c_edu' class="form-control" placeholder="Write your educatioin background" />
        </div>
      </div>
    </div>
    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="lock"></i>Work Experience</h4>
      <div class="form-group row">
        <div class="col-sm-12">
          <cms:input type="bound"  name='c_work' class="form-control" placeholder="Write your educatioin background" />
        </div>
      </div>
    </div>
    <div class="dashboard-section basic-info-input">
      <h4><i data-feather="lock"></i>Special Qualifications</h4>
      <div class="form-group row">
        <div class="col-sm-12">
          <cms:input type="bound"  name='c_special' class="form-control" placeholder="Write your educatioin background" />
        </div>
      </div>
    </div>
 
    <div class="dashboard-section  basic-info-input">
      <h4><i data-feather="lock"></i>Change Password</h4>

      <div class="form-group row">
        <label class="col-sm-3 col-form-label">New Password</label>
        <div class="col-sm-9">
          <input type="password" class="form-control" placeholder="New Password">
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label">Retype Password</label>
        <div class="col-sm-9">
          <input type="password" class="form-control" placeholder="Retype Password">
        </div>
      </div>
      <div class="form-group row">
        <label class="col-sm-3 col-form-label"></label>
        <div class="col-sm-9">
          <button type='submit' class="button">Save Change</button>
        </div>
      </div>
    </div>
  </cms:form>
So that it may be a tad easier for anyone interested in this thread to follow, this is a bare-bones version of the use-case -
Editable regions -
Code: Select all
<cms:editable
    name="user_type"
    label="User Type"
    desc="Type of user"
    opt_values='Candidate | Employer'
    type='radio'
    required='1'
    order='20'
/>

<!-- EMPLOYER'S PROFILE START -->
<cms:func _into='user_type_cond' user_type=''>
        <cms:if user_type='Employer' >
            show
        <cms:else />
            hide
        </cms:if>
</cms:func>
<cms:editable type='text' name='job_free_posting' label='Free Job Posting Available' desc='No of Free Jobs that can be posted' order='30' not_active=user_type_cond  validator='non_negative_integer' required='1'>2</cms:editable>
<!-- EMPLOYER'S PROFILE END-->

<!-- CANDIDATE'S PROFILE START (17 EDITABLES) -->
<cms:func _into='user_type_cond' user_type=''>
        <cms:if user_type='Candidate' >
            show
        <cms:else />
            hide
        </cms:if>
</cms:func>
<cms:editable type='text' name='c_address' label='Address' not_active=user_type_cond order='72'/>

DBF -
Code: Select all
<cms:set submit_success="<cms:get_flash 'submit_success' />" />

<cms:if submit_success>
   <div class="alert alert-success text-center">
      <h6 style='color:green'>Your profile has been successfully updated.</h6>
   </div>
</cms:if>
<cms:form
    masterpage=k_template_name
    mode='edit'
    page_id=k_page_id
    enctype="multipart/form-data"
    method='post'
    anchor='0'
    name='edit_profile_form'
    class="dashboard-form">

    <cms:if k_success >
        <cms:db_persist_form />

        <cms:if k_error>
          <div class="alert alert-danger">
            <strong>Could not edit your profile!</strong><br />
            The following error(s) occured while updating your profile:<br />

            <ul>
                <cms:each k_error>
                    <li>
                        <cms:show item />
                    </li>
                </cms:each>
            </ul>
        </div>
        <cms:else />       
          <cms:set_flash name='submit_success' value='1' />
          <cms:redirect k_page_link />           
      </cms:if>
    </cms:if>

    <div class="form-group row">
        <label class="col-sm-3 col-form-label">Address</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_address' class="form-control" placeholder="Washington D.C"/>
        </div>
    </div>
   
    <div class="form-group row">
        <label class="col-sm-3 col-form-label"></label>
        <div class="col-sm-9">
          <button type='submit' class="button">Save Change</button>
        </div>
    </div>

</cms:form>

@jabeer, as can be seen from the definitions of the editable regions, the 'user_type' radio works as the 'control' field for the two regions that follow (where only one region is visible for each type of user).

In the DBF, you'll notice that only the editable region(s) concerned with only one type of user (namely the 'Candidate') are being exposed in the form.

However, and this is the crux of the matter, the radio field controlling the regions (i.e. the 'user_type' field) is *not* present in the form.

For conditionals to work as properly, all the control fields should be physically present in the form (and also, as noted in the docs, present *above* the fields being controlled).

That is the reason why your form is not working the way it does in the admin panel.

Try adding the missing control field (before all the dependent fields) e.g. as follows and you should find that it solves the issue -
Code: Select all
    ..

    <cms:input type="bound" name='user_type' class="form-control" />

    <div class="form-group row">
        <label class="col-sm-3 col-form-label">Address</label>
        <div class="col-sm-9">
          <cms:input type="bound" name='c_address' class="form-control" placeholder="Washington D.C"/>
        </div>
    </div>

    ...

If the use-case absolutely dictates that the control field cannot be exposed for editing. I think you should ideally structure your solution some other way (i.e. not use conditional fields in the current manner).

As a workaround, however, we can do the following.
We'll still have to include the field in the form but prevent it from being visible (or editable) as shown here is the alternative to the construct above -
Code: Select all
    <cms:hide>
        <cms:input type="bound" name='user_type' class="form-control" />
    </cms:hide>
    <input type="hidden" name="f_user_type" value="Candidate" />

Please notice that we have included the 'user_type' as a bound field. However, we have enclosed it with <cms:hide></cms:hide> tags. The <cms:hide> tag, as opposed to the similar <cms:ignore> tag, actually still executes anything enclosed within it but does not output anything on the frontend - so although the field would be present in the form (as far as Couch executing in the backend is concerned), nothing would be found on the front-end doing a view-source.

To compensate for the field's absence on the front-end, please notice the use of the 'hidden' field which is named after the original field (but with a 'f_' prepended to account for how Couch names fields internally).

Please try and let me know if it helps.
You point it right.
but exposing the user_type this way isn't risky? coz it's only decided on sign up.

earlier I was thinking to implement in another way like this:
conditional user_type (decided on the sign up)
then one-to-one relation with a separate profile template based on the user_type.
but then I was confused about how to update the profile fields(separate profile template) from the user template on edit mode.

thanks!
but exposing the user_type this way isn't risky?

As I already mentioned, this is not the preferred way of handling your particular use-case and we are discussing workarounds only if there is no alternative.

You are right - the risk here would be that the user could try to change the value of 'user_type' from 'Candidate' to 'Employer' (by intercepting the post etc.).

To thwart that, we can explicitly set the value for 'user_type' to 'Candidate' like this -
Code: Select all
<cms:if k_success >
        <cms:db_persist_form
            user_type='Candidate'
        />
       ..

With that, I don't see any other way this workaround could be exploited.

Incidentally, with the explicit setting we can simplify our original exposure of the control field to this -
Code: Select all
    <div style="display:none;">
        <cms:input type="bound" name='user_type' class="form-control" />
    </div>

i.e. no need to use an additional hidden field.

Hope this helps.
4 posts Page 1 of 1
cron