LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to design interactive contact form for web page? (https://www.linuxquestions.org/questions/linux-general-1/how-to-design-interactive-contact-form-for-web-page-582001/)

bezdomny 09-03-2007 10:41 PM

how to design interactive contact form for web page?
 
I am the new webmaster for a non-profit and would like to use Iceape Composer and Bluefish for my work as they are free-of-charge (and Iceape composer will be a great help because of its wysiwyg interface-- my HTML coding skills are quite out-ot-date).

I would like to have a contact form where clients could input their names, and phone numbers and e-mail addresses and the form would either e-mail that to the webmaster, or post it to a file on the server the webmaster could regularly check.

If you can help me do this, perhaps help me script a template, or tell me what back-end services would be required to be supported on my server (PHP? ASP?) please help me. Thank you!

Nailbar 09-04-2007 12:09 AM

To save form data to a file is pretty simple. I'd use PHP, but that's just what I'm used to.

Here's a small example script to help you on your way.

The script you post to:

Code:

<?php

//Check that the user actually sent data
if(!isset($_POST['data1'])) exit('Variable data1 missing!');
if(!isset($_POST['data2'])) exit('Variable data2 missing!');

//Get the stuff posted
$data1=$_POST['data1'];
$data2=$_POST['data2'];

//Save it to the file
if($fh=fopen('thefile.txt','a')){ //Open file for writing
  fwrite($fh,$data1."\n"); //Write first data string to file
  fwrite($fh,$data2."\n\n"); //Write second data string
  fclose($fh); //Close the file
}else exit('Could not save form data!'); //If the file could not be opened

//Tell the user it's all good
echo "Thank you, your form has been recieved...";

?>

The file 'thefile.txt' must be writable by the server.

This is all without authentication so you should look into session variables or cookies too to avoid evil doings.

Read more on www.php.net

bezdomny 09-05-2007 10:26 AM

how to design interactive contact form for web page?
 
Thank you so much, Nailbar! And then I would write an HTML page using the "form" tag, and "post" method pointed to the php page, right? And the three files, the form-html page, the php file, and the underlying text.file would all be in the same directory, right?

Thanks again and best regards,

B3zdomny, aka The Poet Homeless

Nailbar 09-06-2007 10:03 AM

Yeah..

Here's a quick example for the form too, since you said you were out-of-date and all.

Code:

<form method="post" action="store.php">
  <p>
    Data 1: <input type="text" name="data1"/><br/>
    Data 2: <input type="text" name="data2"/><br/>
    <input type="submit" value="Send data"/>
  </p>
</form>

Enjoy your coding :)

And some recommended reading.. www.w3schools.com is where I learned all my web programming.


All times are GMT -5. The time now is 05:01 PM.