Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hello everyone, I'm new around here. I've been trying to implement a feature on my site.
I have a form that gets called on every page in my site. It accepts just one value, a text input. This text input is suposed to form a query string for an external URL that gets called up in an iframe on a unique page on my site. I've tried setting the variable value as a session using <cms:set_session > to no avail. I hope somebody will be able to guide me on how to go about it.
I have a fair grasp of PHP generally by the way. Thanks
This is the code for the form:
Code: Select all

<section class="message-wrap2">


<cms: form class="quform" method="post" enctype="multipart/form-data" onclick="">


<cms: if k_success >
<cms: set_session name ='vrm' value ="frm_name" / >
<cms: redirect '/lookup' / >
</cms: if>



<div class="row" style="background:#e22d2d;color:white">
    <div class="col-sm-12">
  <h4 style="color:white;margin-top:20px;text-align:center">Find out how a remap will benefit your vehicle</h4>
<div class="centerform"><div class="quform-elements">
</div></div></div>
</div>
<div class="row" style="background:#e22d2d;color:white">
    <div class="col-sm-4" style=";margin-top:-10px">
                <p style="color:white;font-size:11pt;text-align:center">Complete the form <br>or<br>call 07594 500487</p>
    </div>

    <div class="col-sm-4">
   <div class="quform-input">     <div class="input-group" style="width:100%;background:blue;border-radius:0px;border:3px solid blue">
  <span class="input-group-addon" id="basic-addon1" style="background:blue;color:yellow;font-size:10pt;border-radius:0px"><b>GB</b></span>

  <input type="text" class="form-control" placeholder="Vehicle Registration (Required)" name="name"  style="background:#f9e563;border-radius:0px;height:30px;margin-right:5px">
</div>
</div></div>



    <div class="col-sm-4" >
               
                   
                    <!-- Begin Submit button -->
             
             
                            <button type="submit"><span><em>Send</em></span></button>
                   
                        <div class="quform-loading-wrap"><span class="quform-loading"></span></div>
           



            </div>
            <br> <br>
             <span id="error_message" style="color:white"></span> 

</div>
</cms:form>
<!--message-wrap ends-->



This is the code for the iframe. The iframe is invoked using shortcode.
Code: Select all


<?php
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

//require_once( K_COUCH_DIR.'addons/cart/session.php' );
//require_once( K_COUCH_DIR.'addons/cart/cart.php' ); // automatically includes session
//require_once( K_COUCH_DIR.'addons/data-bound-form/data-bound-form.php' );
//require_once( K_COUCH_DIR.'addons/inline/inline.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-folders.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-comments.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-users.php' );
//require_once( K_COUCH_DIR.'addons/routes/routes.php' );
   // 2.
   // IFrame shortcode
   // Usage: [iframe src="http://www.somesite.com/" width="100%" height="625" scrolling="yes" frameborder="1" marginheight="2"]


$FUNCS->register_shortcode( 'iframe', 'iframe_handler' );
   function iframe_handler( $params, $content=null ){
      global $FUNCS;

      extract( $FUNCS->get_named_vars(array(
         'src' => 'https://www.direg.co.uk/dealer-tool/responsive-vehicle-look-up-tool/lookup.aspx?vrm= <cms:get_session 'vrm' />&ref=Anglian%20Remaps%20-%20Dealer%20Tool',
         'width' => '100%',
         'height' => '1500',
         'id' => 'anglianremapstool',
         'scrolling' => 'no',
         'frameborder' => '0',
         'marginheight' => '0'
      ), $params) );

      $html =<<<EOS
      <iframe id="$id" src="$src" title="" width="$width" style="height: 1125px;" scrolling="$scrolling" frameborder="$frameborder" marginheight="$marginheight">
         <a href="$src" target="_blank">$src</a>
      </iframe>
EOS;
       return $html;
   }


   
Ok, I was able achieve what I wanted by using using the
Code: Select all
<cms:php> ...</cms:php>
tag. I simply converted the form outputs from their couch form
Code: Select all
<cms:set frm_xyz />
to regular php variables as such:
Code: Select all
<cms:php>
$var="<cms:show frm_xyz />";
</cms:php>

After converting to regular php variable, I was then able to concatenate its value to my URL as follows:
Code: Select all
<?php
$src="http://mysitename.abc?var=$var";
?>

And of course, I had to validate my form inputs to sanitise them before passing them on to my code/URL. I guess paranoia is the name of the game as far as user input is concerned :ugeek:
2 posts Page 1 of 1