Jump to content

Form problem


14862875

Recommended Posts

i would really appreciate your help with my form, if thats possible and your not to busy

 

my form should follow like this, when a person submits his/her first name, it should be displayed on another page. However if he/she doesn't complete one of the fields a warning message should appear and the form should also display.. my problem is that when a person leaves out his first name field as well as his last name field, a warning message appears, but the form are also displayed twice or above each other.. i think i used to many include functions within my if functions..

 

here's my code: index.php

<?php

include('form.php');

?>

 

my form.php

<form name="basic" action="handle_form.php" method="post">

<table cellpadding="8" style="text-align:left;color:black;font-family:tahoma;font-size:12;padding:20px;">

<tr><td>First name:</td><td><input type='text' name='fname' value='<?php if(isset($_POST['fname'])) print $_POST['fname'];?>'</input></td></tr>
<tr><td>Last name:</td><td><input type='text' name='lname' value='<?php if(isset($_POST['lname'])) print $_POST['lname'];?>'</input></td></tr>
<tr><td>Email:</td><td><input type='text' name='email' value='<?php if(isset($_POST['email'])) print $_POST['email'];?>'</input></td></tr>
<tr><td>Contact number:</td><td><input type='text' name='ctn' value='<?php if(isset($_POST['ctn'])) print $_POST['ctn'];?>'</input></td></tr>

<input type="hidden" name="submitted" value="TRUE"/>

<tr><td><input type="submit" value="Submit"></td></tr>

</form>

 

my handle_form.php

<?php

if(isset($_POST['submitted']))
{
if(empty($_POST['fname']))
{
	print "<span style='color:red;font-weight:bold;'>Please fill out all of the fields</span><p/>";
	include('form.php');
}
else
{

print"<b>First name:</b>{$_POST['fname']} <br>";
}

if(empty($_POST['lname']))
{
 print "<span style='color:red;font-weight:bold;'>Please fill out all of the fields</span><p/>";
 include('form.php');

 }
 else
{
 print"<b>Last name:</b>{$_POST['lname']} <br>";

 }

}


?>

 

the handle form code is not fully completed i just wanted to show you the problem

 

 

PLEASE HELP

Link to comment
https://forums.phpfreaks.com/topic/155839-form-problem/
Share on other sites

You need to add:

 

error_reporting(E_ALL);

 

So you can determine the error and which line.

 

However I think it is the syntax:

 


print"<b>Last name:</b>{$_POST['lname']} <br>";

 

Should be:

 


print"<b>Last name:</b>".$_POST['lname']."<br>";

 

And the same for fname...

Link to comment
https://forums.phpfreaks.com/topic/155839-form-problem/#findComment-820253
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.