Help with info on script for a form - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HotUKDeals, you accept our cookie and privacy policy.
Get the HotUKDeals app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

Help with info on script for a form

£0.00 @
I am doing a website for a friend for their business & they have asked me to include a form on one of the pages to send information to them. I can design the website but I know nothing about forms,… Read More
lyzzys321 Avatar
7y, 6m agoPosted 7 years, 6 months ago
I am doing a website for a friend for their business & they have asked me to include a form on one of the pages to send information to them.

I can design the website but I know nothing about forms, I've looked at cgi , asp & form input and I have now done the form in the webpage but I need to know the script command to send the info through via the server, can anyone give me an idiots guide as I've seen so many form input commands I don't know which is the right one to use!

eg


lyzzys321 Avatar
7y, 6m agoPosted 7 years, 6 months ago
Options

All Comments

(20) Jump to unreadPost a comment
Comments/page:
#1
it depends on their server what type it supports. most hosts provide a cgi script to handle this sort of thing
#2
wolf359
it depends on their server what type it supports. most hosts provide a cgi script to handle this sort of thing


there is a cgi-bin folder on the server but there is only one file called test.cgi

What command do I put in the actual form though if I use the cgi-bin
#3
Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?
#4
gRoberts12
Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?


it's is going to collect information on name, address, tel, etc & then there is a selection list that gives info on what courses are available & I've set that section as radio buttons so 1 or more can be selected as required. This information then needs to get to the business owner which ever way is easiest.
1 Like #5
gRoberts12
Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?


this is what I did and it worked

put a form in your webpage as below:


Fields marked (*) are required


Email:*



Name:



Tel:



Enquiry:








When the user clicks submit this goes to contact.php so you also need to upload a file called contact.php as below


$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "[email protected]";
$Subject = "Website Enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Enquiry = Trim(stripslashes($_POST['Enquiry']));

$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "";
exit;
}

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "EmailFrom: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";

// sends email
$success = mail($EmailTo, $Subject, $Body, "From: < $EmailFrom>");

if ($success){
print "";
}
else{
print "";
}
?>

I also have a page called error.htm which will redirect if there is a problem and a ok.htm which redirects to once the form has been submitted ok
#6
dave_lunt2
this is what I did and it worked

put a form in your webpage as below:


Fields marked (*) are required


Email:*



Name:



Tel:



Enquiry:








When the user clicks submit this goes to contact.php so you also need to upload a file called contact.php as below


$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "[email protected]";
$Subject = "Website Enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Enquiry = Trim(stripslashes($_POST['Enquiry']));

$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "";
exit;
}

$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "EmailFrom: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Enquiry: ";
$Body .= $Enquiry;
$Body .= "\n";

// sends email
$success = mail($EmailTo, $Subject, $Body, "From: < $EmailFrom>");

if ($success){
print "";
}
else{
print "";
}
?>

I also have a page called error.htm which will redirect if there is a problem and a ok.htm which redirects to once the form has been submitted ok


Does this work with radio buttons or just text fields? There is about 18 different courses they offer & the user needs to select which ones they want more information on so the business knows which ones they are interetsed in.
#7
Not sure I'll try and see if it will for you
#8
Can they only select one course or multiple courses?
#9
dave_lunt2
Not sure I'll try and see if it will for you


thank you so much for this, I've spent hours this afternoon looking at this
#10
When you create form the beggining in HTML looks something like this...


The action bit, in this case someaction.php has to be an actual PHP file which you code to handle what to do when the form data is submitted.

For a complete newbie to all this, I'd either recommend checking out the tutorials on W3Schools
Otherwise I'd recommend paying someone to do a proper job of it - should cost no more than £20

If you're lucky you'll also get someone willing to do it for a bit of rep on here.
#11
dave_lunt2
Can they only select one course or multiple courses?


they can select whatever they require so could be 1 or could be all 18 or anything in between!
#12
MrBrightside1987
When you create form the beggining in HTML looks something like this...


The action bit, in this case someaction.php has to be an actual PHP file which you code to handle what to do when the form data is submitted.

For a complete newbie to all this, I'd either recommend checking out the tutorials on W3Schools
Otherwise I'd recommend paying someone to do a proper job of it - should cost no more than £20

