Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Send Form By Ajax And Show Result Rate Topic   - - - - -

 
  • masoud_tesna
  • Advanced Member
  • Trial users
  • Join Date: 27-Jun 19
  • 55 posts

Posted 05 January 2020 - 01:34 PM #1

hi..

I have a form that sends and stores information in the database using JAJX method. Everything is fine and work is done. But after sending it to the database I want to send a variable to that page to display ... I did the following but it didn't work.

 

in my tpl file:

<form action="{""|fn_url}" name="freight_request_form" method="post" class="cm-ajax">
        <input type="hidden" name="result_ids" value="result">
        <div class="ty-control-group ty-control-group-brand">
            <input type="text" id="elm_freight_request_product_brand" name="freight_request_data[product_brand]">
            <label for="elm_freight_request_product_brand" class="ty-control-group__title cm-required">{__("product_brand")}</label>
        </div>
        <div class="ty-control-group ty-control-group-sh-code">
            <input type="text" id="elm_freight_request_sh_code" name="freight_request_data[sh_code]">
            <label for="elm_freight_request_sh_code" class="ty-control-group__title">{__("sh_code")}</label>
        </div>

        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_cargo_weights.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_product_types.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_car_types.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_origins.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_destinations.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_package_types.tpl"}

        <div class="wk_post_add_footer vv-fright-btn-post">
        {include file="buttons/button.tpl" but_role="submit" but_name="dispatch[vv_freight_requests.update]" but_text=__("send_data_freight") but_meta="ty-btn__secondary" but_id="freight_request_form"}
        </div>

    

    </form>
    
<div id="result" style="font-size:25px">
<!--result--></div>

in control file:

use Tygh\Registry;
use Tygh\Ajax;
use Tygh\Tools\Url;

if (!defined('BOOTSTRAP')) { die('Invalid Access'); }

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

  if ($mode == 'update') {
    if (defined('AJAX_REQUEST')) {
      $id= $_REQUEST['result_ids'];

      $tracking_code = fn_update_freight_request($_REQUEST['freight_request_data'], $_REQUEST['freight_request_id']);

      $val = $tracking_code['tracking_code'];
      Registry::get('ajax')->assign("result",  $val);

      exit;
    }
  }

}

The following code can send the result to div with the result ID .. But I want it to be pop-up and the code will be displayed in a pop-up I designed ...

Registry::get('ajax')->assignHtml("$id",  $val);

Please tips. thanks
 

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20055 posts

Posted 05 January 2020 - 01:44 PM #2

- Put this part of code to the separate file

 

<div style="font-size:25px" id="result">
{$id}
<!--result--></div>

- Include it in the file where the form is displayed

 

- Use the following code before exit in the controller (do not forget to correct file path)

Tygh::$app['view']->display('addons/your_addon/path_to_file/file.tpl');
It should solve your issue

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • masoud_tesna
  • Advanced Member
  • Trial users
  • Join Date: 27-Jun 19
  • 55 posts

Posted 06 January 2020 - 07:35 AM #3

 

- Put this part of code to the separate file

 

<div style="font-size:25px" id="result">
{$id}
<!--result--></div>

- Include it in the file where the form is displayed

 

- Use the following code before exit in the controller (do not forget to correct file path)

Tygh::$app['view']->fetch('addons/your_addon/path_to_file/file.tpl');
It should solve your issue

 

Thank you dear friend..
Can you give me more explanation?
I didn't notice you wrote in the code above: "{$id}" but in your last code I don't see "{$id}". I got confused.

Do you mean something like that?

in form file: name: form.tpl:

<form action="{""|fn_url}" name="freight_request_form" method="post" class="cm-ajax">
        <input type="hidden" name="result_ids" value="result">
        <div class="ty-control-group ty-control-group-brand">
            <input type="text" id="elm_freight_request_product_brand" name="freight_request_data[product_brand]">
            <label for="elm_freight_request_product_brand" class="ty-control-group__title cm-required">{__("product_brand")}</label>
        </div>
        <div class="ty-control-group ty-control-group-sh-code">
            <input type="text" id="elm_freight_request_sh_code" name="freight_request_data[sh_code]">
            <label for="elm_freight_request_sh_code" class="ty-control-group__title">{__("sh_code")}</label>
        </div>
 
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_cargo_weights.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_product_types.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_car_types.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_origins.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_destinations.tpl"}
        {include file="addons/vv_horn_changes/views/product_vendor/components/freight_request_assign_package_types.tpl"}
 
        <div class="wk_post_add_footer vv-fright-btn-post">
        {include file="buttons/button.tpl" but_role="submit" but_name="dispatch[vv_freight_requests.update]" but_text=__("send_data_freight") but_meta="ty-btn__secondary" but_id="freight_request_form"}
        </div>
 
    
 
    </form>

In the answer file: answer.tpl:

<div style="font-size:25px" id="result">
{$id}
<!--result--></div>

in controller:

    use Tygh\Registry;
    use Tygh\Ajax;
    use Tygh\Tools\Url;
     
    if (!defined('BOOTSTRAP')) { die('Invalid Access'); }
     
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
     
      if ($mode == 'update') {
        if (defined('AJAX_REQUEST')) {
          $id= $_REQUEST['result_ids'];
     
          $tracking_code = fn_update_freight_request($_REQUEST['freight_request_data'], $_REQUEST['freight_request_id']);
     
          $val = $tracking_code['tracking_code'];
          Registry::get('ajax')->assign("id",  $val);


          //your code
          Tygh::$app['view']->fetch('addons/your_addon/path_to_file/file.tpl');
     


          exit;
        }
      }
     
    }


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 20055 posts

Posted 06 January 2020 - 01:39 PM #4

For example, create the following file

 

design/themes/responsive/templates/addons/my_changes/views/vv_freight_requests/answer.tpl

 

<div style="font-size:25px" id="result">
{$id}
<!--result--></div>

To the end of tpl file add

{include file="addons/my_changes/views/vv_freight_requests/answer.tpl"}

Before calling exit in the vv_freight_requests controller add

 

Tygh::$app['view']->display('addons/my_changes/views/vv_freight_requests/answer.tpl');

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • masoud_tesna
  • Advanced Member
  • Trial users
  • Join Date: 27-Jun 19
  • 55 posts

Posted 07 January 2020 - 06:08 AM #5

 

For example, create the following file

 

design/themes/responsive/templates/addons/my_changes/views/vv_freight_requests/answer.tpl

 

<div style="font-size:25px" id="result">
{$id}
<!--result--></div>

To the end of tpl file add

{include file="addons/my_changes/views/vv_freight_requests/answer.tpl"}

Before calling exit in the vv_freight_requests controller add

 

Tygh::$app['view']->display('addons/my_changes/views/vv_freight_requests/answer.tpl');

Thank you my dear friend..