CustomPress – when using the ct_in shortcode, can a field be not required

I have a site that will maintain patient records. I used CustomPress to create some custom fields for patient information – some of that information like DOB is required when creating a patient record.

On the site, I have a search bar that stays on the top of all the pages and it uses the [ct_in id="DOB-Field-ID" property="title | description | input"] shortcodes to display the CustomPress fields in the search form.

I also have a front-end page that us the same shortcodes to let them edit patient records without going into the wp-admin.

The issue I'm running into is on the single-patient-record pages where I let them make the edits. When I go to save the edits on the patient record, the fields in the search error saying they are required even though they are outside of the edit form and outside the loop.

Is there anyway with Javascript or with the shortcodes to tell the fields in the search form they aren't required while still leaving the same fields in the main edit form as being required?

  • Ash
    • WordPress Hacker

    Okay, give an ID to the search form, like:

    <form action="http://squaddev.com/Stangel/?page_id=36" method="post" novalidate="novalidate" id="cp_search_form">

    Then make changes in you added script:

    jQuery('[id^=ct_First_Name_text_1691]').closest('form').validate();

    to

    jQuery('#cp_search_form').validate();

    And finally, you have same name and if for both form fields. ID needs to be unique and you can’t use same ID for more than one element.

    Now, let’s look at your script again, you have code like:

    jQuery('[name="ct_First_Name_text_1691"]').rules('add', { messages: {required: 'Please enter a first name' } });
    jQuery('[name="ct_First_Name_text_1691"]').rules('add', { required: true } );

    So both form fields have same name. Either make it different or use unique id to validate the form.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers

    Ash

  • christina_hooper
    • Site Builder, Child of Zeus

    It’s still not working.

    This part isn’t something that I put in – it’s put in by CustomPress:

    jQuery('[id^=ct_First_Name_text_1691]').closest('form').validate();

    The ID’s on the form fields are created by CustomPress as well, so we can’t change those either. For example, here’s the code I’m using to generate the search form.

    <form action="http://squaddev.com/Stangel/?page_id=36" method="post" novalidate id="cp_search_form">
    <strong>PATIENT SEARCH: </strong>
    <?php echo do_shortcode('[ct_in id="ct_First_Name_text_1691" property="title | description | input"]' ); ?>
    <?php echo do_shortcode('[ct_in id="ct_Middle_Nam_text_5ec0" property="title | description | input"]' ); ?>
    <?php echo do_shortcode('[ct_in id="ct_Last_Name_text_2094" property="title | description | input"]' ); ?>
    <?php echo do_shortcode('[ct_in id="ct_Outstandin_radio_69dd" property="title | description | input"]' ); ?>
    <?php echo do_shortcode('[ct_in id="_ct_datepicker_534687d429ca7" property="title | description | input"]' ); ?>
    <input type="hidden" name="SubmitSearch" value="true">
    <button type="submit" class="SearchButton"><i class="fa fa-search"></i><span>Search</span></button>
    <strong>|</strong>
    <a class="Button" href="<?php echo get_permalink(34);?>"><i class="fa fa-question"></i><span>Help</span></a>
    <a class="Button" href="<?php echo get_permalink(32); ?>"><i class="fa fa-cog"></i><span>Settings</span></a>
    </form>

  • christina_hooper
    • Site Builder, Child of Zeus

    So – I did find a workaround for this, but not an actual solution. I added some javascript to the edit button that enables all the fields on the page to disable all the patient search fields. Since they are disabled, they don’t get submitted, and don’t trip the errors.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.