I have placed my form fields into an html page in my website. Everything is working 100%. When a user fails to complete a required field in my form they're redirected to the error page, as per the process.php file.
Instead of redirecting them I would like to display the error message below the submit button on the same html page without it being refreshed. This will stop users from getting frustrated with having to re-do the form because they were redirected and their details were cleared.
I have inserted the following code into my html page:
<?php
if($errors==1)
echo $error;
?>
This is not working. How do I tell the process.php file to output the error message to my html page?
Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Pages are treated differently based on the file extension.
A file with the extension .html is not treated the same as a file with the extension .php and there for can not be used to execute PHP commands like the one you are trying to implement. There are many ways to solve your problem.
First I am surprised that the "back" button feature of the web browser does not return to the page with all the fields already populated. If this works it is your simplest solution. Just add a note to use the back button to return and modify the entries.
Any other option involves additional programming. You could consider using the new phpFormGenerator 3.0 which has Java code in the html to check the form prior to submitting to the process.php file.
You could consider making your form a .php file and then have the opportunity to insert the php code you are trying to implement. One word of caution though, it is not as simple as you have made it. There has to be an error generated before you can display a message that indicates an error. At the moment all your error detection is in the process.php file.
There are literally hundreds of other programming options to consider.
How would you like to proceed?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2008-05-24
Thanks for your reply. To answer your points...
- "First I am surprised that the "back" button feature of the web browser does not return to the page with all the fields already populated. If this works it is your simplest solution. Just add a note to use the back button to return and modify the entries."
-- I've been doing my design and testing in IE7 and it's not "remembering" the form contents when the back button is clicked. I've not tested this in Firefox but 90% of my users are using IE anyway. More importantly I still don't want my users to be presented with an error page which has no resemblance to my site or have to re-enter their data into my form. It doesn't give a good feeling or impression, which is critical, when I'm trying to gain sales leads from the data they enter.
- "Any other option involves additional programming. You could consider using the new phpFormGenerator 3.0 which has Java code in the html to check the form prior to submitting to the process.php file."
-- I don't think I've got much option in the version I use because I had to install phpFormGenerator through Fantastico in my domains CPanel. I'm using version v2.09.
- "You could consider making your form a .php file and then have the opportunity to insert the php code you are trying to implement. One word of caution though, it is not as simple as you have made it. There has to be an error generated before you can display a message that indicates an error. At the moment all your error detection is in the process.php file."
-- I know my way around html but I wouldn't know where to begin with trying to recreate my website's template in PHP. To me it seems that this option would be going the very long way around when simply trying to "echo" the error message in my html page.
So to answer your question "how would you like to proceed?", I'd like to find the simplest solution to display the error message on my html page as opposed to displaying on a separate one.
I know this is possible because it is being done on other pages within my site. However my web design company did a very messy job with the code so I've no way of simply modifying a form they've already created. Plus their forms are linked to my MySQL database. This is why I decided to keep things simply and install phpFormGenerator to simply capture potential client details. My solution works great except for the placement of the error message.
Any further ideas/thoughts would be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2008-05-26
I haven't had much time to look at this further but what I have thought of doing is the following...
Because the error message already opens in a new page I thought of opening it in a new window rather. This means that it will not navigate away from the html page with my form on it and lose the users info. It can then simply be closed and the user can correct the mistake and continue on my website.
So, is this a possibility, and if so, what would I need to add to the code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2008-05-26
I've managed to get a new window to open by using Javascript with the process.php file. My problem is that this new window is still opening from the original error page which the browser navigates to once the submit button is clicked on my form. Below is my process.php file:
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','CompanyName');
pt_register('POST','Name');
pt_register('POST','Surname');
pt_register('POST','Email');
pt_register('POST','Telephone');
pt_register('POST','PricingPackage');
if($Name=="" || $Surname=="" || $Email=="" || $Telephone=="" || $PricingPackage=="" ){
$errors=1;
}
if($errors=1)
{
print("<script language = 'javascript'>window.open('http://www.mydomain.com/error.html');</script>");
exit();
}
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Company Name: ".$CompanyName."
Name: ".$Name."
Surname: ".$Surname."
Email: ".$Email."
Telephone: ".$Telephone."
Pricing Package: ".$PricingPackage."
";
$message = stripslashes($message);
mail("info@mydomain.com","A potential client would like us to call them back",$message,"From: MyDomainCallBack");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $CompanyName."|".$Name."|".$Surname."|".$Email."|".$Telephone."|".$PricingPackage."
";
fwrite($make,$to_put);
I don't know php and can't see why the code is opening a new window to display the error message. I'd like the javascript to open the new window on top of my html form. So how can I stop the original error page from opening before my new window javascript is run?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not possible the way it is coded now. When you click the submit button the process.php file is loaded. This is what generates the error message.
Your choices are somewhat limited if you choose to stay with version 2.09. Using 3.0 is a valid option. You would not be able to instal version 3.0 as it is only available in a demo site but the form you generate would have code for checking values before submission. There would still be alot of work to integrate this into another page. If you would like I can take a copy of your html page and add the version 3.0 features for you.
The 3.0 version uses Java to check the form without leaving the form page. If all checks are OK then it submits to the process.php file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2008-05-27
Thanks for getting back to me. I appreciate your offer to add the features of version 3 to "pre-validate" my form before running the process.php file. I've included my HTML code below. If there is anything else you need please let me know.
Hi
I have placed my form fields into an html page in my website. Everything is working 100%. When a user fails to complete a required field in my form they're redirected to the error page, as per the process.php file.
Instead of redirecting them I would like to display the error message below the submit button on the same html page without it being refreshed. This will stop users from getting frustrated with having to re-do the form because they were redirected and their details were cleared.
I have inserted the following code into my html page:
<?php
if($errors==1)
echo $error;
?>
This is not working. How do I tell the process.php file to output the error message to my html page?
Thanks in advance.
Pages are treated differently based on the file extension.
A file with the extension .html is not treated the same as a file with the extension .php and there for can not be used to execute PHP commands like the one you are trying to implement. There are many ways to solve your problem.
First I am surprised that the "back" button feature of the web browser does not return to the page with all the fields already populated. If this works it is your simplest solution. Just add a note to use the back button to return and modify the entries.
Any other option involves additional programming. You could consider using the new phpFormGenerator 3.0 which has Java code in the html to check the form prior to submitting to the process.php file.
You could consider making your form a .php file and then have the opportunity to insert the php code you are trying to implement. One word of caution though, it is not as simple as you have made it. There has to be an error generated before you can display a message that indicates an error. At the moment all your error detection is in the process.php file.
There are literally hundreds of other programming options to consider.
How would you like to proceed?
Thanks for your reply. To answer your points...
- "First I am surprised that the "back" button feature of the web browser does not return to the page with all the fields already populated. If this works it is your simplest solution. Just add a note to use the back button to return and modify the entries."
-- I've been doing my design and testing in IE7 and it's not "remembering" the form contents when the back button is clicked. I've not tested this in Firefox but 90% of my users are using IE anyway. More importantly I still don't want my users to be presented with an error page which has no resemblance to my site or have to re-enter their data into my form. It doesn't give a good feeling or impression, which is critical, when I'm trying to gain sales leads from the data they enter.
- "Any other option involves additional programming. You could consider using the new phpFormGenerator 3.0 which has Java code in the html to check the form prior to submitting to the process.php file."
-- I don't think I've got much option in the version I use because I had to install phpFormGenerator through Fantastico in my domains CPanel. I'm using version v2.09.
- "You could consider making your form a .php file and then have the opportunity to insert the php code you are trying to implement. One word of caution though, it is not as simple as you have made it. There has to be an error generated before you can display a message that indicates an error. At the moment all your error detection is in the process.php file."
-- I know my way around html but I wouldn't know where to begin with trying to recreate my website's template in PHP. To me it seems that this option would be going the very long way around when simply trying to "echo" the error message in my html page.
So to answer your question "how would you like to proceed?", I'd like to find the simplest solution to display the error message on my html page as opposed to displaying on a separate one.
I know this is possible because it is being done on other pages within my site. However my web design company did a very messy job with the code so I've no way of simply modifying a form they've already created. Plus their forms are linked to my MySQL database. This is why I decided to keep things simply and install phpFormGenerator to simply capture potential client details. My solution works great except for the placement of the error message.
Any further ideas/thoughts would be appreciated.
I haven't had much time to look at this further but what I have thought of doing is the following...
Because the error message already opens in a new page I thought of opening it in a new window rather. This means that it will not navigate away from the html page with my form on it and lose the users info. It can then simply be closed and the user can correct the mistake and continue on my website.
So, is this a possibility, and if so, what would I need to add to the code?
I've managed to get a new window to open by using Javascript with the process.php file. My problem is that this new window is still opening from the original error page which the browser navigates to once the submit button is clicked on my form. Below is my process.php file:
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','CompanyName');
pt_register('POST','Name');
pt_register('POST','Surname');
pt_register('POST','Email');
pt_register('POST','Telephone');
pt_register('POST','PricingPackage');
if($Name=="" || $Surname=="" || $Email=="" || $Telephone=="" || $PricingPackage=="" ){
$errors=1;
}
if($errors=1)
{
print("<script language = 'javascript'>window.open('http://www.mydomain.com/error.html');</script>");
exit();
}
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Company Name: ".$CompanyName."
Name: ".$Name."
Surname: ".$Surname."
Email: ".$Email."
Telephone: ".$Telephone."
Pricing Package: ".$PricingPackage."
";
$message = stripslashes($message);
mail("info@mydomain.com","A potential client would like us to call them back",$message,"From: MyDomainCallBack");
$make=fopen("admin/data.dat","a");
$to_put="";
$to_put .= $CompanyName."|".$Name."|".$Surname."|".$Email."|".$Telephone."|".$PricingPackage."
";
fwrite($make,$to_put);
header("Refresh: 0;url=http://www.mydomain.com/thanks.html");
?><?php
}
?>
I don't know php and can't see why the code is opening a new window to display the error message. I'd like the javascript to open the new window on top of my html form. So how can I stop the original error page from opening before my new window javascript is run?
Not possible the way it is coded now. When you click the submit button the process.php file is loaded. This is what generates the error message.
Your choices are somewhat limited if you choose to stay with version 2.09. Using 3.0 is a valid option. You would not be able to instal version 3.0 as it is only available in a demo site but the form you generate would have code for checking values before submission. There would still be alot of work to integrate this into another page. If you would like I can take a copy of your html page and add the version 3.0 features for you.
The 3.0 version uses Java to check the form without leaving the form page. If all checks are OK then it submits to the process.php file.
Thanks for getting back to me. I appreciate your offer to add the features of version 3 to "pre-validate" my form before running the process.php file. I've included my HTML code below. If there is anything else you need please let me know.
<!-- BEGIN Record CallBack -->
<form enctype='multipart/form-data' action='phpform/use/CallBack/process.php' method='post'>
<table border="0" cellpadding="2" class="CobaltFormTABLE">
<tr>
<td colspan="2" class="blue">
<div align="center" class="blue">
<p>
<strong>
<br>
Let us call you back with full details
</strong>
<br>
<br>
</p>
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="blue sm style11">
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<span class="style12">
Company
</span>
</div>
</td>
<td>
<div align="left">
<input type="text" class="CobaltInput" maxlength="250" size="23" name='CompanyName' style="WIDTH: 104px; HEIGHT: 20px">
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="sm style11">
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<span class="style13">
<strong>
Name*
</strong>
</span>
</div>
</td>
<td>
<div align="left">
<input type='text' class="CobaltInput" maxlength="250" size="40" name='Name' style="WIDTH: 104px; HEIGHT: 20px">
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="sm style11">
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<span class="style13">
<strong>
Surname*
</strong>
</span>
</div>
</td>
<td>
<div align="left">
<input type="text" class="CobaltInput" maxlength="250" size="40" name='Surname' style="WIDTH: 104px; HEIGHT: 20px">
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="sm style11">
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<span class="style13">
<strong>
Email*
</strong>
</span>
</div>
</td>
<td>
<div align="left">
<input type="text" class="CobaltInput" maxlength="250" size="40" name='Email' style="WIDTH: 104px; HEIGHT: 20px">
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="sm style11">
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<strong>
<span class="style13">
Work Phone*
</span>
</strong>
</div>
</td>
<td>
<div align="left">
<input type="text" class="CobaltInput" maxlength="250" size="40" name='Telephone' style="WIDTH: 104px; HEIGHT: 20px">
</div>
</td>
</tr>
<tr>
<td nowrap class="blue">
<div align="left" class="sm style11">
<strong>
<img style="MARGIN-RIGHT: 5px" height="6" src="images/1arrow10.gif" border="0">
<span class="style13">
Pricing Package*
</span>
</strong>
</div>
</td>
<td>
<div align="left">
<select name='Package' style="width:104px">
<option value='Package1'>Package 1
<option value='Package2'>Package 2
</select>
</div>
</td>
</tr>
<tr>
<td nowrap align="right" colspan="2">
<div align="center">
<input type=submit value='Request Call Back'>
<br>
<br>
</div>
</td>
</tr>
</table>
</form>
<!-- END Record CallBack -->
I will need the entire file. Please send it to me as an email attachment.
PS. I did have the code tabbed correctly to make it easy to read but seems the forum has removed the formatting.
Thank you so much for your help with this. With the Javascript you added to my html page, my form is now working exactly how I envisaged it.