The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Re direct to a thank you page after submit button pressed
Ted
post Sep 4 2018, 05:23 AM
Post #1


Newbie
*

Group: Members
Posts: 10
Joined: 4-September 18
Member No.: 26,706



This is my first post and I have little experience with php scripts so I have created a web site with a form for a customer to enter their details. All works and I get an email with their details. The customer gets a plain page with a Thank you message. I want to change that to my custom thankyou.html page but with no success. I get this error on a plain page - Warning: Cannot modify header information - headers already sent by (output started at /var/sites/r/ringsjustforyou.co.uk/public_html/html_form_send.php:1) in /var/sites/r/ringsjustforyou.co.uk/public_html/html_form_send.php on line 80.
This is my html code for the form;-
<!-- Start of the form Code -->
<div id="sendform">
<form name="htmlform" method="post" action="html_form_send.php"><table width="450px">
<tr>
<td valign="middle"><label for="first_name">First Name *</label></td>
<td valign="top"><input type="text" name="first_name" maxlength="50" size="30" /></td>
</tr>
<tr>
<td valign="middle"><label for="last_name">Last Name *</label></td>
<td valign="top"><input type="text" name="last_name" maxlength="50" size="30" /></td>
</tr>
<tr>
<td valign="middle"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" name="email" maxlength="80" size="30" /></td>
</tr>
<tr>
<td valign="middle"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" name="telephone" maxlength="30" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Enquires *</label></td>
<td valign="top"><textarea name="comments" maxlength="1000" cols="25" rows="10"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><input type="submit" value="Submit" /><a href= "http://www.ringsjustforyou.co.uk/html_form.php"></a></td>
</tr>
</table>
</form>
</div>
<!-- End of the Form code -->

This is the code for the php file html_form_send.php;-
<?php
if(isset($_POST['email'])) {

// CHANGE THE TWO LINES BELOW
$email_to = "*@ringsjustforyou.co.uk";

$email_subject = "Custom Ring(s) Request";


function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- place your own success html below

Thank you for your enquiry. We will be in touch with you very soon. -->


<?php

header("Location: ./http://www.ringsjustforyou.co.uk/thankyou.php");

}
die();
?>

The line 80 in the error massage refers to this;-
Header ("Location: ./http://www.ringsjustforyou.co.uk/thankyou.php");
I have tried the thankyou page as .html and .php with the same error
I hope I have told you enough to help me

Thank you in advance

This post has been edited by Christian J: Sep 7 2018, 10:46 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Christian J
post Sep 6 2018, 05:49 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



No, I meant that http://www.ringsjustforyou.co.uk/thankyou.php resulted in a PHP error, so it can't be plain HTML like you posted. But let's wait with that file, since the redirection to it doesn't work in the first place.

Like I wrote in my previous post, when I go to http://www.ringsjustforyou.co.uk/html_form.php I get a 404 ("file not found") error, so where is the form page you're testing with located?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ted
post Sep 7 2018, 05:27 AM
Post #3


Newbie
*

Group: Members
Posts: 10
Joined: 4-September 18
Member No.: 26,706



QUOTE(Christian J @ Sep 6 2018, 05:49 PM) *

No, I meant that http://www.ringsjustforyou.co.uk/thankyou.php resulted in a PHP error, so it can't be plain HTML like you posted. But let's wait with that file, since the redirection to it doesn't work in the first place.

Like I wrote in my previous post, when I go to http://www.ringsjustforyou.co.uk/html_form.php I get a 404 ("file not found") error, so where is the form page you're testing with located?


I tried to attach a word docx file with screen shots of what I see here with comments to your questions but I could not do that as I think the file was too large so I have created a web page with the info.
This is the link
http://www.ringsjustforyou.co.uk/christian.html
I hope this works
Ted

This post has been edited by Ted: Sep 7 2018, 05:41 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 7 2018, 10:44 AM
Post #4


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(Ted @ Sep 7 2018, 12:27 PM) *

Img4a shows what looks like a tab/indentation/whitespace before the PHP start tag, something like this:

CODE
    <?php
