Welcome Guest, Not a member yet? Register   Sign In
redirect after post?
#1

[eluser]Zero-10[/eluser]
My site is setup as such:
domain.com/section/articles/subsection/articleid

naturally the article id is stored as say... $articleid and is called upon for breadcrums and other things but one thing that I can't seem to get is have a form redirect to that specific article.

I tried things like (inside the comment post function)
redirect('section/articles/subsection/' . $articleid);

in function commentpost but it doesn't do too well and the url is always
section/articles/commentpost

What do I do? Sad
#2

[eluser]Wondering Coder[/eluser]
why don't you try using route.?
#3

[eluser]pmoroom[/eluser]
I don't understand the problem. Are you saying you are not getting $articleid?
#4

[eluser]Zero-10[/eluser]
What I'm getting is something like:
mysite.com/section/articles/comment_insert

instead of getting:
mysite.com/section/articles/subsection/articleid

In other words, when [submit] is clicked, it should basically refresh the page but it doesn't. I'd love to have it be AJAX one day but keeping it simple first would be the most ideal.
#5

[eluser]cideveloper[/eluser]
post some code. Where is the form action pointing to?
#6

[eluser]Zero-10[/eluser]
Form is pointing to
Code:
function comments_insert()
        {
            $this->db->insert('comments', $_POST);
            redirect('section/articles/subsection/' . $articleid);
        }

I simplified the redirect to make it more obvious of what I'm talking about. It's in the same controller as the article is found from.
#7

[eluser]aquary[/eluser]
You forgot to put the articleid inside the function's parameter.
Code:
function comments_insert($articleid)
        {
            $this->db->insert('comments', $_POST);
            redirect('section/articles/subsection/' . $articleid);
        }

If the articleid is in $_POST, you'll have to use the $_POST['articleid'] instead, but normally I'd put it in the URI.
#8

[eluser]Zero-10[/eluser]
I did that before, does nothing.
#9

[eluser]aquary[/eluser]
What was you form's code anyway? the action part is to where? Maybe it'll be more useful if you show us the full code, so we could understand you motive Smile
#10

[eluser]skunkbad[/eluser]
Code:
$segs = $this->uri->segment_array();
// assuming that article ID is always the last URI segment
$articleid = end( $segs );
redirect('section/articles/subsection/' . $articleid);

Normally I post all forms to the same method, and by doing that, the above code would work. You'd just have to run form validation and determine if there is a valid post vs a page load of the article.

I think for your code, you might try this:

Code:
function comments_insert()
{
    $this->db->insert('comments', $_POST);
    redirect('section/articles/subsection/' . $this->input->post('articleid'));
}

Although unless you are validating the $_POST array and rewriting $_POST, you're using some potentially unsafe code;




Theme © iAndrew 2016 - Forum software by © MyBB