Forums

[solved]Save the record if condition

lopezio 30 Apr, 2011
I
I have one form and I want to save the values of the form in a database only if the user has the correct password.
I verify the password with a field named cod_prof

here is my php code for verify the user in On Submit code - after sending email

<?php
if($_POST['cod_prof']=="xxxyyy"){
$pasta=$_POST['Username'];
!JFolder::create('C:\xampp\xampp\htdocs\joomla\uploads'.DS.$pasta) ;
echo $_POST['cod_prof'];
}else{
echo "No permission";
}
?>

I get the No permission message if the user is note validated but the record is inserted in the database. How can I avoid that?
GreyHead 01 May, 2011
Hi lopezio,

The files are uplaoded long before the OnSubmit After Code is run. If you want to add extra validaton - which is what this is - then do it in the ServerSide Validation box on the Validation tab:
<?php
$cod_prof = JRequest::getString('cod_prof', '', 'post');
if ( !$cod_prof ) {
  return  "You must enter a code";
}
if ( $cod_prof != "xxxyyy" ) {
  return "No permission";
}
?>


Bob

PS I don't think that you need to create the folder; you can set the file name to include a custom folder in the File Uploads tab.
lopezio 01 May, 2011
Right answer Greyhead
Thank you
This topic is locked and no more replies can be posted.