开发者

How to use <button type=button>

I’m usually Using input type submit eg: <inp开发者_开发知识库ut type=“submit” name=“assign” value=“Assign”/> and using this is no problem for me but now I want to use button eg:<button type=“button” class=“button” id=“deleteb”><div>Assign Student</div></button> but don’t know how to used it or call it to my controller.

this is my controller function

if($assign_student)//<input type="submit" name="assign" value="Assign"/>
{
    if($maxMember->max_members > $countMember)
    {
        if($countMember+1 == 1)
        {
            $is_leader  = 1;
        }
        else
        {
            $is_leader = $this->input->post('is_leader');
        }
        $student = array(
            'user_id' => $this->input->post('student'),
            'group_no' => $this->input->post('group'),
            'is_leader' => $is_leader
            );

        $this->admin_db->save_group($student['group_no'],$student);   
    }
    else
    {
        $data['max_error'] = "<p class='error'>Sorry, This group reached the maximum number of members!</p>";
    }  
}


If you want the button to submit the form you must have type="submit"

If you want the button to send a value, it's better to use a hidden input to send along additional information. Example:

<input type="hidden" name="assign" value="Assign" />

You can set a name and value to the <button>, but guess what?: In IE6, the actual html content of the button will be sent as the post data instead. It's one of my favorite bugs.

It's not very clear why you posted your controller code, but if you are checking for a "trigger" value before processing, like $this->input->post('assign'), you can check for the presence of any other of the form values instead, or the presence of any $_POST values, or as I mentioned: a hidden input.


If you press a submit-button, you are posting a form to some script, in this case PHP.

if you submit the form, your browser sends the information contained in the form to the receiving script.

eg, if you make a page with a form that contains:

You can check like this...

if (isset($_POST["deleteb"]))
{
//Do stuffs
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