Programming Tips : Input Without Form & PHP shortcut

Hello guys! I’m Chrisandy, people use to call me Sandy or Chris. I’m currently doing internship at Tansah Web & Innovation in Bandung. It’s almost a year since i’ve started internship in this company.

I’ve been troubled by many problems since i’m working in here and i’ve got through many difficult problem and try to solve the problem by myself, but there were problems that i couldn’t solve them myself. I’ve tried to find the solution on the internet, and it works. In this blog, i just want to tell you about some of the problems and┬áprogramming tips that i’ve been through for almost a year of internship program, most specifically about Input Without Form & PHP shortcut.

Input Without Form

The first one that i want to tell you is about submit an input tag without encapsulate the input tag in a form tag. Some people will think to encapsulate the input tag into form tag, but there’s another way to submit the input. I want to tell you a little secret to submit the input tag without encapsulate it to form tag. It’s so simple, you just add a javascript function into that input tag. You can add attribute onchange in your input tag. You can add some javascript function into onchange attribute.

In my case i want to submit a CSV file to my backend code, but i don’t want to use button to submit my file. Then after i chose the file and click ok, the file transfered into my backend code and i can get the file with $_POST syntax. In this case, i used the onchange attribute on my input type file. i added a javascript function into the onchange attribute. The function that i used in this attribute is this.form.submit(). This function forced you to submit the file right after you click ok. Then in the backend code, you can get the file with $_POST. It’s easier than create a form then fill the action. The other solution if you still want to use form tag is with AJAX. You can pass the file with AJAX. In the backend you can get the file too. Less works than use the form tag.

PHP shortcut

The second one that i want to share with you guys is to write file into csv file and move it into specific folder in the server. The first method that i used to do that was using move_uploaded_file() to move the file into specific folder. In this method i’ve to input the array file manually into thec CSV file. It will waste your time to create the code to manually input the array file into CSV file. After that problem was done, then i got the same problem as well. I need to move the CSV file and input the array file into CSV file. But this time i tried to find another solution. Then i found fputcsv() php function.

After read the documentation and tried to apply the function in my code. Then i realized the fputcsv() code not waste your time to create the code to manually input the array file into the CSV file, and fortunately you can use fputcsv() to move your file into the specific folder in the server. You can use this php shortcut if you want to create a file and post it in the server. This way is easier than move_uploaded_file(). If you use move_uploaded_file() method, you should get the file name and the other atribute.

That’s all about what i can tell you guys right now. Working with the team to solve the problem is fun. Arguing with each other is fun. Learn about this problem is new to me and my team at the internship program. If we find another problem and we got the best way to solve it, we’ll share it to you guys. I hope this programming tips will help you in the future. See you in the other blog of mine.


If you are interested, please feel free to check what is internship personnel doing in our blog post.