Welcome Guest, Not a member yet? Register   Sign In
Post value isn't displayed in view
#1

[eluser]Unknown[/eluser]
I faced a problem with posting a value from field ( text.val() ) to a view page. Everything seems to be fine, console log shows the data but from the php function it doesn't show anything ( it only does if it is encrypted with sha1). If you need more details please ask, this is frustrating.
Quote: //Result in page view
//passed(post) : da39a3ee5e6b4b0d3255bfef95601890afd80709
//no sha(post) :
//console.log passed plain(post) :: PLFyUEsvfX7p-ptrJzMMrhUKTkFRI48m6b

//controller
Code:
public function importPlaylistYT($id ="PLFyUEsvfX7p-ptrJzMMrhUKTkFRI48m6b",$index = 1,$results = 2){
  
     $ytclass = new YTClass;
  //$innerdata = $ytclass->playlist_feed('PL1A3F38B724842E2C', 1, 2);
  // Validate stuff
  
  if(!is_numeric($index)) {
   $ytclass->error = "playlist_feed() - Second parameter (index) must be numeric";
   return false;
  }
  if(!is_numeric($results)) {
   $ytclass->error = "playlist_feed() - Third parameter (results) must be numeric";
   return false;
  }
  
  $result = $ytclass->curl_run('http://gdata.youtube.com/feeds/api/playlists/'.$id.'?start-index='.$index.'&max;-results='.$results);
  if($result == false)
   return false;
  if(strlen($result) < 100){
   $ytclass->error = 'playlist_feed() - '.$result;
   return false;
  }
  
  // Start parsing with SimpleXML
  $xml = simplexml_load_string($result);
  
  // Number of results, index and results per page
  $openSearch = $xml->children('openSearch', true);
  $result_arr = $ytclass->open_search($openSearch);
  
  $c = 0;
  foreach($xml->entry as $entry) {
   $result_arr['results'][$c] = $ytclass->parse_entry($entry);
   $c++;
  }

  //var_dump($result_arr['totalResults']);
  echo "<pre>";
  var_dump($result_arr);
  echo "</pre>";
  $x=0;
  $store=array();
  //foreach($result_arr as $dataset){
  // $store[] = array_push($dataset['results'][$x]);
  // $x++;
  //}
// $store[] = array_push($dataset['results'][$x]);
//var_dump($store);
  //echo 'http://gdata.youtube.com/feeds/api/playlists/'.$id.'?start-index='.$index.'&max;-results='.$results;
  $password1  = sha1($this-&gt;input-&gt;post("yt_id",TRUE));
  $password2  = $this-&gt;input-&gt;post("yt_id");
  echo "passed : " .$password1 ."&lt;/br&gt;";
  echo "no sha :" .$password2;
                //Result in page view
  //passed(post) : da39a3ee5e6b4b0d3255bfef95601890afd80709
  //no sha(post) :
  //console.log passed plain(post) :: PLFyUEsvfX7p-ptrJzMMrhUKTkFRI48m6b
  //$this-&gt;input-&gt;post("yt_id")
  //js $.post('music/importPlaylistYT', {"yt_id": ytpllink}, function(data, textStatus)

  
  //can you do all this for 10? ill make it easy for you and might get more tasks
  

  $this->load->view('ajax/importPlaylistYT',$data);
}
//js handler
Code:
function importPlaylistYT()
{
var ytpllink  = $('#getYTlink [name="yt_id"]').val();
//if(isEmpty(ytpllink))
//{
// alert(msg_required_fields);
// return false;
//}
$.post('music/importPlaylistYT', {"yt_id": ytpllink}, function(data, textStatus) {
alert( "success" );
})
  .done(function() {
    alert( "second success" + ytpllink);
console.log("passed on js : " + ytpllink);
   $("#YTImporterModal").modal("hide");
      show_loading();
   $.get(base_url+"music/importPlaylistYT/", function(data, textStatus) {
    $("#target").html(data);
   });
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
});

}
function importPlaylistYT_modal()
{
$("#YTImporterModal").modal("show");
}

//main frame view music.php
Code:
@MODAL
<div class="modal" id="YTImporterModal">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
              <h4 class="modal-title">&lt;?php echo ___("label_change_password"); ?&gt;</h4>          
          </div>
          <div class="modal-body loginModal">
              &lt;form class="form-signin" role="form"&gt;
                <div id="getYTlink">
                  <h3 class="form-signin-heading">&lt;?php echo ___("label_change_password"); ?&gt;</h3>                  
                  &lt;input type="text" name="yt_id" class="form-control" placeholder="Give PL id" required&gt;                                
                  <button   class="btn btn-primary"  type="button">&lt;?php echo ___("label_change_password_button"); ?&gt;</button>                          
                </div>

                
                <div class="clearfix"></div>
              &lt;/form&gt;
              
          </div>          
        </div>
      </div>
    </div>
@LinK for modal popup
Code:
<li id="importPlaylistYT">
<a href="#" >F</a>
</li>
//page view importPlaylistYT.php
Code:
<div class="row">
<div class="jumbotron"  id="">

  <h1></h1>
  <h3><strong></strong></h3>


    <p></p>
</div>
</div>
&lt;?PHP
if(count($importPlaylistYT->data) == 0)
    {
        ?&gt;
        <div class="alert alert-info">
            <strong>&lt;?php echo $query ?&gt;</strong>  No Found!
        </div>
        &lt;?php
    }  
?&gt;
#2

[eluser]joergy[/eluser]
da39a3ee5e6b4b0d3255bfef95601890afd80709
is the sha1() from the value false
Therefor Your $this->input->post("yt_id",TRUE) returns false and not a value.
That's the reason why you don't have an output for "no sha :"

I haven't walked through Your code for the reason, but probably this info helps You.
#3

[eluser]CroNiX[/eluser]
To expand on what joergy is stating, if the variable you request via $this->input->post('var_name') does NOT exist in $_POST, it will return boolean false. Therefore, it seems that your js is incorrect here:
Code:
var ytpllink  = $('#getYTlink [name="yt_id"]').val();

You should probably give your input element it's own ID and then reference it in your js.
Code:
&lt;input type="text" name="yt_id" id="yt_id" class="form-control" placeholder="Give PL id" required&gt;

Code:
var ytpllink  = $('#yt_id').val();




Theme © iAndrew 2016 - Forum software by © MyBB