solved Couple of issues using form builder

alt=
@hello77957
5 years ago
56 posts
Hi, I've created a couple of extra fields which i've added to my create template. I've managed to call the user input in the text field, but I can't find the right way to call the selected radio button. What is the correct syntax please?

Also, I have set those fields to 'required' in the form builder, but the form is submitting with out those fields being entered, do I need to do something else in the templates to make sure users complete those fields?
updated by @hello77957: 04/19/19 05:07:14PM
paul
@paul
5 years ago
4,326 posts
Sorry, but I'm a bit confused as to what you are doing. I'm not sure if you are editing a template, or function code (in the module index.php file, say) using the Form Designer, or any combination of these. Can you give more detail, maybe with sample code, if that is what you are doing?
Thanks


--
Paul Asher - JR Developer and System Import Specialist
alt=
@hello77957
5 years ago
56 posts
Hi Paul, yes sorry, I've used form designer to create a couple of fields to go into my customised guestbook module. One is a text field, and the other is a radio button field with three options.

I set both these fields to 'required'.

I've added the code for those fields in the item_index.tpl form. Now I need to figure out the code which displays the users entry in those fields.

Looking at the item_list.tpl, the code which outputs the textarea entry is

{$item.guestbook_text|jrCore_format_string:$item.profile_quota_id}

So I modified that code to output my new text fields, which works fine, but I don't know what to add or change to that code to call whichever option the user has selected with the radio button.

Also, on testing the form, it's letting me submit without entering anything in those fields, so the 'required' is not working.
paul
@paul
5 years ago
4,326 posts
Quote: {$item.guestbook_text|jrCore_format_string:$item.profile_quota_id}
If its a text field it likely doesn't need the modifier to format the text string so you just use {$item.guestbook_text}, or whatever your field name is.

Quote: So I modified that code to output my new text fields, which works fine, but I don't know what to add or change to that code to call whichever option the user has selected with the radio button.
The radio field name takes the value of the selected option. So, if there is a radio field, 'guestbook_radio' say, with three options with values of 'aaa', 'bbb' and 'ccc', and 'bbb' was selected, then in the template, $item.guestbook_radio = 'bbb'
This means that in your template you can test for this -
{if $item.guestbook_radio == 'aaa'}
    // Do whatever needs to be done if 'aaa'
{elseif $item.guestbook_radio == 'bbb'}
    // Do whatever needs to be done if 'bbb'
{elseif $item.guestbook_radio == 'ccc'}
    // Do whatever needs to be done if 'ccc'
{/if}

Quote: Also, on testing the form, it's letting me submit without entering anything in those fields, so the 'required' is not working.
I've just tried this and its working for me - If a radio option isn't selected upon form submit, a message shows telling the user that it needs to be. So its likely a configuration thing with your Form Designer settings. Post a screenshot maybe?

Just one suggestion though, you are building a custom module so why not just enter the form field code in your module function so that you don't need to use the Form Designer?

hth


--
Paul Asher - JR Developer and System Import Specialist
alt=
@hello77957
5 years ago
56 posts
Hmm, actually I don't think it's form designer but something about the way guestbook module is coded.

I've just added a text field in every other module and each of them output what ive written in them. When I tried it on the original guestbook module, nothing showed.

Think i'm going to have to abandon this custom module, all I wanted was to have the user's connection to the profile owner show above their message, but it seems it can't be done.


Thanks anyway
paul
@paul
5 years ago
4,326 posts
The GuestBook module is a bit different to other modules in that the sign form is in a template and is not a module view as is more common in other modules. However, this does not mean that it cannot be easily customised, the same as other modules.
I have updated the module to make it more flexible in this respect, so to do what you describe, update your site with the latest Guestbook module then modify the module's item_index.tpl and item_list.tpl templates as follows -

item_index.tpl line 25 -
                <form id="gform" method="POST" onsubmit="jrGuestBook_post_entry('{$_profile_id}','#gform','#guestbooks');return false">
                <input type="hidden" id="profile_id" name="profile_id" value="{$_profile_id}">

                    {* These lines added *}
                    Your connection to this profile<br>
                    <input type="text" name="guestbook_profile_connection" value=""><br><br>

                    <textarea name="guestbook_text" cols="40" rows="5" class="form_textarea"></textarea>
                <br>
                <div style="vertical-align:middle">
                    <img id="form_submit_indicator" src="{$jamroom_url}/skins/{$_conf.jrCore_active_skin}/img/submit.gif" width="24" height="24" alt="{jrCore_lang module="jrCore" id="73" default="working..."}" style="margin:8px 8px 0px 8px;"><input id="guestbook_submit" type="submit" value="{jrCore_lang module="jrGuestBook" id="19" default="sign guest book"}" class="form_button" style="margin-top:8px;">
                </div>
                </form>

item_list.tpl line 13
                    <div class="p10">
                        <span class="info"><a href="{$jamroom_url}/{$item.profile_url}">@{$item.user_name}</a></span>, <span class="info_c">{$item._created|jrCore_date_format}</span><br>

                        {* This line added *}
                        <br><b>Connection: </b>{$item.guestbook_profile_connection}<br><br>

                        <span class="normal">{$item.guestbook_text|jrCore_format_string:$item.profile_quota_id}</span>
                    </div>

I've tried this and it works fine :-)

Hope this helps


--
Paul Asher - JR Developer and System Import Specialist
alt=
@hello77957
5 years ago
56 posts
@Paul, First of all, thank you so much for going above and beyond to help. :)

Second, excuse my lack of knowledge, its not working for me.
The fields have been added but typing into the "Your connection to this profile" field is just returning "Connection:" with a blank space after it.

I've tried it on my custom module and the original guestbook module with the same results. Perhaps it's something todo with my server environment.

I really do appreciate your taking the time to make the code for me, but ultimately I wanted a radio option as there's only three ways a user can be connected to the profile owner and I don't want to give them the ability to put anything different. Regardless, I've tried every field type and can't get any of them to work.

I'll have to think of something else.

Thanks again!
updated by @hello77957: 01/18/19 06:37:42AM
paul
@paul
5 years ago
4,326 posts
Radio option still works fine for me -
                <form id="gform" method="POST" onsubmit="jrGuestBook_post_entry('{$_profile_id}','#gform','#guestbooks');return false">
                <input type="hidden" id="profile_id" name="profile_id" value="{$_profile_id}">

                    <br><br>
                    <input type="radio" name="guestbook_profile_connection" value="friend" checked> Friend<br>
                    <input type="radio" name="guestbook_profile_connection" value="associate"> Associate<br>
                    <input type="radio" name="guestbook_profile_connection" value="collegue"> Collegue
                    <br><br>
                    
                <textarea name="guestbook_text" cols="40" rows="5" class="form_textarea"></textarea>
                <br>
                <div style="vertical-align:middle">
                    <img id="form_submit_indicator" src="{$jamroom_url}/skins/{$_conf.jrCore_active_skin}/img/submit.gif" width="24" height="24" alt="{jrCore_lang module="jrCore" id="73" default="working..."}" style="margin:8px 8px 0px 8px;"><input id="guestbook_submit" type="submit" value="{jrCore_lang module="jrGuestBook" id="19" default="sign guest book"}" class="form_button" style="margin-top:8px;">
                </div>
                </form>

If you want send your site url and admin login tp support[at]jamroom[dot]net and I'll take a look.
Thanks


--
Paul Asher - JR Developer and System Import Specialist
alt=
@hello77957
5 years ago
56 posts
@Paul ! That would be amazing! Thank you!

Tags