Page 1 of 1

CreateFormStart Issue

Posted: Thu May 22, 2008 3:27 am
by rbharany1
Hi

I am a newbie using CMS Made Simple.
I need to create a form which will allow administrators to upload certain files needed for processing data to the front end users.
I am trying to create a module using the module tutorial on the site and have a problem
I am trying to use the CreateFormStart method to create the form and call an action.php file (in this case action.do_upload.php file).
The code I was using is fairly simple as I was just trying to see if the CreateFormStart actually calls the action file on a button submit which will return nothing but an echo telling me that the file has been successfully called.
the code I'm using in the module.php file is as follows:

Code: Select all

echo $this->CreateFormStart($id,"do_upload");
echo $this->CreateInputSubmit($id,"submit","Upload File");
echo $this->CreateFormEnd();
The code of my action.do_upload.php file is as follows:

Code: Select all

<?
  echo ("This is here");
?>
 

The problem I am having is on submit the page is not being called and all I can see is the module header in the admin section.
Nothing is being echoed back to me.
Can somebody please guide me on what I am doing wrong?

Re: CreateFormStart Issue

Posted: Sat May 24, 2008 1:29 pm
by duclet
You need to post more of the code. Also, posted the generated HTML as well.

Re: CreateFormStart Issue

Posted: Sat May 24, 2008 1:35 pm
by calguy1000
That code looks valid for an admin side action... as duclet said, we'll have to see more of the files... because it's probably something simple that is wrong somewhere.

Re: CreateFormStart Issue

Posted: Sun May 25, 2008 11:54 pm
by rbharany1
Hi Guys

Thank you for your reply.
I have managed to sort out this issue, which was that i was actually making this declaration in the main module declaration file under the function action( as was explained in the module tutorial).
I have removed the code from there and set up a new action.defaultadmin.php file which is where I an now writing the following code section

Code: Select all

 echo $this->CreateFormStart($id,"do_upload",$returnid,"post","multipart/form-data");
 echo $this->CreateInputHidden($id,"upload","upload");
 echo "<table>";
 echo "  <tr>";
 echo "    <td>Choose the vacancy file to upload</td>";
 echo "    <td>";
 echo $this->CreateInputFile($id,"uploadedfile","'text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel'",'25');
 echo "    </td>";
 echo "   </tr>";
 echo "   <tr>";
 echo "    <td colspan=2>";
 echo $this->CreateInputSubmit($id,"submit","Upload File");
 echo "    </td>";
 echo "   </tr>";
 echo "</table>";
 echo $this->CreateFormEnd();
This is now calling the action.do_upload.php file correctly.
However i now have another issue which is....how do I actually access and move the file which is being uploaded. I could do this is php by the following code and actually want to know what is the CMS Made Simple equivilent for this

Code: Select all


//set the destination folder
define('target_path','TestingFile/');

//Test to see if the file has been picked up correctly--comment out before actual deployment
print_r($_FILES);

//Set the allowed files type to be uploaded (currently only CSV file types are allowed)
  $ftypeAllowed = false;
  $fileTypes = array('text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel');
  //Check to see if the file type being uploaded is the correct type
  foreach($fileTypes as $types){
    if($types == $_FILES['uploadedfile']['type']){
       $ftypeAllowed = true;
        break;
    }
  }

  if($ftypeAllowed){
    $file ="TestFile.csv";  
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'],target_path.$file);
    echo("File Uploaded Successfully");
  }
  else{
    echo("This file type is not allowed to be uploaded");
  } 
  
The reason I'm asking is that when the action.do_upload.php file is being called, it seems to me that it is losing the reference of the file input box and returning a null value.
Also if possible could you explaing to me that in this type of scenario is there any way to actually check if a form post has been done or is that taken for granted.

Once again thank you for your help

Re: CreateFormStart Issue

Posted: Mon May 26, 2008 12:30 pm
by calguy1000
and use cms_move_uploaded_file() which has additional checks for file size, and all that

Also, you'll find it easier if your admin forms use smarty templates too.