First problem here is that the admin is able to add a user, to the project, without actually selecting a user which they want to add. There should be a check, backend and front end, that checks if the user is submitting the form without having a user selected, and notifies the users.
The problem with the cancel button, in this instance, it works same as the submit button. The reason for this is that the cancel button has no button type declared in the source. Having no button type declared makes the browser treat at as a submit button. Next thing is the cancel button has some javascript, that is to take effect on clicking the button, but this javascript does not function properly, and this is why the button is handled as a submit as it has no action.
The proper fix here would be to add button type to the source. As this button has a on click, the button type would have to be button. So the source would look like something like the following
- Code: Select all
<button type="button" onclick="javascript action">Cancel</button>
but as the on click javascript doesn't function, clicking it, does nothing.
The question now is what should the cancel button actually do. Should it reset the user selection, toggle/close project user list, or something else. Personally, in this instance, I do not see the point of having a cancel button. As the user, if they have changed their mind, and do not want to add a user, can void their actions just by not clicking on the add button.
Second instead of using a drop down list, I think it should be a user list instead, that allows multiple selections. This way the admin can add multiple users, all at once, without having to add each person separately.
Now on to fixing this. My recommendations would be to completely remove the cancel button, not only is it not necessary, but I think it can also confuse people. If you are wanting to remove the cancel button, remove the following line found in adminprojects.tpl
- Code: Select all
<button onclick="blindtoggle('form_member');toggleClass('addmember','add-active','add');toggleClass('add_butn_member','butn_link_active','butn_link');toggleClass('sm_member','smooth','nosmooth');return false;" onfocus="this.blur();">{#cancel#}</button>
If you are not wanting to remove the button, and you are wanting it to reset the user selection and toggle/close the project user list, replace line 183, mentioned above, found in adminprojects.tpl, with the following.
- Code: Select all
<button type="reset" onclick="javascript:accord_projects.activate($$('#acc-projects .accordion_toggle')[{$smarty.section.opro.index}]);toggleAccordeon('acc-projects',this);">{#cancel#}</button>
Now we can even go further, and make the user field required, and have it trigger the javascript validation. To do this, in adminprojects.tpl, replace lines 167 to 173 with the following.
- Code: Select all
<form novalidate="novalidate" class = "main" method="post" action="manageproject.php?action=assign&id={$opros[opro].ID}&redir=admin.php?action=projects&mode=useradded" {literal}onsubmit="return validateCompleteForm(this);"{/literal}>
<fieldset>
<div class="row">
<label for="addtheuser">{#user#}</label>
<select name="user" id="addtheuser" required="1" exclude="-1" realname="User">
<option value = "-1">{#chooseone#}</option>
The last thing to do, would be to add some PHP code to the backend to actually validate and check if the admin is submitting the form without a user selected. And also, one more thing I noticed, not allow the admin to add the same user multiple times.