Jump to content

I am looking for a checkbox (yes/no) orientated PHP script


Danosaur

Recommended Posts

My main objective is to have a list of words for a user to check via checkbox through an html code; I would like for those checked or unchecked words to be saved to a text file, spread sheet, or any document on my server.  Even better would be for said information to be compiled in a paragraph separated by commas. I have been looking for upload scripts and trying to modify guestbook scripts-but I am just a newb...

 

I would appreciate any help or suggestions!

Link to comment
Share on other sites

and now for a much more useful answer:

 

This is one way to create a comma seperated paragraph in a text file.

<html><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="checkbox" name="food">food<br>
<input type="checkbox" name="boxes">boxes<br>
<input type="checkbox" name="computers">computers<br>
<input type="checkbox" name="racecars">racecars<br>
<input type="submit" value="generate file">
</form>
</html>

<?php
//only proceed if the form has been submitted
if(!$_POST)exit();

//file creation

// *******in order for this to work, chmod current directory to 777
//I ended up having to chmod this php file and the name.txt file to 777, not sure
//if that was entirely necessary.

foreach($_POST as $key => $val){
  if($data){$data .= ', ';}
  $data .= $key;
}

$ourFileName = "name.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $data);
fclose($ourFileHandle);
?>

Link to comment
Share on other sites

chmod is how you change file/directory permissions.

 

you can change it either through your FTP client or in a terminal/shell if you have access to the server.

 

google chmod.

 

In filezilla (my ftp client) I would select the directory on the server, right-click it, and select 'file attributes'. 777 is full access, that allows the php script to be able to create/overwrite files in the same directory. 

Link to comment
Share on other sites

and now for a much more useful answer:

 

This is one way to create a comma seperated paragraph in a text file.

<html><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="checkbox" name="food">food<br>
<input type="checkbox" name="boxes">boxes<br>
<input type="checkbox" name="computers">computers<br>
<input type="checkbox" name="racecars">racecars<br>
<input type="submit" value="generate file">
</form>
</html>

<?php
//only proceed if the form has been submitted
if(!$_POST)exit();

//file creation

// *******in order for this to work, chmod current directory to 777
//I ended up having to chmod this php file and the name.txt file to 777, not sure
//if that was entirely necessary.

foreach($_POST as $key => $val){
  if($data){$data .= ', ';}
  $data .= $key;
}

$ourFileName = "name.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $data);
fclose($ourFileHandle);
?>

 

wow! huge help so far!

 

Just some final tweaking...what line of code could I have a user input text field to be uploaded into name.txt... instead of the typical '<input type="text" name="">'? And, is it possible to create a different file on submit, or possibly have the submissions logged in the same file?

 

Thanks for the help so far

Link to comment
Share on other sites

wow! huge help so far!

 

Just some final tweaking...what line of code could I have a user input text field to be uploaded into name.txt... instead of the typical '<input type="text" name="">'?

 

I'm not sure if I understand your question, why would you need to do it differently?

 

And, is it possible to create a different file on submit, or possibly have the submissions logged in the same file?

 

Absolutely, if you program the script to generate a unique filename (like using the current timestamp as the filename).

 

As for logging all submissions in one file, yeah you could routinely append one text file, but at that point I would say just use a database.

Link to comment
Share on other sites

wow! huge help so far!

 

Just some final tweaking...what line of code could I have a user input text field to be uploaded into name.txt... instead of the typical '<input type="text" name="">'?

 

I'm not sure if I understand your question, why would you need to do it differently?

 

And, is it possible to create a different file on submit, or possibly have the submissions logged in the same file?

 

Absolutely, if you program the script to generate a unique filename (like using the current timestamp as the filename).

 

As for logging all submissions in one file, yeah you could routinely append one text file, but at that point I would say just use a database.

 

I am pretty much completely new to php, just so you guys understand where I am coming from. Your first quote: I would eventually like to have a custom text field in junction with the  checkboxes to show up in 1 file-and I am pretty lost on how to do so.

 

Your second quote: I've searched on google, been working on this project for about a week now (laugh if you must)...and I am pretty stuck. I think this is more then I can chew, but regardless, it needs to be finished. What is the best way to finish this project and get a decent understanding with PHP?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.