If you're lucky you'll also get someone willing to do it for a bit of rep on here.


Thanks for that, I've been looking at that website but not at the php stuff, I was looking at asp & html form tags.

I'm doing the website free of charge as it's my neighbours business, she said if I couldn't sort it out then she would just have an email link requesting the user to email her, just thought it would be better if I could get it set up for her to help her out.
#13
Okay you'll be better off with check boxes as this allows the user to select multiple courses, a radio button is for one or the other usually like male or female

set up a form like by copying and pasting this into your webpage



Name:




E-Mail:





Geography

Maths

English



Message:









Then set up a new page and paste the following (edit field to with your own email address) and save the page as contact.php

if(isset($_POST['submit'])) {


$to = "[email protected]";
$subject = "Enquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

foreach($_POST['check'] as $value) {

$check_msg .= "Checked: $value\n";

}

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);


} else {

echo "blarg!";

}
?>


Upload both files to your server and give it a test, then you can add remove fields etc, just get it so it is working first
#14
dave_lunt2
Okay you'll be better off with check boxes as this allows the user to select multiple courses, a radio button is for one or the other usually like male or female

set up a form like by copying and pasting this into your webpage



Then set up a new page and paste the following (edit field to with your own email address) and save the page as contact.php



Upload both files to your server and give it a test, then you can add remove fields etc, just get it so it is working first


Just copied & pasted the 1st part into the body of a blank page & changed the email address, also saved the contacts.php & when I submit I am getting this message

Data has been submitted to ****@********.com! PHP Notice: Undefined variable: check_msg in D:\websites\**********\www\contact.php on line 13 PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in D:\websites\***********\www\contact.php on line 20

what does that mean? obviously something to do with the contact.php but I'm not sure what.

I still haven't received the email yet either

EDIT just re-read you post again! I forgot to change the "to" part in the contact.php :roll: just off to do that now

2nd EDIT I did actually change the top part to my email address where it shows as

if(isset($_POST['submit'])) {


$to = "[email protected]";


should I have changed anything else or just that part?
#15
lyzzys321
Just copied & pasted the 1st part into the body of a blank page & changed the email address, also saved the contacts.php & when I submit I am getting this message

Data has been submitted to ****@********.com! PHP Notice: Undefined variable: check_msg in D:\websites\**********\www\contact.php on line 13 PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in D:\websites\***********\www\contact.php on line 20

what does that mean?

on line 13 I have:- E-Mail: & line 20 is:-

I still haven't received the email yet either


have you actually uploaded it to a server or are you trying it from your PC

you need to upload these files to your website then go to the actual page for example

--www.mysite.com/contactuspage.html--

also the html page is telling it to submit to contact.php not contacts.php as you have put above, just in case that is it
#16
dave_lunt2
have you actually uploaded it to a server or are you trying it from your PC

you need to upload these files to your website then go to the actual page for example

--www.mysite.com/contactuspage.html--

also the html page is telling it to submit to contact.php not contacts.php as you have put above, just in case that is it


yep I uploaded them to the server & I did save as contact.php not contacts.php
#17
above code worked fine for me. i haven't had a test email from it yet but thats nothing new for my email :)

did you actually load the form from the server and not locally? you not only need to upload them but you can't test them locally either
#18
wolf359
above code worked fine for me. i haven't had a test email from it yet but thats nothing new for my email :)

did you actually load the form from the server and not locally? you not only need to upload them but you can't test them locally either


I did upload it to the server, I will try doing the two files again, it must be something I did if it works for you.

Just to carify the only thing I need to change is the email address near the top within the contact.php
#19
i'm not doubting you uploaded it but did you actually run it from the server? as in going onto the net and entering the url for its location on the server.

i still haven't rec'd the test maili sent so its possible the script isn't fully functional or more likely my crappy email :)
#20
wolf359
i'm not doubting you uploaded it but did you actually run it from the server? as in going onto the net and entering the url for its location on the server.

i still haven't rec'd the test maili sent so its possible the script isn't fully functional or more likely my crappy email :)


Fairly sure I did, not had much chance to do anything since I last logged on as been I've out, will have another look at it now, thanks for your help

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!