Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] change form submit function on with javascript?
#1

[eluser]Brandt1981[/eluser]
I am using CI and the doctrine plugin to do CRUD.

I want to be able to switch the submit destination function based on the state of the text boxes in the form.

If all the text boxes in the form are blank and I fill them out and hit submit, I want it to create a new database record ( know how to do the doctrine part ).

If the text boxes contain text as the result of a query by primary key ( I know how to query ) and then the text is modified, I want the submit to call on the update function in the controller to update the record. ( I got this part working but need to know how and when to switch between the different submits )

If the text boxes contain text and they are blanked out, then I want the submit to delete the field ( I think update will do this ) or do I need a delete function


Maybe this would be easiest with radio buttons at the top that specify
(Update, Create, Delete) Create being default if the text boxes are blank on a page load, or update being the default after returning a record...?
#2

[eluser]LuckyFella73[/eluser]
I would not try to switch with js. You can place some hidden form fields
and switch the values depending on what status you have. When passing
data from DB to the form set the value of hidden input field to something
like "edit" for example.

I would prefer to add a delete button as well instead of deleting the record
in case no input is given.
#3

[eluser]Brandt1981[/eluser]
Thanks, I figured out how to switch them using a variable in the view's form_open uri's and setting them in the controller as needed.
#4

[eluser]Unknown[/eluser]
could you please explain in detail how you did that?
#5

[eluser]Brandt1981[/eluser]
home.php Controller:

in the index function I have this:

Code:
$vars['submit']='create';
$this->load->view('home',$vars);


In the query function I have this:
Code:
$vars['submit']='update';
$this->load->view('home', $vars);


home.php View:

form action looks like this:

Code:
<?php echo form_open('home/'.$submit); ?>
#6

[eluser]Unknown[/eluser]
Thanks for ur information...

web designers




Theme © iAndrew 2016 - Forum software by © MyBB