+ Reply to Thread
Results 1 to 7 of 7

Thread: Auto posting data

  1. #1

    Auto posting data

    Hi!

    I have my own smarty object 'Cars' that is in index.php. It is an array that contains
    rows from some table generated from file.php.

    require_once('file.php' );

    $rlSmarty ->assign('Cars', $data);

    in our fiedls_search_box.tpl file, I add in the following foreach to render data from cars array

    <select id="{$post_form_key}_{$field.Key}_{$multicat_listi ng_type}_level0" class="multicat">

    {foreach from=$Cars item='option' key='key'}
    <option {if $fVal.$fKey == $option.ID}selected="selected"{/if} value="{$option.makes_models_id}">
    {$option.makes_name}</option>
    {/foreach}

    </select>

    replacing the generic code

    <!-- <option value="0">{$lang.any}</option >

    {foreach from=$field.Values item='option' key='key'}
    <option {if $fVal.$fKey == $option.ID}selected="selected"{/if} value="{$option.ID}">
    {$lang[$option.pName]}</option>

    {/foreach}-->

    When I go to the main page (index.php) the search box pull down for makes/model choices shows my data from my table just fine but when I select an option and press the SEARCH button and am taken to the autos/search-results.html page, the wrong value is pre-populating the same makes/model <select> html control (i.e. not the value from the choice from index.php) on the search-results.html page.

    Is there any code areas (or code help I can get), perhaps in Java Script or in any php files so I can override things and get things working, so data can transport over to the auto generated page search-results.html correctly, because I can't easily spot the places to edit things again, so things properly work out.

    Many, many thanks!!

    -Matt
    Last edited by Maciej Tkaczyk; January 24, 2018 at 03:27 AM.

  2. #2
    Flynax developer Rudi's Avatar
    Join Date
    Dec 2014
    Location
    Planet Earth
    Posts
    3,162
    Hello,

    Because you use {if $fVal.$fKey == $option.ID}selected="selected"{/if}

    and $fVal.$fKey ( $smarty.post[$field.Key] ) and your $option.ID don't match

  3. #3
    Thank you!

    Also if you can answer this please.

    I have the MAKE/MODEL dropdown now working with my own data. How can I get the SUBCATEGORY to populate the models based on the MAKE/MODEL selected value. Ex. user chooses Acura in MAKE/MODEL pull down and thus the SUBCATEGORY dropdown auto fills models for Acura makes only.

    Thanks ever so much for some suggestions.

  4. #4
    Flynax developer Rudi's Avatar
    Join Date
    Dec 2014
    Location
    Planet Earth
    Posts
    3,162
    you'd better use Multi-field plugin where you can create fields with multi-levels of nesting and then put them on your form

    otherwise, you should use ajax together with php to realise your idea but it's more complicated

  5. #5

    Unhappy

    Thanks so much Sir!

    That really helped. I have the dropdowns now filled via ajax calls in my fields_search_box.tpl file. The problem I now am facing to finish things up is when I choose the Make/Model & then the SubCategory selections from index.php, those particular values don't carry over to the search-results.html page that renders when I click on the 'Search' button on the index page.

    Note -If I choose just Make/Model that works to carry the value over to the search-results page.

    here is the code for that works for Make/Model <select> tag

    {foreach from=$myCars item='option' key='key'}
    {$fVal.$fKey = $option.makes_name}
    <option {if $fVal.$fKey == $option.makes_name}selected="selected"{/if} value="{$option.makes_name}">{$option.makes_name }</option>

    here is the non working code for subcategory that doesn't carry over or cause the Make/Model value carry over either

    <select class="multicat {if $smarty.section.multicat.last} last{/if}"
    id=
    "{$post_form_key}_{$field.Key}_{$multicat_listing_ type}_level{$smarty.section.multicat.index}">
    <option value="0">{$lang.any}</option>

    Note again that Ajax is working properly to populate initially the subcategory tag on the index page but again causes conflict on search page...

    Any help would be greatly appreciated to get my values carried over.

    Thanks again for any suggestions Sir.
    Last edited by Maciej Tkaczyk; March 25, 2018 at 04:51 AM.

  6. #6
    Flynax developer Rudi's Avatar
    Join Date
    Dec 2014
    Location
    Planet Earth
    Posts
    3,162
    Sorry Maciej,

    But I can't tell you all the details that you should do because we don't guide customers how to make customizations
    if you're aware of how to use ajax functions it shouldn't be difficult to get what you need

    The only thing is that you should create a php function in some controller which would fetch sub-categories from your database once some parent category is selected
    this php function should be run via ajax request

    there are many examples in google, you may follow them

  7. #7
    Thanks again Rudi.
    Last edited by Maciej Tkaczyk; April 29, 2018 at 02:18 PM.

+ Reply to Thread