Author Topic: HTML help?  (Read 2330 times)

Offline luisc99 (OP)

  • Staff Member | Administrator
  • Cheese
  • *****
  • Posts: 1438
  • Llamas: 60
    • View profile
HTML help?
« on: 28 October 2013, 12:49:14 PM »
Hey!

This is a question to those of you (if any) who know HTML reasonably well. I've tried this myself, but HTML and java are total opposites and I was ver confused, and spent a long time producing useless code. What I'm trying to acheive is havning a webpage where users can fill in a form, and the results of that form would be added in a new line of a currently existing .txt file I have in my website. Let me explain.

The user has three options, although they will only be allowed to use two of them. One will be required, and that is a simple text box. The other two will also be required, but only one of them can be filled in. I thought this may be possible with a radio button. One of these options will be a simple drop down menu, while the other will be a text box. I then want the results to be saved in a new line in the text file.  Let me show an example:



Method 1:
The user fills in the text box with "name" and selects "green" from the drop-down menu. In the text file, I want name:www.luisc99.tk/green.png to be added onto the end.

Method 2:
If the user selects the second option, they will still have to fill out the value of "name" but instead of a drop-down, they will fill in their own text such as "www.google.com/test.png" and on the end of the text file, I want name:www.google.com/test.png

An example of how I want the file layed out is here.



Or an image example:




The problem is, I have no idea how this could be acheived. The file layout must not change, as my mod requires that format in order to be able to read and understand it. It must also put the data collected from the form onto a new line. If anyone out there with knowladge of how I could do this would be kind enough to help me, or even provide code examples, I would be greatly appreciative. Otherwise, shhh :P

Thanks,
Luis







If it's possible, it would also be nice for a user to be able to fill in the form twice with the same name in the first box, and rather than it add another line to the file if it replaced the already existing one. That would be cool to avoid confilcts :P
« Last Edit: 28 October 2013, 01:06:24 PM by luisc99 »

Offline Noket

  • Member of Parliament
  • Cheese
  • *
  • Posts: 325
  • Llamas: 20
    • View profile
Re: HTML help?
« Reply #1 on: 28 October 2013, 02:40:59 PM »
I have pretty good knowledge of HTML, Javascript, and PHP. I'm very strong in HTML and Javascript. Weaker in HTML.

What you're asking for requires a medley of all three. You'll need server communication via PHP (or python), Javascript to handle the logic, and HTML to call the javascript function when a user hits the submit button. The javascript would execute the correct PHP code in the end.

Offline luisc99 (OP)

  • Staff Member | Administrator
  • Cheese
  • *****
  • Posts: 1438
  • Llamas: 60
    • View profile
Re: HTML help?
« Reply #2 on: 28 October 2013, 02:42:54 PM »
I have pretty good knowledge of HTML, Javascript, and PHP. I'm very strong in HTML and Javascript. Weaker in HTML.

What you're asking for requires a medley of all three. You'll need server communication via PHP (or python), Javascript to handle the logic, and HTML to call the javascript function when a user hits the submit button. The javascript would execute the correct PHP code in the end.

Hm, that makes it sound even more complicated than I originally thought. Any idea how I could do this?

Offline Noket

  • Member of Parliament
  • Cheese
  • *
  • Posts: 325
  • Llamas: 20
    • View profile
Re: HTML help?
« Reply #3 on: 28 October 2013, 03:58:53 PM »
writing the code presently :p

Offline Noket

  • Member of Parliament
  • Cheese
  • *
  • Posts: 325
  • Llamas: 20
    • View profile
Re: HTML help?
« Reply #4 on: 28 October 2013, 07:03:46 PM »
Some of the code is broken .. this is all I can do tonight, but I hope it gives you a starting point. The logic might be wrong, but I think I constructed each of the for() loops correctly. Chrome is telling me that verify() isn't being called, and I'm not sure why .. anyway. Hope this helps a bit.

Code: [Select]
<html>
<head>
<title>Luisc99 Thing</title>
<script type="text/javascript">
function verify(){
var user = document.getElementsByName("user");
var png = document.getElementsByName("png");
var drop = document.getElementById("drop");
var logicReturn;
if(png.length()>0){

var pngLength = png.length();
var pngArray = new Array();
/* Builds the pngChars array */
for(i=0,i<pngLength-1,i++){
/* Array point [0] is assigned the first letter */
pngArray[i] = png.charAt(i+1);
}
/* Finds an ending filetype based on the url entered, starting from the end */
var indexOf;
for(i=pngLength-1,i!=0,i--){
/* Searches for the symbol ".", starting at the end, assigns a number for the location of
that variable in the array.*/
if(pngArray.indexOf(".") == i){
indexOf = i+1; /* String based value */
/* End the for loop */
i = 0;
}
else{
/* Continue the loop */
}
}
/* Uses indexOf to build the ending filetype */
var deltaPng = pngLenth-indexOf+1; /* String based value, location of period */
var filetypeArray = new Array(pngArray.slice(deltaPng));
var filetypeString = filetypeArray.toString();
if(filetypeArray == ".png"){
logicReturn = user+png;
alert(logicReturn);
}
else{
alert("That's not a valid .png!\n"+filetypeArray);
}
}
else{
logicReturn = user+":www.luisc99.tk/files/archive/capes/vcmod/reg"+drop+".png";
}
}
</script>

</head>
<body>

Username: </br>

<input name="user" type="text" style="width:500px;"/> </br>
Define your own image (Must be a direct link and in .png format): </br>
<input name="png" type="text" style="width:500px;"/> </br>
<button onclick="verify()">Submit</button>

</body>
</html>