Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Help

Featured Replies

Hi Guys....

 

I need a bit of ehlp if poss please...

I'm trying to center my form in php see image and see code. post-5282-1226330208_thumb.jpg

 

 

Here's my code

 

<?php  $username = trim($_POST['username']);
	   													$useraddr = trim($_POST['useraddr']);
	   													$phonenum =  trim($_POST['phonenum']);
	   													$comments = trim($_POST['comments']);
	   													$sent = $_POST['sent'];
															$self = $_SERVER['PHP_SELF'];
	   													$errname = null;
	   													$num = null;   
	   													$msgend = null;
															$validemail = true; $vlidphone = true;

																															$form ="<form action=\"$self\" method=\"post\">";
	   																															$form.="<table><tr><td align=\"right\" valign=\"top\">Name:</td><td><input type=\"text\" name=\"username\"";
	   																															$form.=" size=\"30\" value=\"$username\" ></td></tr>";
	   																															$form.="<tr><td align=\"right\" valign=\"top\">Email:</td><td><input type=\"text\" name=\"useraddr\"";
	   																															$form.=" size=\"30\" value=\"$useraddr\"></td></tr>";
	   																															$form.="<tr><td align=\"right\" valign=\"top\">Phone:</td><td><input type=\"text\" name=\"phonenum\"";
	   																															$form.=" size=\"30\" value=\"$phonenum\"></td></tr>";													  
	   																															$form.="<tr><td align=\"right\" valign=\"top\">Message:</td><td><textarea name=\"comments\" cols=\"25\" rows=\"4\">";
	   																															$form.="$comments</textarea></td></td>";
 																																$form.="<tr><td></td><td><input type=\"submit\" name=\"sent\" value=\"Send\"></td></tr></table>";
	   																															$form.="</form>";  



		  if($sent) { $valid=true; 
		  if(!$username)			 { $errmsg.="Name, "; $num++; $valid = false; }
																	if(!$useraddr)  { $errmsg.="Email address, "; $num++; $valid = false; }
																	else {												  
																							$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+";
																							$_host = "([-0-9A-Z]+\.)+";
																							$_tlds = "([0-9A-Z]){2,4}$/i";

																							if(!preg_match($_name."@".$_host.$_tlds, $useraddr)) 
																							{ $validemail = false; $valid = false; }}

																	if(!$phonenum)		   { $errmsg.="Phone number, "; $num++; $valid = false; }
																	if(!$comments)			{ $errmsg.="Message, "; $num++; $valid = false; }
																	if(!$validemail){ 
																				if(!$errmsg)	 { $emaile.="T"; }
																				else							  { $emaile.="<br />Also, t"; }																		 
																				$emaile.="he email address is incorrect!"; }
   if(!$valid)					{ echo("<h1 class=\"hd\">Sorry...</h1>"); } }

														if($num > 1)	{ $errmsg.="are missing."; }
														if($num == 1) { $errmsg.="is missing."; }

														if($valid) {
   $to = "email@mydomain.com";
   $re = "Online Form Feedback";							 
   $msg = "Email Address: ".$useraddr."\n\nPhone Number: ".$phonenum." \n\nMessage/Comments: ".$comments. "\n\nName: ".$username;																		
   $headers = "From: $useraddr \r\n";
   mail($to, $re, $msg, $headers);
   echo("<h1 class=\"hd\">Message Sent</h1>Thank you $username for your interest,
   we will be in touch very soon."); }

  else { echo("<p class=\"error\">$errmsg $emaile</p> $form"); }
?>

 

I just wish to know how to get it in then center, altough i have put it inside the "wrapper" div which is centerlised.

 

 

 

Hi Lee

 

Its not really a php problem, its the use of tables within your php

 

Try this and use the attached css to position it

 

<style type="text/css">
<!--
fieldset {
width:20%;
margin-left:300px;
}


-->
</style>


<?php															  $username = trim($_POST['username']);
														   $useraddr = trim($_POST['useraddr']);
														   $phonenum =  trim($_POST['phonenum']);
														   $comments = trim($_POST['comments']);
														   $sent = $_POST['sent'];
															$self = $_SERVER['PHP_SELF'];
														   $errname = null;
														   $num = null;  
														   $msgend = null;
															$validemail = true; $vlidphone = true;

																															$form ="<form action=\"$self\" method=\"post\">";
																																   $form.="<fieldset><label>Name:</label><br><input type=\"text\" name=\"username\"";
																																   $form.=" size=\"30\" value=\"$username\" ><br>";
																																   $form.="<label>Email:</label><br><input type=\"text\" name=\"useraddr\"";
																																   $form.=" size=\"30\" value=\"$useraddr\"><br>";
																																   $form.="<label>Phone:</label><br><input type=\"text\" name=\"phonenum\"";
																																   $form.=" size=\"30\" value=\"$phonenum\"><br>";													  
																																   $form.="<label>Message:</label><br><textarea name=\"comments\" cols=\"25\" rows=\"4\">";
																																   $form.="$comments</textarea><br><br>";
																																 $form.="<input type=\"submit\" name=\"sent\" value=\"Send\"></fieldset>";
																																   $form.="</form>";  



		  if($sent) { $valid=true;
		  if(!$username)			 { $errmsg.="Name, "; $num++; $valid = false; }
																	if(!$useraddr)  { $errmsg.="Email address, "; $num++; $valid = false; }
																	else {												  
																							$_name = "/^[-!#$%&\'*+\\.\/0-9=?A-Z^_'{|}~]+";
																							$_host = "([-0-9A-Z]+\.)+";
																							$_tlds = "([0-9A-Z]){2,4}$/i";

																							if(!preg_match($_name."@".$_host.$_tlds, $useraddr))
																							{ $validemail = false; $valid = false; }}

																	if(!$phonenum)		   { $errmsg.="Phone number, "; $num++; $valid = false; }
																	if(!$comments)			{ $errmsg.="Message, "; $num++; $valid = false; }
																	if(!$validemail){
																				if(!$errmsg)	 { $emaile.="T"; }
																				else							  { $emaile.="<br />Also, t"; }																		
																				$emaile.="he email address is incorrect!"; }
   if(!$valid)					{ echo("<h1 class=\"hd\">Sorry...</h1>"); } }

														if($num > 1)	{ $errmsg.="are missing."; }
														if($num == 1) { $errmsg.="is missing."; }

														if($valid) {
   $to = "email@mydomain.com";
   $re = "Online Form Feedback";							
   $msg = "Email Address: ".$useraddr."\n\nPhone Number: ".$phonenum." \n\nMessage/Comments: ".$comments. "\n\nName: ".$username;																		
   $headers = "From: $useraddr \r\n";
   mail($to, $re, $msg, $headers);
   echo("<h1 class=\"hd\">Message Sent</h1>Thank you $username for your interest,
   we will be in touch very soon."); }

  else { echo("<p class=\"error\">$errmsg $emaile</p> $form"); }
?>

 

Pat

  • Author

So do I just add

 

fieldset {

width:20%;

margin-left:300px;

}

 

into my CSS doc?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.