Html5 submit form button-send input to file? -
i have multi-page website, i'm still new programming have learned quite bit of html , css. question is:
how can have submit form button take users input-data, , send .txt file on computer while offline?
this can test form , sure can send input data. form model application , includes text boxes, radio buttons, select lists, passwords, emails etc...
and moment not need salt-hashing or security, off-line form testing, thanks!
edit: have submit button set in, not send input data anywhere
if offline, there no way computer receive data.
however, if web site on web server out on internet, data can saved text file on server, access later.
the form needs action tag, tells form data should sent processing. has few important tags within well:
<form method="post" action="http://www.yoursite.com/script-to-process-submission.php"> one: <input type='text' name='inputbox1'/> two: <input type='text' name='inputbox2'/> </form>
you place input boxes within form tags. method can "get" or "post" way in data sent. method means responses input boxes sent in url, separated ampersands, this:
http://www.yoursite.com/script-to-process-submission.php?inputbox1=what+the+user+entered&inputbox2=also+what+the+user+entered
the issue here long form may not have data submitted-- servers limit length of input can sent way. longer form better "post" method.
once form submitted, , data has been sent server, need script set in server-side language perl or php. here example in php:
<?php $response = ""; foreach ($_post $key => $value){ $response .= $key . " -> " . $value . "\n"; } // save disk in file called saved_response.txt // file_append adds form responses text file, , lock_ex locks file first file_put_contents('saved_response.txt',$response,file_append | lock_ex); exit;
if preferred method, change $_post above $_get.
important note: there no cleaning involved in above code, , malicious user send bad data server, , cause harm. should consider sort of cleaning of text submitted, such as:
$clean_value = preg_replace("/[^ 0-9a-za-z]/", "_", $value);
you put right before $response.= line above. it's role keep numbers, , lowercase/uppercase letters.
save php code plain text file 'script-to-process-submission.php', , try form.
Comments
Post a Comment