Cancel button on a form |
[eluser]Unknown[/eluser]
Hi, Following the example in the documentation and the video tutorial, it seems neat to be able to run validation rules, etc, on forms, and submit with something simple like: Code: if ($this->form_validation->run() == FALSE) This is great for forms with a single, unnamed submit button. But if I add a cancel button to my form, I need to name the buttons in order to tell which is pressed: Code: <input type="submit" name="submitOK" value="Submit Comment" /> in the form, and then: Code: if ( array_key_exists('submitOK', $_POST) ) {...} in the controller. The problem is then that the POST array contains an array_key 'submitOK', which unlike all other POST entries does not correspond to an a database field for my INSERT action. The two options I can think of are: 1) Remove the array key with unset($_POST['submitOK']) - but doesn't seem right messing with the system's POST array 2) Creating a new array duplicating all elements except this one Both options seem a bit messy, given the otherwise very clean form process provide by CI. Is there a better alternative? Thanks, Dan
[eluser]umefarooq[/eluser]
you can use link for cancel process just put the page name you want to show if clicked Code: <a href="page.php">Cancel</a>
[eluser]CroNiX[/eluser]
I use this: Code: if ($this->form_validation->run() === FALSE && $this->input->post('submitOK'))
[eluser]saidai jagan[/eluser]
I use this <input type="submit" name="submitOK" value="Submit Comment" /> <input type="button" name="submitCancel" value="Cancel" onclick="redirect('some controller');">
[eluser]Tandubhai[/eluser]
<input type=“submit” name=“submitOK” value=“Submit Comment” /> <input type=“button” name=“submitCancel” value=“Cancel” onclick=“redirect(‘some controller’);” > Quote:<script>
[eluser]andrewtheandroid[/eluser]
Alternatively you can make a link to where you want to redirect then style it as a button using CSS. or use the <button> tag in a link. Code: // button link
[eluser]Aken[/eluser]
For usability purposes, a "Cancel" feature relating to a form should be a link. Definitely not a submit input or a button, and DEFINITELY not one right next to the submit button.
[eluser]JoostV[/eluser]
Most Web forms would have improved usability if the Reset button was removed.
[eluser]Colin Williams[/eluser]
Your model should remove the value before it performs the insert. Also, why is everybody harking on him about the cancel button?
|
Welcome Guest, Not a member yet? Register Sign In |