Welcome Guest, Not a member yet? Register   Sign In
[Not Working]Do something when Input Button is submited
#1

[eluser]flyenig[/eluser]
EDIT:Changed a few things

Hello.

simple Question:

how can i run a query or something when someone clicks on a button?

This is my stuff, but its not working

the controller:
Code:
//This displays friend requests, and i can approve them here
function show_requests()
{
    $query2 = $this->membership_model->get_requests($this->session->userdata('user_id'));
    $data['req'] = $query2;

    $data['action'] = site_url('site/process_req');
    $data['title'] = '';
    $data['sec_title'] = '';
    $data['main_content'] = 'view_req';

    $this->load->view('m_user_home',$data);    
        
}

//this processes the friend requests base on which button was clicked
function process_req()
{
    if($this->input->post('deny'))
    {
        redirect('site/show_users/','refresh');
    }
    elseif($this->input->post('accept'))
    {
        redirect('site/');
    }
}

The view:
Code:
<form action="<?php echo $action; ?>" style="display:block">
    <input type="submit" value="deny" class="butn rounded" name="deny"/>
           <input type="submit" value="accept" class="butn rounded" name="accept" />
</form>

What am i doing wrong?
#2

[eluser]Colin Williams[/eluser]
User Guide.
#3

[eluser]flyenig[/eluser]
yes ive read the user guide. but i cant find what im looking for
#4

[eluser]Colin Williams[/eluser]
Look again at the Controllers page. It will reveal how to use the URI to pass parameters to the controller. Then look at the URI Class to see various ways to access the URI parameters
#5

[eluser]flyenig[/eluser]
Ok i changed the Question because im using forms now.

Well now that im using this method, its not working.
What am i doing wrong?
#6

[eluser]Colin Williams[/eluser]
You are missing key knowledge on how this whole game works. Maybe start here http://www.w3schools.com/php/php_forms.asp
#7

[eluser]flyenig[/eluser]
im not new to php, im just new to the forums, and ive been working with codeigniter for a while now, its just this simple thing that i do not get.

Like everytime i click on, for example, deny, it takes me to a blank page with the url

http://localhost/www/cl/index/site/process_req?
#8

[eluser]Colin Williams[/eluser]
Didn't claim you were new to anything, just missing a lot of pieces. You might be able to program a lunar mission in PHP, but I just recognize that you are missing very basic Web development fundamentals. First, your buttons contain no "name" attributes. Look at the HTTP Request you are sending and you'll see the problem that causes. And I don't know what your $action variable contains, but whatever is there is why your form is going where it is going.
#9

[eluser]flyenig[/eluser]
Ok I appologize,
I didn't put enough of my code on here and yea wow I forgot the name attributes lol

Since im typing this from my ipod, Tomorrow I'll post more of my code so I can get more help and so u guys can understand what I need help with.

But thank you for ur help so far Smile
#10

[eluser]flyenig[/eluser]
ok i posted more code, check the first post




Theme © iAndrew 2016 - Forum software by © MyBB