Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter chrisjdahl

    (@chrisjdahl)

    Thank you very much! Today I have been trying to modify the FormData object, but I couldn’t figure out how to access it and modify the data.

    However I found one of your custom events “icds.forms.submitting”, and it looks like I can modify the Object in here.

    Unless you see any issues here, I’m happy as can be and will mark this resolved.

    		document.addEventListener("icds.forms.submitting", (e) => {
    const fields = e.detail.fields;
    Object.entries(fields).forEach(([key, value]) => {
    if (value === null) delete fields[key];
    });
    });
    Thread Starter chrisjdahl

    (@chrisjdahl)

    Sure, the record does already exist. The user is redirected from the initial form to this “more information” conversational form. I am trying to load a single form that has all my fields, and then via javascript, control which fields are displayed to the user on each prompt.

    Below is the code for my form builder, then I have all my questions stored in a twig collection called questions and all the logic and the content that is displayed for each page in a javascript object called “Pathways”. Basically there are 4 “starting point pathways” and each page after displays a different set of questions/messages based on the previous response. Many of these pathways reuse the same questions so I thought loading each question in a single form would be a better way to go. I also wanted to utilize “stay on same page after form submit” so we don’t possibly lose users each time the page reloads.

    One solution that seems like it might work is renaming the input’s name attribute on submit so that it doesn’t map correctly to the record…. (although it throws a lot of warnings in the icds logs and a lot of my javascript rely’s on the name attribute)

    There’s probably a much better way to do what I’m trying to do, and I’m all ears for it! Thanks

    {# generate form #}
    {% form entity="lead" keep=true keep-data=true mode="update" record=lead|to_entity_reference %}
    <form id="get-started" method="post" enctype="multipart/form-data">
    <h2 id="form-heading"></h2>
    <p id="form-message"></p>
    <div class="active-questions"></div>
    <div class="inactive-questions">
    {% for key, field in questions %}
    <div class="form-group">
    <label for="{{ field.name }}">{{ field.label }}</label>

    {% if field.type == 'text' %}
    <input type="text" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />

    {% elseif field.type == 'date' %}
    <input type="date" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />

    {% elseif field.type == 'file' %}
    <input type="file" name="{{ field.name }}" id="{{ field.name }}" class="form-control" />

    {% elseif field.type == 'number' %}
    <input type="number" name="{{ field.name }}" id="{{ field.name }}" class="form-control"
    min="{{ field.min }}" max="{{ field.max }}" />

    {% elseif field.type == 'textarea' %}
    <textarea name="{{ field.name }}" id="{{ field.name }}" class="form-control"
    rows="{{ field.rows }}"></textarea>

    {% elseif field.type == 'radio' %}
    <div class="{{field.class}}">
    {% for option in field.options %}
    <div class="form-check">
    <input type="radio" name="{{ field.name }}" id="{{ field.name }}_{{ option.value }}"
    value="{{ option.value }}" class="form-check-input" {% if option.selected %} checked {% endif %}
    {% if option.hidden %} hidden {% endif %} {% if option.disabled %} disabled {% endif %} />
    <label class="form-check-label" for="{{ field.name }}_{{ option.value }}">{{ option.label }}</label>
    </div>
    {% endfor %}
    </div>

    {% elseif field.type == 'checkbox' %}
    {% for option in field.options %}
    <div class="form-check">
    <input type="checkbox" name="{{ field.name }}" id="{{ field.name }}_{{ option.value }}"
    value="{{ option.value }}" class="form-check-input {{option.class}}" {% if option.selected %}
    checked {% endif %} {% if option.hidden %} hidden {% endif %} {% if option.disabled %} disabled {%
    endif %} />
    <label class="form-check-label" for="{{ field.name }}_{{ option.value }}">{{ option.label }}</label>
    </div>
    {% endfor %}

    {% elseif field.type == 'select' %}
    <select name="{{ field.name }}" id="{{ field.name }}" class="form-control">
    {% for option in field.options %}
    <option value="{{ option.value }}" {% if option.selected %} selected {% endif %} {% if option.hidden %}
    hidden {% endif %} {% if option.disabled %} disabled {% endif %}>{{ option.label }}
    </option>
    {% endfor %}
    </select>
    </div>

    </div>
    <div class="form-nav">
    <button type="button" id="prev-btn" class="btn btn-primary">Prev</button>
    <button type="submit" id="next-btn" class="btn btn-primary">Next</button>
    <button type="submit" id="submit-btn" class="btn btn-primary">Submit</button>
    </div>
    </form>

    {% endform %}
    Thread Starter chrisjdahl

    (@chrisjdahl)

    Hi Yani, thank you for the info. I will try this next time.

    Thread Starter chrisjdahl

    (@chrisjdahl)

    I changed the call to get_home_path() to be ABSPATH and it seems to be working now. Not sure why it sometimes successfully imported / exported, but who knows.

    Thread Starter chrisjdahl

    (@chrisjdahl)

    Thank you both for your quick and well thought out responses!
    @kprovance I will reach out to the plugin author and also look into working with TGM so that I don’t need to embed Redux with my plugin.

    Thread Starter chrisjdahl

    (@chrisjdahl)

    I can’t really seem to figure this out :/ sorry. I removed the last close tag, but no luck. Also tried adding the handler page to the theme, but no luck there either. I think I’m going to just hide the output with css ?? the data / emails are going through great! So this seems to be the easiest temporary solution.
    Appreciate you trying to help out.

    Thread Starter chrisjdahl

    (@chrisjdahl)

    Hi Mario,

    Adding the following to my handler fixed the error:

    require_once(‘../wp-blog-header.php’);
    header(“HTTP/1.1 200 OK”);
    header(“Status: 200 All rosy”);

    Wait… I spoke too soon.

    • This reply was modified 4 years, 6 months ago by chrisjdahl.
    Thread Starter chrisjdahl

    (@chrisjdahl)

    Oh, sorry…
    So the only error that was in the debug log is here.
    Array to string conversion
    I got rid of the echo statement causing it.
    https://pastebin.com/SWTQZJx5
    I’ve included some of my wp-config.php. Are those ok logging settings?

    Thread Starter chrisjdahl

    (@chrisjdahl)

    Thanks Mario,
    I’ve sent you an email to the gmail address on your website with the login info and php handler.

Viewing 9 replies - 1 through 9 (of 9 total)