# Solved: Form



## rammyboy (Sep 26, 2005)

A while back sequal7 helped me to modify a template and understand HTML. With this new found knowledge i always wanted to make my own website and use a self developed model.

I have done this to the best of my ability and as far as i can see i have got everything to work apart from the form on the "products" page of the website.
I managed to get the form to open via javascript and i have created the confirmation pae

The addresses are www.iansprint.co.uk/form.html and www.iansprint.co.uk/confirmation.html

I read on a website that because i had been creating individual pages rather than a website in frontpage i cannot publish directly through frontpage and therefore a form like this cannot work. I read into the cgiemail way of doing it but could not understand this.

How could i get the form to work and send the results in an email to a designated email address?

Many Thanks in advance!

Alex


----------



## Xperience (Feb 13, 2007)

You can use PHP to do this. See attachment.


----------



## rammyboy (Sep 26, 2005)

Xperience said:


> You can use PHP to do this. See attachment.


Hi,

How do i use these PHP scripts?

I have no idea on how to use them?

Any help appreciated?

Alex


----------



## MMJ (Oct 15, 2006)

index.php

```
Your Name: 
Your Email:  

Your Message:
```
mailer.php

```
<?PHP 
// Edit the following:
$to = "[email protected]"; //your email address
$subject = "Feedback"; //Subject
$headers = "From: ". preg_replace('/[\r\n\t\s:]/', null, $_POST['email']); //Email of sender, will be set automatically
$forward = 1; //Do you want the page to redirect if the 
$location = "thankyou.php"; #set page to redirect to, if 1 is above

/***************NO NEED TO EDIT BELOW*******************/

$date = date ("l, F jS, Y"); 
$time = date ("h:i A");

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
	$body  = "You have recieved an email from your php form on $date at $time.\n
"; 
	$body .= 'Name: '. $_POST['name'] ."\r\n";
	$body .= htmlentities(strip_tags($_POST['message']));
	@mail($to, $subject, $body, $headers);

	if ($forward == 1)
		header ("Location: $location"); 
	else
		echo "Thank you for submitting our form. We will get back to you as soon as possible.";
}
?>
```


----------



## rammyboy (Sep 26, 2005)

Sorry, i may be acting like a complete noob but i have no clue what to do with the code you have supplied me with?

How do i put this into practice?

Alex


----------



## MMJ (Oct 15, 2006)

Put each part of code in the filename I posted, upload it into your site.


----------



## rammyboy (Sep 26, 2005)

Right i have uploaded the two files that i think i have modified correctly.

The two files are here if you can check them? I made them with notepad but i dont know if this was the correct thing to do?
http://www.megaupload.com/?d=LS7CTIV0


----------



## MMJ (Oct 15, 2006)

You uploaded them to a website that has php support, right?


----------



## rammyboy (Sep 26, 2005)

Yep i uploaded them but as soon as i had the index page dissapaeared and when going to the main page by typing in the domain name, i just got that simple feedback form rather than my home page?

What do i do next?


----------



## rammyboy (Sep 26, 2005)

This is starting to seem like an unachievable task to me!

Lets start again!

I want to create a form with all of the fields on "www.iansprint.co.uk/form.htm". 

The user should be able to input all the data they want to input into the seperate fields and then when they click submit, i want the information to be emailed through to my email address so that it looks like this for example.

The field was "Contact Name"

The user typed in "John Smith"

I want it to be emailed to my email account in this format, Contact Name - John Smith

And so on

Is this possible? And could anyone give me an idiots guide on how to do it?

Thanks for all of your help.

Alex


----------



## Sequal7 (Apr 15, 2001)

Hey Alex, I personal messaged you back about your form, but lets have a look at this objectively and simply.

I want you to download the form in this zipped file, and unzip to your computer. Once it is unzipped you will see a mailtest.php file, upload that to your server. Once it is uploaded, call the form by going to http://www.iansprint.co.uk/mailtest.php
Check your email, you should get an email at your sales email address, and the page should say:


> Mail Sent Successfully Alex, You can use a PHP mail form.


This will tell you if you can send php email based forms.
If you can, then I would suggest you use a php mail form, they are far less messy than cgi forms, and allot easier to customize too.

Let me know what happens...I can help you create a webform using php like the one you want.


----------



## rammyboy (Sep 26, 2005)

Sequal7,

The mail worked! I just received it so if you could assist me in creating a PHP form I would be extremely grateful! Can we make it look like the form I have created at www.iansprint.co.uk/form.htm?

Thanks

Alex


----------



## Sequal7 (Apr 15, 2001)

That is good Alex, delete that file from your server now, you dont *need or want it* there anymore!

