Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:11:08+00:00 2026-05-28T17:11:08+00:00

I got one controller called Profile with several function such as get_user_timeline and do_upload

  • 0

I got one controller called Profile with several function such as get_user_timeline and do_upload. The get_user_timeline loaded into profile_view with ajax call from JQuery. It’s functionality is to pull twitter timeline every 60 second.

It was running well after i put a form into the view to call the do_upload function. do_upload functionality is to upload file such as picture or mp3 to server. I put form validation into that function so when user didn’t fill the entire from he/she will redirect back to profile_viewwith some warning. I did it by calling $this->index() in the do_upload function.

When i tested my code, I submitted the form with several input left blank. The profile_view loaded with nice form validation error warning, but it seems my Jquery won’t work anymore because it doesn’t display the twitter timeline. I checked the url.. it’s say http://localhost/myproject/profile/do_upload instead http://localhost/myproject/profile . Is it CI default behavior? how to deal with it? it seems my Jquery only works with the http://localhost/myproject/profile could you give any advices guys? thanks

here’s my code.
The profile controller

<?php

class Profile extends CI_Controller
{
    function __construct()
    {
        parent::__construct();

        $this->load->library('tweet');
        $this->load->library('form_validation');
        $this->load->model('user_model');

    }

    function index()
    {
        if($this->session->userdata('is_logged_in') == TRUE)
        {

            $data['biography'] = $this->user_model->get_user_by_id($this->session->userdata('user_id'));


            $data['user'] = $this->tweet->call('get', 'users/show', array('id' => $this->session->userdata('user_id')));

            $data['main_content'] = 'private_profile_view';
            $this->load->view('includes/template', $data);
        }
        else
        {

            redirect('welcome');
        }
    }


    /** timeline features **/
    function get_home_timeline()
    {
        $timeline = $this->tweet->call('get', 'statuses/home_timeline');
        echo json_encode($timeline);

    }


//the do_upload function
function do_upload()
    {
        $config['upload_path'] = './media/';
        $config['allowed_types'] = 'mp3';
        $config['max_size'] = '30720';

        $this->load->library('upload', $config);
        //set validation rules
        $this->form_validation->set_rules('title', 'Song title', 'trim|required|xss_clean');
        $this->form_validation->set_rules('album', 'Album', 'trim|required|xss_clean');
        $this->form_validation->set_rules('artist', 'Artist', 'required|xss_clean');
        $this->form_validation->set_rules('song_license_agreement', 'License', 'required|xss_clean');

        if ($this->form_validation->run() == FALSE)
        {
            $this->index(); //this return the warning but make my Jquery fail
        }
    }   

THE .JS

$(document).ready(function(){


                update_timeline('profile/get_home_timeline', '#home_timeline ul', 'home'); //this is call to the timeline, this won't work if i submit the upload form

});

function update_timeline()
{
   //my ajax call goes here
}

THE VIEW

<div id="timeline" class="">
            <ul>
                <li><a href="#home_timeline" id="home_timeline_menu">Home</a></li>
                <li><a href="#user_timeline" id="user_timeline_menu">MyStatus</a></li>
                <li><a href="#mentions_timeline" id="mentions_timeline_menu">@me</a></li>
            </ul>
            <section id="home_timeline">
                <ul>
                   <!-- this is where the timeline goes -->
                </ul>
            </section>
<div>
<!-- and this is the form -->
<article id="music_upload_form">

                <?php echo validation_errors(); ?>
                <?php echo form_open_multipart('profile/do_upload');?>
                <input type="hidden" id="user_id" name="user_id" value="<?php echo $user->id_str;?>" />
                <label for="title">Song Title</label>
                <input type="text" name="title" id="title" size="30" value="<?php echo set_value('title'); ?>"/><br />
                <label for="album"> Album Title </label>
                <input type="text" name="album" id="album" size="30" value="<?php echo set_value('album'); ?>"/><br />
                <label for="artist">Artist</label>
                <input type="text" name="artist" id="artist" size="20" value="<?php echo set_value('artist'); ?>"/><br />
                <input type="file" name="userfile" size="20" /><br />
                <input type="radio" name="owner" id="license" value="<?php echo set_value('owner'); ?>"/>I AM the artist/owner of this song and I have the right for distribution<br />
                <input type="radio" name="licensed_user" id="license" value="<?php echo set_value('licensed_user');?>"/>I AM NOT the artist/owner of this song BUT I have the right for distribution</br>
                <input type="checkbox" name="song_license_agreement" value="<?php echo set_value('song_license_agreement');?>"/>By selecting this option, I swear that all information entered is right<br />
                <input type="submit" value="Upload Your Song" />
                </form>
            </article>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:11:09+00:00Added an answer on May 28, 2026 at 5:11 pm

    OK, I think I get what’s going on here.

    Instead of calling $this->index(), which just runs the index() method in the current one, redirect the user instead.

    function do_upload()
    {
        if ($error)
        {
            redirect('profile');
        }
    }
    

    Calling $this->index() doesn’t actually change the URL or current method, it just runs whatever code you have there.

    To get the errors to display on the next page, you can assign them to a session item:

    $this->session->set_flashdata('errors', validation_errors());
    

    Then in your view:

    echo $this->session->flashdata('errors');
    

    I used flashdata because it will automatically be cleared on the next request. You might want to look into writing or adopting some kind of feedback/message library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a controller called Items and another one called Categories. Items may belong
I've got one function checkEvery15Seconds that runs every 15 seconds. It checks to see
The setup I have an MVC application that's making AJAX requests into my controller.
new to cakePHP and trying my first join. I've got one table called users
I got one UITextField on my Modal view controller. When Done key is clicked,
I got one big question. I got a linq query to put it simply
I got one problem at my exam for subject Principal of Programming Language. I
I got one main search field always visible at the site and a login
I've got one long GridView control on ma website. It allows row selection. The
I've got one really big .java class file that has a lot of members.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.