if(isset ...

--maybe the redirect started working once you removed that?

QUOTE
I decided to rename the thankyou.php to thankyou.html. It works.

That might be because the server is configured to only run PHP on pages with .php extensions. If so maybe you still have invalid PHP code in the thankyou.html page, but the PHP is simply ignored by the server now. I'd remove any unwanted PHP code from the "thankyou" files just in case.

Glad that it worked finally! smile.gif

(BTW I've edited the email address in the previous posts so spambots won't find it.)
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ted
post Sep 7 2018, 04:42 PM
Post #5


Newbie
*

Group: Members
Posts: 10
Joined: 4-September 18
Member No.: 26,706



QUOTE(Christian J @ Sep 7 2018, 10:44 AM) *

QUOTE(Ted @ Sep 7 2018, 12:27 PM) *

Img4a shows what looks like a tab/indentation/whitespace before the PHP start tag, something like this:

CODE
    <?php
if(isset ...

--maybe the redirect started working once you removed that?

QUOTE
I decided to rename the thankyou.php to thankyou.html. It works.

That might be because the server is configured to only run PHP on pages with .php extensions. If so maybe you still have invalid PHP code in the thankyou.html page, but the PHP is simply ignored by the server now. I'd remove any unwanted PHP code from the "thankyou" files just in case.

Glad that it worked finally! smile.gif

(BTW I've edited the email address in the previous posts so spambots won't find it.)

I did not realise that the space before the <?php was whitespace. I thought whitespace was blank lines between lines. However the html_form_send.php file I created with notepad has no space. The <?php is as far to the left as it can go. So this is the reason the file starting working. You did ask about whitespace in an earlier post but I misunderstood. I have checked the thankyou.html and there is no php code in it.
Christian I cannot thank you enough. Also thank you for edited my e-mail address, I did not think about that.
Kind regards
Ted

This post has been edited by Ted: Sep 7 2018, 04:44 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
Ted   Re direct to a thank you page after submit button pressed   Sep 4 2018, 05:23 AM
Christian J   Headers must/should be the first thing that's ...   Sep 4 2018, 11:29 AM
Ted   Hello Christian J Sorry for the delay in replying....   Sep 5 2018, 06:07 AM
CharlesEF   I also suggest you not suppress mail errors. In o...   Sep 4 2018, 01:23 PM
CharlesEF   I meant for you to place the header command inside...   Sep 5 2018, 10:14 AM
Ted   Hello CharlesEF This is what I have done as you su...   Sep 5 2018, 12:13 PM
Christian J   if(mail($email_to, $email_subje...   Sep 5 2018, 01:00 PM
Ted   Hello Christian J I have removed the semicolon but...   Sep 5 2018, 05:12 PM
Christian J   Is there any content (even whitespace, tabs or lin...   Sep 5 2018, 07:20 PM
Ted   Is there any content (even whitespace, tabs or li...   Sep 6 2018, 01:34 AM
Christian J   Is there any content (even whitespace, tabs or li...   Sep 6 2018, 06:02 PM
CharlesEF   Can you post or attach the entire current version ...   Sep 5 2018, 07:54 PM
Ted   Can you post or attach the entire current version...   Sep 6 2018, 01:43 AM
Christian J   I tested the script, and it redirected to where I ...   Sep 6 2018, 05:27 AM
Ted   I tested the script, and it redirected to where I...   Sep 6 2018, 09:16 AM
Christian J   [quote name='Christian J' post='136156' date='Sep...   Sep 6 2018, 01:51 PM
Ted   [quote name='Ted' post='136158' date='Sep 6 2018,...   Sep 6 2018, 05:01 PM
Christian J   No, I meant that http://www.ringsjustforyou.co.uk/...   Sep 6 2018, 05:49 PM
Ted   No, I meant that [url=http://www.ringsjustforyou....   Sep 7 2018, 05:27 AM
Christian J   This is the link [url=http://www.ringsjustforyou....   Sep 7 2018, 10:44 AM
Ted   This is the link [url=http://www.ringsjustforyou...   Sep 7 2018, 04:42 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 25th April 2024 - 08:20 AM