Why does PHP break my CSS? - php

I have recently created a contact form with PHP mailer which is finally working. However the success message is breaking my page and displaying in the top left corner instead of underneath the form. As you can see below.
This is the HTML:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
</table>
<input type="submit" value="Submit" name="submit">
<?php
if ($success) {
echo $success;
}
?>
</form>
It also creates a huge blank white area in the middle of my page under the form. Does anyone know why this is? or how I would go about debugging it?

You should put this in a div or a span
<div style="text-align:center;"> <?php
if ($success) {
echo $success;
}
?>
</div>

Try following code:
<form method="POST">
<table border="1">
<tr>
<td><label for="name" class="g">Name</label></td>
<td><input id="name" name="name" type="text" autofocus></td>
</tr>
<tr>
<td><label for="address" class="g">Address</label></td>
<td><textarea rows="3" id="address" name="address" cols="50"></textarea></td>
</tr>
<tr>
<td><label for="number" class="g">Contact number</label></td>
<td><input id="number" name="number" type="text" autofocus></td>
</tr>
<tr>
<td><label for="email" class="g">Email</label></td>
<td><input id="email" name="email" type="text" placeholder="example#domain.com" autofocus></td>
</tr>
<tr>
<td><label for="message" class="g">Enquiry</label></td>
<td><textarea rows="3" id="message" name="message" cols="50"></textarea></td>
</tr>
<?php
if ($success) {?>
<tr><td colspan="2">
<?php echo $success; ?>
</td></tr>
<?php }
?>
</table>
<input type="submit" value="Submit" name="submit">
</form>

Related

ReCaptcha V2 returns False even though checked

Having a problem with ReCaptcha. Even if checkbox is checked, it still returns false. I have triple checked my keys and happy they are correct. I am using code based on that successfully used on another of my sites. Cannot see what is wrong.
For ease of reference, I have copied all the relevant coding. Hopefully someone will see straight away what I've done wrong.
Form Code:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" placeholder="Please enter your first name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" placeholder="Please enter your surname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="email" name="email" placeholder="Please enter your email address" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="tel" name="telephone" placeholder="Please enter your phone number" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center"><div class="g-recaptcha" data-sitekey="6LejdlwUAAAAAHb5qaNIhfDzxL1i9a9sCyw8dLzD"></div></td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <br> Email Form
</td>
</tr>
</table>
</form>
Code from the PHP:
<?php
// Code from ReCaptcha evaluation:
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "************************************";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are a spammer ! Your form has been rejected.</h2>';
} else
// End Code from ReCaptcha evaluation.
Many Thanks
Tim

Having trouble sending HTML form to email through PhP [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 7 years ago.
I have created a form and would like the information to be sent to my email using php. The information submits, and I receive an e-mail, but the email only displays the first and last name of input by the individual submitting the form. I would like to know what is missing from either the php side or html side.
Thank You
<form name="contactform" method="post" action="appraisal_form.php">
<table width="500px">
<tr>
<td>
<label for="first_name">First Name *</label>
</td>
<td>
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="last_name">Last Name *</label>
</td>
<td>
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td>
<label for="email">Email Address *</label>
</td>
<td>
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="telephone">Telephone Number</label>
</td>
<td>
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<!--- Property Type-->
<tr>
<td>
<label for="lender">Lender *</label>
</td>
<td>
<input type="text" name="lender" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_officer">Loan Officer *</label>
</td>
<td>
<input type="text" name="loan_officer" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="property_address">Email Address *</label>
</td>
<td>
<input type="text" name="property_address" maxlength="100" size="30">
</td>
</tr>
<tr>
<td>
<label for="city">City *</label>
</td>
<td>
<input type="text" name="city" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="zip">Zip Code *</label>
</td>
<td>
<input type="text" name="zip" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="pin">PIN(Permenant Index Number) *</label>
</td>
<td>
<input type="text" name="pin" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="rooms">Number of Rooms *</label>
</td>
<td>
<input type="text" name="rooms" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="bath">Number of Bathrooms *</label>
</td>
<td>
<input type="text" name="bath" maxlength="80" size="30">
</td>
</tr>
<!--- Garage /yes or no-->
<tr>
<td>
<label for="plat">Plat of Survey *</label>
</td>
<td>
<input type="text" name="plat" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="borrow">Borrowers Name *</label>
</td>
<td>
<input type="text" name="borrow" maxlength="80" size="30">
</td>
</tr>
<!--- sale /refinance-->
<tr>
<td>
<label for="price">Purchase Price *</label>
</td>
<td>
<input type="text" name="price" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="loan_amount">Loan Amount *</label>
</td>
<td>
<input type="text" name="loan" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="cod">C.O.D *</label>
</td>
<td>
<input type="text" name="cod" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="invoice">Invoice *</label>
</td>
<td>
<input type="text" name="invoice" maxlength="80" size="30">
</td>
</tr>
<tr>
<td>
<label for="comments">Comments *</label>
</td>
<td>
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" name="submit" id="submit" value="Submit">
<input type="reset" name="Reset" id="reset" value="reset">
</td>
</tr>
</table>
</form>
PHP
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$lender = $_POST['lender']; // required
$loan_officer = $_POST['loan_officer']; // required
$property_address = $_POST['property_address']; // required
$city = $_POST['city']; // required
$zip = $_POST['zip']; // not required
$pin = $_POST['pin']; // required
$rooms = $_POST['rooms']; // required
$bath = $_POST['bath']; // required
$plat = $_POST['plat']; // required
$borrow = $_POST['borrow']; // not required
$price = $_POST['price']; // required
$cod = $_POST['cod']; // not required
$comments = $_POST['comments']; // required
$to = "rosaliam2#yahoo.com";
$subject = "New Appraisal Request";
$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 />';
}
mail($to, $subject, $message, "From" . $first_name . $last_name);
echo "Your Information has been sent";
?>
Actually there is no message variable to send!!
you are just sending $first_name and $last_name as headers!

