This content has been marked as final. Show 3 replies
I think it would be simpler to use url variables instead of onClick functions.
I'm not sure I really understand what you are looking for but here's what I do when I want to use the same form to add or edit records:
The form gets either pre-filled with an existing record, or empty for new records. For existing records the record ID (primary key in the DB) is filled into a hidden field.
In the action script I can verify:
WHERE PK= #my_hidden_record_field#
INSERT into table_something
field1, field2, field3
So the data sent from the client to the server includes information if this is an existing record or a new record, and on server side you can process it accordingly. In this case it would not matter if the button is an update-button, or save- button.
This also allows you to simply build a copy-record feature if you need it (just empty the record field).
I think it may help you to evaluate in more detail what should happen SERVER-SIDE, and what should happen CLIENT-SIDE.
As example if you are talking about prior condition, I would expect on the server you would know about that condition, and could send the entry-form to the client already setup to be used as a edit-form OR a add-record-form.
Below is the detailed explanation of my problem
My application has two different users...
When the advisor logs in, he has two links to navigate to
The first page has drop down menus of other advisors from which he can add permissions for some activities. In the second page, the advisor has a form with text fields where he has to enter the student details manually. Right now there is a <a href="index.cfm">Add student only for me</a>. That is when the advisors click the "add student only for me" , adds a new student, and i am retrieving the values and making them display in the page.
I am doing this as follows:
a) I am retreiving the student name as a link, so when the advisor wants to edit some information about the student , he can do so.
b) Initially, I am setting two values like
<cfset student_edit = 0>
<cfset student_add = 0>
so when the student name is clicked , i set the student_edit to 1, and have the following hidden values:
<cfif student_edit eq 1>
<input type = "hidden name="editaction" value="edit">
<input type="hidden" name="addaction" value="add">
then i am creating my component object (by using <cfset saveobject = createObject(component.addstudent)>)and pass the required parameters like firstname, etc for saving the student details. There is a function called save_student() which requires parameters.
All this is working fine.
Recently, my prof asked me to add another link which says "Add student for all advisors". That is, the advisors he added in the previous page should also see these students in their students page. Currently What I am doing is as follow:
a) I created another anchor link saying "Add students for all advisors". I wrote a query to get the advisors whom the current advisor gave permissions to. Then I am getting their IDs from the database, and when I click the button, this particular student will get inserted for every advisor. So I write another function in the component to accomodate this change, which inserts this particular student for all the advisors. I am calling this function using the same component object I created above. Previously, because I coded that if its not an edit action, then add the student. Like below:
<a href="index.cfm" onClick="addform(1);return false;" <cfif editaction EQ 1>Save<cfelse>Add New Student.</cfif></a>. the addform() function is for validation purposes
<a href="index.cfm" onClick="addstudentsforall();addform(1);return false;" <cfif editaction EQ 1>Save<cfelse>Add New Student for all.</cfif></a>.
Now, the problem I am facing.
I hope you understood my question.