Jake
Jake

Reputation: 151

Submit Button Only Working on Index Page

Been having trouble with a form not submitting data to a page (Change Password) when on any page of the website apart from the index page (Which is working as it should). The website is built using CodeIgniter.

The code currently used on all pages for the form is the following:

<div class="modal-body">
    <form role="form" id="change_password_form" action="<?php echo base_url('auth/change_password')?>" method="post">
        <fieldset>
            <div class="form-group">
                <input class="form-control" placeholder="Old Password" name="old" type="password" autofocus>
            </div>
            <div class="alert alert-danger" id="old" role="alert" style="display:none"></div>
            <div class="form-group">
                <input class="form-control" placeholder="New Password - minimum 8 characters" name="new" type="password" value="">
            </div>
            <div class="alert alert-danger" id="new" role="alert" style="display:none"></div>
            <div class="form-group">
                <input class="form-control" placeholder="Confirm New Password" name="new_confirm" type="password" value="">
            </div>
            <div class="alert alert-danger" id="new_confirm" role="alert" style="display:none"></div>
            <input type="hidden" name="user_id" value="<?php echo $user_id;?>" id="user_id"  />
        </fieldset>
</div>
<div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="changepassword" value="Submit">Submit</button>
    </form>
</div>

On the index page, this successfully goes to the change_password function and will check the details to see if they meet the rules. An error message is shown below the text box when submit is clicked. However on other pages using the same code, nothing happens when submit is clicked. when I go into Main.php and change the page of index.php in the index function to any other page (view_inventory.php for example), The change password works correctly on the new index page, but will not work on the old index page.

I can get the change password to work on other pages if I replace the submit button with the code below (Doesn't show the results under the text boxes, but on a new blank page), but I didn't really want to have to edit so many pages if it can be fixed in a smaller amount.

<input type="submit" value="Submit" class="btn btn-primary">

Any help would be gratefully appreciated.

Upvotes: 1

Views: 102

Answers (1)

Peter Black Moore
Peter Black Moore

Reputation: 92

I had the same error last week. you have to use a Submit inside form instead of button.

You can use form_submit for example:

echo form_submit('mysubmit', 'Submit');
// Would produce:  <input type="submit" name="mysubmit" value="Submit" />

Here is the documentation:

http://www.codeigniter.com/user_guide/helpers/form_helper.html

Regards.

Upvotes: 1

Related Questions