Printing Textarea element on PDF without being overflow

I'am Generating a PDF with the help oh HTML and PHP. But the text in textarea in getting overflowed. The text in printing only in a single line.
My HTML Code is
<html>
<head>
<title>registration form</title>
</head>
<h2 ALIGN="CENTER">Registration form</h2>
<form action="pro1.php" method="post">
<table border="0" align="center">
<tbody>
<tr>
<td><label for="id">Id: </label></td>
<td><input id="id" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="name">Name: </label></td>
<td><input id="name" maxlength="50" name="name" type="text" /></td>
</tr>
<tr>
<td><label for="course">Course: </label></td>
<td><input id="course" maxlength="50" name="course" type="text" /></td>
</tr>
<tr>
<td><label for="branch">Branch: </label></td>
<td><input id="branch" maxlength="50" name="branch" type="text" /></td>
</tr>
<tr>
<td><label for="rolln0">Rollno: </label></td>
<td><input id="rollno" maxlength="50" name="rollno" type="text" /></td>
</tr>
<tr>
<td><label for="email">Email_Address:</label></td>
<td><input id="email" maxlength="50" name="email" type="text" /></td>
</tr>
<tr>
<td><label for="username">User_Name:</label></td>
<td><input id="username" maxlength="50" name="username" type="text" /></td>
</tr>
<tr>
<td><label for="aboutus">About Us:</label></td>
<td valign="middle" align="center"><textarea wrap="wrap" rows ="1" cols ="1" name = "aboutus"></textarea></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input id="password" maxlength="50" name="password"
type="password" /></td>
</tr>
<tr>
<td align="right"><input name="Submit" type="Submit" value="Add" /></td>
</tr>
</tbody>
</table>
</form>
</html>
and my PHP Code is
require('fpdf/fpdf.php');
$pdf = new FPDF();
//var_dump(get_class_methods($pdf));
$pdf -> AddPage();
$pdf->SetFont("Arial","B",16);
$pdf->Cell(0,10,"Welcome {$pro_name}",1,1);
$pdf->Cell(50,10,"Name: ",1,0);
$pdf->Cell(50,10,$pro_name,1,1);
$pdf->Cell(50,10,"Branch: ",1,0);
$pdf->Cell(50,10,$pro_branch,1,1);
$pdf->Cell(50,10,"Roll No: ",1,0);
$pdf->Cell(50,10,$pro_rollno,1,1);
$pdf->Cell(50,10,"Email: ",1,0);
$pdf->Cell(50,10,$pro_email,1,1);
$pdf->Cell(50,10,"About Us: ",1,0);
$pdf->Cell(50,10,$pro_aboutus,1,1);
$pdf->output();
}
?>
please help me, and tell me what should i do so that my text area prints within the a4. Thank You In Advance
Use MultiCell rather than Cell.
As it says, "This method allows printing text with line breaks."
Example:
$this->MultiCell(60,5,$txt);
Full example here
MultiCell documentation here

html / php code validation error

