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

[eluser]Zero-10[/eluser]
@skunkbad

I tried $this->input etc... and unfortunately that lead to the same error of a blank page url: http://www.mysite.com/comments_entertainment_insert

controller:
Code:
function articles() {
$articleid = $this->uri->segment(4, 6); //this works perfect, no need to correct this
etc...

function comments_insert()
{
    $this->db->insert('comments', $_POST);
    redirect('entertainment/articles/information/' . $articleid);
}

view file:
Code:
<?=form_open('section/articles/comments_insert');?>
<?=form_hidden('cme_articles_article', $this->uri->segment(4));?>
<?=form_hidden('cme_articles_author', $this->phpbb_library->getUserInfo('user_id'));?>
<textarea name="cme_articles_body" id="cme_articles_body" rows="3"></textarea>
<button type="submit"><img src="button.png" width="102" height="28" border="0" alt="submit" style="cursor: pointer;" /></button>
&lt;/form&gt;
I removed styles and a bunch of other stuff to make it more readable but that's basically how it's set up. It's really depressing when you think you're getting somewhere because things just work and then there's a show-stopper even though it should technically work :/

Please ignore the security vulnerabilities, I'm aware, I just want to get this to work first before adding validation etc...
#12

[eluser]aquary[/eluser]
Which one of those fields is the articleid ? Is it cms_articles_article ?
In that case, try this one for comments_insert():
Code:
function comments_insert()
{
    $this->db->insert('comments', $_POST);
    redirect('entertainment/articles/information/' . $this->input->post('cme_articles_article'));
}
#13

[eluser]Zero-10[/eluser]
[quote author="aquary" date="1309174987"]Which one of those fields is the articleid ? Is it cms_articles_article ?
In that case, try this one for comments_insert():
Code:
function comments_insert()
{
    $this->db->insert('comments', $_POST);
    redirect('entertainment/articles/information/' . $this->input->post('cme_articles_article'));
}
[/quote]

You're correct, cme_articles_article is the database column for the article id however that did nothing.

Just in case that this makes a difference... in my config file i have:
Code:
$config['uri_protocol']    = "AUTO";
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']     = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']     = 'd'; // experimental not currently in use

Thanks for the help so far!
#14

[eluser]aquary[/eluser]
Try print_r($_POST); to see what got posted.
#15

[eluser]InsiteFX[/eluser]
Code:
echo $this->input->post('cme_articles_article');

redirect('entertainment/articles/information/' . $this->input->post('cme_articles_article'), 'refresh');

If that does not work then you have a problem retriving your article_id

InsiteFX
#16

[eluser]oneos[/eluser]
Might I suggest

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



Code:
//view (I'm assuming your "post comment" / "view article" view has access to $articleid:

&lt;?=form_open('section/articles/comments_insert/'.$articleid)?&gt;
    ... your form here
&lt;/form&gt;

or somesuch
#17

[eluser]Zero-10[/eluser]
adding $articleid to both the comments_insert($articleid) and the form was brilliant and will likely solve the issue on where it needs to go once the url goes somewhere but at the present time it goes to..

http://www.mysite.com/comments_insert

instead of

http://www.mysite.com/section/articles/s.../articleid

very strange considering that everything posts just fine (it gets stored int he database and everything). For some reason redirect doesn't redirect.

EDIT: Scratch that, if i add in the full url, it will redirect properly but the articleid is still missing wtf? This doesn't logically make sense unless codeigniter has a limit to how far you can pass a variable.

controller passes it to viewfile > viewfile passes it to another view file > that view file passes it to another view file > that view file passes it back to the controller for posting

EDIT #2: Although I'm baffled to why $articleid didn't work, another code worked thanks to aquary. The problem was that as the redirect I had to add a the full url including http:// in order for it to redirect -somewhere- and after that it was just a matter of grabbing the article id which I got from posting.

Code:
echo $this->input->post('cme_articles_article');

redirect('section/articles/subsection/' . $this->input->post('cme_articles_article'), 'refresh');

Thank you all for helping, I don't think I would have come to this conclusion on my own.
#18

[eluser]Zero-10[/eluser]
Sorry for double posting but I'd assume that people would have read my previous post and ignore any edit update at this point Tongue

The problem with the redirect method is that it redirects fine, but it doesn't "refresh" the page. That being said you don't see the comment that was just posted unless you refresh. Without using jquery/ajax stuff (although that would be pretty sexy) is it possible to get it to load the new comment with redirect('....'); or is something else needed?

I'm sorry with all of these questions >_<;
#19

[eluser]oneos[/eluser]
Although I do not see why the new comment would not show up as it currently is (without severe database performance issues), you could try redirect('...', 'refresh');
#20

[eluser]Zero-10[/eluser]
[quote author="oneos" date="1309298201"]Although I do not see why the new comment would not show up as it currently is (without severe database performance issues), you could try redirect('...', 'refresh');[/quote]

hmm that killed it lol! Big Grin

I worked with AJAX instead of having it static like that so I'll have to tip my hat at jquery for the big help Smile




Theme © iAndrew 2016 - Forum software by © MyBB