CreateFormStart Issue

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
rbharany1
New Member
New Member
Posts: 2
Joined: Thu May 22, 2008 3:10 am

CreateFormStart Issue

Post 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?
User avatar
duclet
Forum Members
Forum Members
Posts: 187
Joined: Fri Jun 23, 2006 12:55 pm

Re: CreateFormStart Issue

Post by duclet »

You need to post more of the code. Also, posted the generated HTML as well.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CreateFormStart Issue

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
rbharany1
New Member
New Member
Posts: 2
Joined: Thu May 22, 2008 3:10 am

Re: CreateFormStart Issue

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: CreateFormStart Issue

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”