I keep getting errors while trying to validate this code.
Error message examples:
e.g. 1 - Line 152, Column 42: Unescaped '<' not allowed in attributes values …>
<input type="text" name="Name" value="<?php echo htmlspecialchars($Name); ?>"…
e.g. 2 - Line 152, Column 42: attributes construct error …>
<input type="text" name="Name" value="<?php echo htmlspecialchars($Name); ?>"…
e.g. 3 - Line 152, Column 42: Couldn't find end of Start Tag input line 152 …>
<input type="text" name="Name" value="<?php echo htmlspecialchars($Name); ?>"…
The same errors occur for any lines that contains the line e.g < php echo htmlspecialchars($...)
Please let me know what I am doing wrong.
<!-- Form-->
<form name="editcontact" method="post" action="">
<table border="1" cellpadding="2">
<caption>Edit Contact</caption>
<!--ID Input-->
<tr><td><?php if ($ContactID != '') { ?>
<input type="hidden" name="ContactID" value="<?php echo htmlspecialchars($ContactID); ?>" />
<?php } ?></td></tr>
<!--Name Input-->
<tr>
<td><label for="Name">Name</label></td>
<td><input type="text" name="Name" value="<?php echo htmlspecialchars($Name); ?>" size="30" maxlength="50" tabindex="1"/></td>
</tr>
<!-- Address Input-->
<tr>
<td><label for="Address">Address</label></td>
<td><textarea name="Address" cols="45" rows="5" tabindex="2"><?php echo htmlspecialchars($Address); ?> </textarea></td>
</tr>
<!--Phone Input-->
<tr>
<td><label for="Phone">Phone</label></td>
<td><input type="text" name="Phone" value="<?php echo htmlspecialchars($Phone); ?>" size="20" maxlength="20" tabindex="3" /> </td>
</tr>
<!--Mobile Input-->
<tr>
<td><label for="Mobile">Mobile</label></td>
<td><input type="text" name="Mobile" value="<?php echo htmlspecialchars($Mobile); ?>" size="20" maxlength="20" tabindex="4" /> </td>
</tr>
<!--Email Input-->
<tr>
<td><label for="Email">Email</label></td>
<td><input type="text" name="Email" value= "<?php echo htmlspecialchars($Email); ?>" size="30" maxlength="50" tabindex="5" /></td>
</tr>
<!--Submit Button-->
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" value="Submit" onclick="return validateForm()" tabindex="6"/>
</td>
</tr>
</table>
</form>
Run the PHP and validate the HTML output. Don't try to validate PHP as if it was HTML.

php inserting last inserted values to the database

I have my login table in mysql is like this
id
fname
lname
email
contactno
userid
password
acctype
status
Now my form is like this
<form name="frm" method="post" action="registerform.php">
<table id="new-account" class="create-an-account" width="100%" border="1" cellspacing="10px" cellpadding="10px">
<tr>
<td width="45%">
<label for="firstname">First Name</label>
<input type="text" style="width:230px;" name="Firstname" id="Firstname" /></td>
<td width="10%"></td>
<td width="45%">
<label for="lastname">Last Name:</label>
<input type="text" style="width:230px;" name="LastName" id="LastName" />
</td>
</tr>
<tr>
<td>
<label for="">Account Type</label>
<select class="select" name="at" id="ValidSelection" style="width:245px;" >
<option value="0">Select Account Type</option>
<option value="agent">agent</option>
<option value="admin">admin</option>
</select>
</td>
</tr>
<tr>
<td><label for="">Email Id:</label></td>
</tr>
<tr>
<td><input type="text" name="email" id="ValidEmail" style="width:230px;"/></td>
</tr>
<tr>
<td><label for="">Contact Number</label></td>
</tr>
<tr>
<td><input type="text" name="contact" id="ValidNumber" style="width:230px" /></td>
</tr>
<tr>
<td><label for=""><strong>Choose Your Login Id:</strong></label>
<input type="text" style="width:230px;" name="LoginId" id="LoginId"/>
</td>
</tr>
<tr>
<td><label for=""><strong>Password: <br /></strong></label></td>
</tr>
<tr>
<td><input type="password" style="width:230px;" name="Password" id="ValidPassword" /></td>
</tr>
<tr>
<td><label for="">Confirm Password:</label></td>
</tr>
<tr>
<td>
<input type="password" style="width:230px;" name="ConfirmPassword" id="ValidConfirmPassword"
/>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="signup" value="Create Account" style="margin-top:20px" /></td>
</tr>
</table>
and for insert data my php code is like this
<?php
if(isset($_REQUEST['signup'])) {
mysql_query("insert into login (`fname`,`lname`,`email`,`contactno`,`userid`,`password`,`acctype`,`status`) values('".$_REQUEST['Firstname']."','".$_REQUEST['LastName']."','".$_REQUEST['email']."','".$_REQUEST['contact']."','".$_REQUEST['LoginId']."','".$pswd."','".$_REQUEST['at']."','active')");
}
?>
Now here when I am reloading the page it is automatically inserting the last entered values to the database. So here can someone kindly tell me what is the issue here? Any help and suggestions are welcome.
If you reload the page after submitting a form, it will keep the POST data. To solve this follow the below things :
You can redirect to some other page after inserting the data, use header("location:new_page.php")
You can unset REQUEST, use unset($_REQUEST) after insert
after inserting the $_POST data use redirect to avoid this situation .
even you can redirect to same page like this :-
header('Location: '.$_SERVER['PHP_SELF']);
exit;

Categories