• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass variable in url on form submit

#1
[eluser]Wonder Woman[/eluser]
Hi,

I have an edit url set up so that the article id is appended on the end, however when I got to submit the form it doesn't work because I can't append this variable on the end.

View:
Code:
echo anchor('admin/pages/edit/'.$page->id, 'Edit');

Controller:

function edit($page_id)
Code:
{
    $this->session->set_userdata('page_id', $page_id);
    $data['page_id'] = $this->session->userdata('page_id');
    $this->form_validation->set_rules('content','content','trim|required|htmlspecialchars');
    $this->form_validation->set_error_delimiters('<p class="error">* ','</p>');
    
    if($this->form_validation->run() == FALSE){
        $this->load->view('admin/pages/edit', $data);
    } else {            
        redirect('admin/pages/edit', $data);
    }
}

How can I do it so that the page will submit and go back to 'admin/pages/edit/1', for example.

Many thanks in advance.

#2
[eluser]d1a8lo24[/eluser]
Use the $page_id var and append/concatenate like you did in the anchor function in the redirect()

Code:
redirect('admin/pages/edit' . $page_id, $data);

#3
[eluser]Wonder Woman[/eluser]
I have tried that but it doesn't work, my browser says there is a problem loading the page.

#4
[eluser]d1a8lo24[/eluser]
Quick notice i guess you're using javascript to submit otherwise an anchor/link will not work to subit a form you need a form_open() and a form_close() thing.

More under
http://ellislab.com/codeigniter/user-gui...elper.html

#5
[eluser]d1a8lo24[/eluser]
Sorry i miss the '/'
Now try it again
Code:
redirect('admin/pages/edit/' . $page_id, $data);

#6
[eluser]d1a8lo24[/eluser]
Quick question do you have index function and are you using that to submit to the edit function in the same controller?

#7
[eluser]Wonder Woman[/eluser]
I have an initial view, pages.php:

Code:
anchor('admin/pages/edit/'.$page->id, 'Edit').' '.anchor($page->url, 'View');
// this is for every record

This then takes you to my edit page:

Code:
echo form_open();
echo form_label('Content: ','content');
echo form_hidden('page_id', $edit->id);
echo form_textarea('content', $edit->content, 'id="content"');
echo form_submit('save', 'Save');
echo form_close();

This is the edit function in the controller:

Code:
function edit($page_id)
{
    $this->session->set_userdata('page_id', $page_id);
    $data['page_id'] = $this->session->userdata('page_id');
    $this->form_validation->set_rules('content','content','trim|required|htmlspecialchars');
    $this->form_validation->set_error_delimiters('<p class="error">* ','</p>');
        
    if($this->form_validation->run() == FALSE){
        redirect('admin/pages/edit/'.$page_id, $data);
    } else {            
        redirect('admin/pages/edit', $data);
    }
}

Hope this makes sense...

#8
[eluser]d1a8lo24[/eluser]
Ok sorry on your redirect you can't pass any data

more info here
http://ellislab.com/codeigniter/user-gui...elper.html

#9
[eluser]d1a8lo24[/eluser]
Also if you were using the session to see if the page id was being past you can remove it.

If you were trying to pass that id then you don't need to put it in the array data since you already set in the session just use the session class to output the result in your view.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.