Tell me, what fields are *required* to send the form? (example, if they don't fill in a field it will return an error, please fill in the ___field to submit and others can be left blank or do they all have to filled out?)


----------



## rammyboy (Sep 26, 2005)

Hi Sequal,

Thanks for taking a look.

The fields we require and need to be filled in are:

Contact Name, Telephone Number, Job Description, Quantity, Finished Size and i think thats it, but! (why is there always a but?!) we still want the other fields on the form to help us more than anything!

Thanks for the help!

Alex


----------



## Sequal7 (Apr 15, 2001)

Ok Alex, here is the  finished form and its submission page, upload them both to your server and try them out. Make sure they are both in the same directory or change the include on the form.php page at the top to the correct directory where you put the inc file.

You can test it here;

*You will notice; *that they are .php files, so any links from other pages to your form.htm will need to be changed to this form.
If your not sure how to, let me know and I can help you.


----------



## rammyboy (Sep 26, 2005)

Hi Sequal,

Trying to edit it to make it look like how it did (not saying you havent done a brilliant job!!!) but what should i edit it in?

I have done it in frontpage and i think i broke it.

What i need to do for the time being is change it to send mail to my personal address for testing and also edit the fonts and the likes to make it look the same?

Hope this isnt to much to ask?

Thanks

Alex


----------



## rammyboy (Sep 26, 2005)

Also how do i edit that submision page?

Thanks
Alex


----------



## rammyboy (Sep 26, 2005)

I get this error on the file i have uploaded


Parse error: syntax error, unexpected '=' in /home/iansprin/public_html/form.php on line 288


----------



## rammyboy (Sep 26, 2005)

Ignore all of that!

I downloaded the error log's, realised i was messing with a proven item, went back to the originals and started tinkering again.

I have now edidted the actual form and that is exactly to me liking.

The products page now opens the new form and the form will send things through to our sales address! And yes Sequal7 you are a genius! You are worth your weight in gold! 

Now one last thing....How can i edit the submmission page? 

All i want that page to be able to do is say

"Success....blah blah blah"

And there to be a close button that shuts down the screen as it comes from a pop up?

If you can sort these then yes, i could kiss you!!
Thanks everyone!

Alex


----------



## Sequal7 (Apr 15, 2001)

With all that praise, I am almost afraid to say yes, but *yes, all that can all be done*.

You don't need to edit the submission (.lib.php) page, you just edit the form.php page. The only thing you would edit on the submission page is the email address the form sends to. This is defined by the *$to* near the top of the submission lib.php page.

```
// ===============================================
function    sendFormMail( $form_mail, $sFileName = ""  ) 
{ 
    global    $HTTP_POST_VARS ; 
	$to = "[email protected]"; // Change to your email address
	$from = "[email protected]" . HOST_NAME ; //change to who the form comes from if no senders email included!
```
Now, to change your response and add a close button;

Look for this in the form.php html view .

Change

```
<?php
		if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;; 

else: //!$isHideForm
	print( "<br><br><hr><center><b>Your form has been sent. Thank you.</b><br><br><input type='button' value='Home' onclick=\"location.href='/';\"></center><br><br>" );
endif; //!$isHideForm
?>
```
 to

```
<?php
		if( $sErr ) print "<script language='javascript' type='text/javascript'>location.href='#error';</script>";;; 

else: //!$isHideForm
	print( "<br><br><hr><center><b>Your form has been sent. Thank you.</b><br><br><form><input type='button' value='Close window' onclick='javascript:window.close();'></form></center><br><br>" );
endif; //!$isHideForm
?>
```
Then change the text "Your form has been sent. Thank you." to what ever you want printed on the page after the form is sent, that is in the area you just replaced.


----------



## finwood (May 10, 2004)

I use Response-O-Matic. You can design your form with Frontpage, and use 3 lines of code from Response-O-Matic, and they will e-mail you the results. It is free for 1 form per e-mail address. Really simple, with great results.


----------



## rammyboy (Sep 26, 2005)

With people as clever and helpful as sequal around, why rely on another company to email you your own results? This works perefectly touch wood and is instant!


----------



## Sequal7 (Apr 15, 2001)

Did your changes work?

If you are happy with your form please mark this thread a solved.


----------



## finwood (May 10, 2004)

rammyboy,

Yes, there are many clever, helpful, and patient people on this forum willing to write php scripts for someone, and teach them how to use them. However, there are people who need a form sent without all of the hassle. I get my rental applications as soon as they are submitted. And, it took only 10 minutes to set it up. Plus....I have been using Response-O-Matic for several years. It is free and very reliable.


----------



## rammyboy (Sep 26, 2005)

Yes thanks sequal!

The last thing to make it perfect is:

How do i change the submision bit to have white, arial font?

And then the masterpiece will be finished!

Thanks

Alex


----------



## Sequal7 (Apr 15, 2001)

You can add the text attributes to either the style tag at the beginning part of your page or as a style in your css sheet or right in the code itself.

To add to your webpage *in either CSS of as a style tag* add this;

```
.subtext {
font-family: Arial ;
font-color: #FFFFFF ;
}
```
then in the line that displays the submission message add to the text line by doing this;

```
<span class="subtext"><br><br><hr><center><b>Your submission text here.</b><br><br></span>
```
*OR* to add directly to the line that displays with *no* css do this;

```
<br><br><hr><center><font face='arial' color='#FFFFFF' weight='bold'>Your submission text here.</font><br><br>
```
Heres a sample on some css you can utilize, its easier to implement.
http://www.htmlcodetutorial.com/character_famsupp_212.html


----------

