Jump to content
absorr

Submitting To Submit

Recommended Posts

I want to make it so that when you hit the submit button, the text in the text box is added onto a separate html document. Don't explain how, just give me a code example and some basics on it.

Share this post


Link to post
Share on other sites

Don't explain how? When it comes to web development (or anything that requires some learning), you have two choices: hire somebody to do it or learn it yourself. This task you want will require a server-side language. PHP is the language of my choice, but it depends on what you need. First, you need to learn how to use forms and the $_POST array. This will help you get the data to the script that will modify the other HTML document. You can use file_put_contents() to change the file. While that solution fits the requirements you posted, I'm guessing you actually want to choose where in the HTML document you want the new content to be placed. That task is a lot more difficult; you would want to build a content management system and that required working with databases.

Share this post


Link to post
Share on other sites

By don't explain I meant don't give me an essay. I did say I would like some basics. And yes, I am mainly aiming for the code, but that does not mean I don't want anything else. And also I'm not aiming to place it in a certain place in the document. I'm puting it in a separate place so i can use an iframe to get the code in. That's just some things I wanted to clarify. Thanks Duotone Fox for your great answer.

Share this post


Link to post
Share on other sites

Ok, now that I have it so that it submits things in a forum to a txt via php, how do I make it so that when it puts things in the txt it doesn't replace whats already there? Reply to this in any way, sorry if my restrictions above were annoying.The code for the PHP is <?php$a_str = array($_POST["fname"],$_POST["age"]);$contents = implode(PHP_EOL, $a_str);$contents .= PHP_EOL . PHP_EOL;file_put_contents("testtxt.txt", $contents);print("|$contents|");?>if that helps you

Edited by absorr

Share this post


Link to post
Share on other sites

If you just want to append the new data to the beginning or the end of the file, you can use file_get_contents to read the contents first. Then when you put the contents, just concatenate the new data with the old data.

Share this post


Link to post
Share on other sites

file_put_contents has parameters you can use so it appends to the existing file.http://es.php.net/file_put_contents Example:

file_put_contents('file.txt', 'Data', FILE_APPEND);

Share this post


Link to post
Share on other sites
file_put_contents has parameters you can use so it appends to the existing file.http://es.php.net/file_put_contents Example:
file_put_contents('file.txt', 'Data', FILE_APPEND);

THANK YOU THANK YOU THANK YOU! That worked perfectly! Funny story, I asked my Web Design teacher about this and he said he barely knew anything about PHP so he gave me 2 huge books to look through.

Share this post


Link to post
Share on other sites

That's because web design is only a small branch of the field of web development.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...