This topic is locked

Confirm Save on Edit page

3/13/2008 1:25:56 AM
PHPRunner General questions
L
laonian author

I have a field named lock_record (type: checkbox) on the Edit page. If it is checked, the record will be locked after Save and no more editing will be possible. I want the user to confirm on this selection. It seems that I could modify the Save button like:
if ($values["lock_record"]==1)
<SPAN class=buttonborder><INPUT class=button onclick="if (!confirm('You have selected to lock the record which will prevent it from further editing. Do you really want to do that?')) return false;" type=submit value=&nbsp;&nbsp;Save&nbsp;&nbsp; name=submit1></SPAN>
My problem is I don't know how to include the "if" condition in the Save button script. Could anybody help me? Thanks.

Sergey Kornilov admin 3/13/2008

The short answer - you cannot do this.
onclick event (Javascript) happens on the client where you don't have access to the database.

S
spintz 3/13/2008

This is possible, and I do similar things, they just are not readily available in PHPR, so it requires a bit of custom code.
In your edit page, you want to have code like this -

<!-- The checkbox -->

<INPUT id=lockRecordCheck type=checkbox value="Lock Record" >

<!-- a hidden input, that holds the value from the javascript verification process -->

<INPUT type=hidden id=lock_record name=lock_record value=0 >
<!-- This function is called when the Save button is clicked. -->

<script>

function OnLockVerify()

{

var lock_recordObject = document.getElementById( "lock_record" );
if( document.getElementById( "lockRecordCheck" ).checked )

{

// If they say they really don't want to lock it, go ahead with the save, just change the value of the lock_record hidden input

if( confirm( 'You have selected to lock the record which will prevent it from further editing. Do you really want to do that?' ) )

{

lock_recordObject.value = 1;

}

else

{

lock_recordObject.value = 0;

}

}

else

{

lock_recordObject.value = 0;

}

}

</SCRIPT>
<!-- The save button, it calls the OnLockVerify function and returns true -->

<SPAN class=buttonborder><INPUT id=savebutton class=button onclick="OnLockVerify(); return true;" type=submit value=&nbsp;&nbsp;Save&nbsp;&nbsp; name=submit1></SPAN>


Then, in your BeforeEdit event, you want to do this, so the lock_record value can be set

$values['lock_record'] = $_POST["lock_record"];
L
laonian author 3/14/2008

This is possible, ...


Dear Spintz, you are my hero!
I did not hold any hope after the Admin has answered : you cann't do it. That is why did not come back to this thread until this morning. After using your codes (without any changes), my project worked like a charm. This is exactly what I need. I really appreciate that I get such a big help from you, an advanced PHPR member, besides the support group, turning the impossibles into possibles.

S
spintz 3/14/2008

Glad to have helped!