Hi I've got a problem with submitting my own simple form in Wordpress it always redirects me to the page witch not exists. I use almost all thing for action field in form like (get_permalink,$_SERVER["PHP_SELF"]) and even did it manually.
<?php
if (isset($_POST["email"]) && $_POST["email"]) {
$content = "user email: {$_POST["email"]}; phone : {$_POST['phone']} ";
$subject = "Test email ";
$to = "some#gmail.com";
$status = wp_mail($to,$subject,$content);
}
?>
<div class="center form-wrapper">
<form action="<?php echo get_permalink(); ?>" method="post">
<h2 class="center white form-logo">
Subscribe
</h2>
<input type="text" placeholder="Enter email" name="email">
<input type="text" placeholder="Enter name" name="name">
<input type="text" placeholder="Enter phone number" name="phone">
<input type="hidden">
<input type="submit" name="submit" value="send" >
</form>
Related
I have query results returned in an array on page1 and I want two of those results to pass and populate a form on page2. i have that part working except that one of the variables is a paypal button which includes html so it ends up displaying the button on page1 and does not let user click to page2. Besides displaying the button it displays " />. I need to know how, if possible, to pass the button details to become the "submit" button on page2. Thanks.
THIS IS PAGE1 CODE:
$results=mysqli_query($connection, $sql);
if (mysqli_num_rows($results) < 1) {
echo "<br>We are working on this trip's details.<br><br><h3
style='color:#C8FE2E'>Check back soon!</h3>";
} else {
$tripID = 1; //temp var
$payButton = 2; //temp var
while($row=mysqli_fetch_array($results)) {
echo"Trip ID: " .$row[1].
"<br>Date: " .$row[3].
"<br>Departs From: " .$row[4].
"<br>Departure Time: " .$row[5].
"<br>Arrives at Casino: " .$row[6].
"<br>Leaves at Casino: " .$row[7].
"<br>Arrives at Drop Off: " .$row[8].
"<br>Drop Off Location: " .$row[9].
"<br>Price: $" .$row[10].
"<br><br>Trip Details: " .$row[11]
;
$tripID = $row[1];
$payButton = $row[14]; //should not display on this page
echo "";
}
}
if(mysqli_num_rows($results) > 0) {
?>
<br><br>
<form action="reserve-form.php" method="POST">
<input type="hidden" name="tripID" value="<?php echo $tripID; ?>"/>
<input type="hidden" name="payButton" value="<?php echo $payButton;?>"/>
<button class='reg-btn' type="submit" name="clicked" style='border:none' >Register Now</button>
</form>
<?php
}else{
echo"";
}
mysqli_close($connection);
?>
AND THIS IS PAGE2 (where the button SHOULD display):
Reserve your Seat
<div class="form-group">
<label>Trip ID#</label>
<input class="form-control" type="text" name="tripID" value="<?php echo
$_POST['tripID']; ?>" readonly>
</div>
<div class="form-group">
<label>First Name</label>
<input class="form-control" type="text" name="firstName" required >
</div>
<div class="form-group">
<label>Last Name</label>
<input class="form-control" type="text" name="lastName" required>
</div>
<div class="form-group">
<label>Phone Number</label>
<input class="form-control" type="text" name="phone" required>
</div>
<div class="form-group">
<label>Email Address</label>
<input class="form-control" type="email" name="email" required>
</div>
<center><input class="btn btn-success" id="submit_btn" type="submit" value="Submit" name="submit">
<img src="images/Spinner-gif.gif" class="ld_img" style="display:none;"/>
</center>
</form>
The landing page has form but it is not submitting and not redirecting to the next page.After submitting the form, it stays on the same page.
It was alright and was working before but I cant figure out where is the problem.
Code in formPage.php is below:
<form action="insert.php" enctype="multipart/form-data" class="contact_form" method="post" name="htmlform" >
<input class="frm-input" name="name" type="text" size="30" maxlength="50" placeholder="Enter Name" required="required" />
<input class="frm-input" name="email" type="text" size="30" maxlength="80" placeholder="Enter Email" required="required"/>
<input class="frm-input" name="jobtype" type="text" size="30" maxlength="30" placeholder="Job Type" required="required"/>
<input class="frm-input" name="ent_type" type="text" size="30" maxlength="80" placeholder="Entity Type" required="required"/>
<input class="frm-input" name="tas_out" type="text" size="30" maxlength="80" placeholder="Task Outline" required="required"/>
<input class="frm-input" name="l_st" type="text" size="30" maxlength="80" placeholder="Logo style of interest (optional)" />
<textarea required="required" class="frm-input frm-txtarea" name="message" placeholder="Task Description!!" maxlength="1000" cols="25" rows="6" ></textarea>
<input style="float: left;" type="file" name="image" size="66"/>
<input type="submit" class="btn btn-success btn-lg" name="submitt" value="submit" style="float: right" />
</form>
In this file I am trying to get the form information and storing them in database.But this page is not loading after the form submission.
Code in insert.php is below:
<?php
/*
$name = "";
$text = "";
$post = "";
*/
//echo $name;
if (isset($_POST['submitt']))
{
$name = $_POST["name"];
$mail = $_POST["email"];
$j_type = $_POST["jobtype"];
$e_type = $_POST["ent_type"];
$task = $_POST["tas_out"];
$l_st = $_POST["l_st"];
$task_des = $_POST["message"];
$image_name=$_FILES['image']['name'];
$image_type=$_FILES['image']['type'];
$image_size=$_FILES['image']['size'];
$image_temp=$_FILES['image']['tmp_name'];
//$date = date(m-d-y);
echo $name;
echo $mail;
echo $j_type;
echo $e_type;
echo $task;
echo $l_st;
echo $task_des;
if ($image_type=='image/jpeg' || $image_type=='image/png' || $image_type=='image/gif') {
move_uploaded_file($image_temp, "img/$image_name");
}
$connection=mysqli_connect("localhost", "root", "","com");
$query="insert into details (name, mail, j_type, e_type, task_outline, l_style, task_desc, image) values('".$name."','".$mail."','".$j_type."','".$e_type."','".$task."','".$l_st."','".$task_des."','".$image_name."')";
if(mysqli_query($connection,$query)){
//include('test.php');
echo '<h2>Data submitted successfully!!</h2>';
header("refresh:1; url=login.php");
//echo 'Back';
}else{
echo "Data not Submitted!";
# code...
}
}
echo "Data not Submitted!";
?>
echo "Data not Submitted!"; // put this line inside the last bracket
Sorry it was my fault,there was a typo mistake in the form action.Everything else is fine.
I am using the code below, but want error messages when the user skips a required field. Can anyone help, please? So if a user forgets to fill the required input filed "first name", that an error message appears above the field with the text "First name is a required field".
<form id="comment_form" action="form.php" method="post">
<div class="compulsoryfield">
<input class="inputfield-radio" type="radio" name="gender" value="Mr" required><label class="label-radio">Mr.</label>
<input class="inputfield-radio" type="radio" name="gender" value="Ms"><label class="label-radio">Ms.</label>
<span class="requiredmark-radio">*</span>
</div>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<input class="inputfield3" type="firstname" placeholder="first name" required>
</div>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<input class="inputfield1" type="lastname" placeholder="last name" required>
</div>
<input class="inputfield2" type="companyname" placeholder="company name (if applicable)">
<input class="inputfield2" type="customernumber" placeholder="customer number (on invoice if available)" >
<br><br>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<input class="inputfield3" type="email" placeholder="email address" required>
</div>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<input class="inputfield1" type="emailagain" placeholder="re-enter email address (to confirm)" required>
</div>
<input class="inputfield2" type="telephonenumber" placeholder="telephone number (country code included)">
<br><br>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<input class="inputfield3" type="subject" placeholder="subject of message" required>
</div>
<div class="compulsoryfield"><span class="requiredmark">*</span>
<textarea id="textareafieldid" class="textareafield" name="message" placeholder="add your message here" rows="8" cols="39" required></textarea></div><br><br>
<p id="recaptcha-header">before sending, please show us you're real:</p>
<div><span class="requiredmark">*</span><div id="g-recaptcha-outer" class="compulsoryfield2">
<div class="g-recaptcha" data-sitekey="mySitekey"></div></div><br><br>
<input id="button-type1" type="submit" name="submit" value="SEND">
</form>
and
<?php
$email;$comment;$captcha;
if(isset($_POST['gender'])){
$email=$_POST['gender'];
}if(isset($_POST['firstname'])){
$email=$_POST['firstname'];
}if(isset($_POST['lastname'])){
$email=$_POST['lastname'];
}if(isset($_POST['companyname'])){
$email=$_POST['companyname'];
}if(isset($_POST['customernumber'])){
$email=$_POST['customernumber'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['emailagain'])){
$email=$_POST['emailagain'];
}if(isset($_POST['telephonenumber'])){
$email=$_POST['telephonenumber'];
}if(isset($_POST['subject'])){
$email=$_POST['subject'];
}if(isset($_POST['message'])){
$email=$_POST['message'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the captcha form.</h2>';
exit;
}
$secretKey = "mtSecretKey";
$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 !</h2>';
} else {
echo '<h2>Thanks for your email.</h2>';
}
?>
I suggest you to try js plugins like :
http://parsleyjs.org/
or
http://www.formvalidator.net/
You gonna see, the first is for me the best , and the second is very simple.
With the second you just have to add an attribute rules to your field like :
data-validation="required".
With this example you can required a field.
send the destination of the form to the same page the form is on.
At the top of the page before any html code is sent to the client, do your form handling.
$problemstring = "";
$firstname = "";
if(isset($_POST['submit'])){
if(!isset($_POST['firstname'])){$problemstring = "Error in firstname"}
//repeat for all fields
}
if(strlen($problemString)==0) {
//Do database actions here
//The Line below redirects to another page if form good
if(strlen($problemString)==0) die(header('Location: index.php'));
}
This code you check your form for blank data then if there are no problems run the database operations. If there is a problem the rest of the page will load.
Put the code below where you want the error message to be displayed.
<?php
if(strlen($problemString)>0) {
echo '<table><tr>';
echo '<td colspan="3">';
echo '<font color="#FF0000"><strong>There was a problem with your form</strong><br>';
echo $problemString;
echo '</font></td>';
echo '</tr>';
echo '<tr><td colspan="3" height="16"></td></tr></table>';
}
?>
In your form do this:
<input class="inputfield3" type="firstname" placeholder="first name" value="<?php echo $firstname; ?>" required>
this will populate the field with what was entered into the form before the submit, if this was the empty field it would be blank. if the page is loaded for the first time the value would be blank (or whatever you set).
Ive used this in my website and it works well.
I have a form called addcustomer.php . it's contain firsname, lastname, mobile fields.i have also 2 button on this form. onr button for saving data and the others for sending sms to customers.
i want to when i click second button 3 data fields passed to another form called smsinfo.php.
now action for saving data works good but when direct to smsinfo . there is no data on this form .
<form method ="POST" name = "custform" action="">
<div class="cell_2_2"><label class="lblfields">Firstname:</label> <input type="text" name="firstname" autocomplete="off"/></div>
<div class="cell_3_2"><label class="lblfields">Lastname :</label> <input type="text" name="lastname" autocomplete="off"/></div>
<div class="cell_5_2"><label class="lblfields">Mobile :</label> <input type="text" name="mobile" autocomplete="off"/></div>
<input type="submit" name="submit" value="Save"/>
<input type="submit" name="sendsms" value="Sms"/>
if (isset($_POST['submit']))
{
Saving code here
} else if (isset($_POST['sendsms'])) {
header("Location: smsinfo.php");
}
here code of smsinfo.php:
<?php
$Fname = $_REQUEST['firstname'];
$Lname = $_REQUEST['lastname'];
$Mob = $_REQUEST['mobile'];
?>
<html>
<body>
<form action="sendingsms.php" method="POST">
<input style="width: 100px;" name="firstname" type="text" value="<?php echo $firstname; ?>"/>
<input style="width: 100px;" name="lastname" type="text" value="<?php echo $lastname; ?>"/>
<input style="width: 100px;" name="mobile" type="text" value="<?php echo $mobile; ?>"/>
</form>
</body>
</html>
thanks all and sorry for my poor english
I am using a custom optin page with a form , While testing and in work,When I submit the form I get all the details on my email except the phone number , I do not see any problem with the codes , I tried diff things like changing the value and stuff but it did not work, Here is the form code
<div class="form fix ">
<p class="form-text">Fill This Out and See Your <br>Timeshare Report</p>
<form name="contactform" action="mail-script.php" method="POST">
<label for="fname">First Name:
<input type="text" name="fname" id="fname" />
</label><br>
<label for="lname">Last Name:
<input type="text" name="lname" id="lname" />
</label><br>
<label for="email">Email Address:
<input type="text" name="email" id="email" />
</label><br>
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
</label><br>
<label for="resort">Resort Name:
<input type="text" name="resort" id="resort" />
</label><br>
<label for="amount">Amount Owed? $:
<input type="number" name="amount" id="amount" />
<p style="font-size: 12px !important;margin-top: -14px;padding-right: 30px;text-align:right;">
If Paid Off Leave Zero, Else Put Amount</p>
</label><br>
<div class="checkbox">
<div class="check-text fix">
<p>I'm Considering To</p>
</div>
<div class="check-one fix">
<input type="checkbox" name="call" id="" value="sell"/> Sell It <br>
<input type="checkbox" name="call" id="" value="buy"/> Buy It <br>
<input type="checkbox" name="call" id="" value="rent "/> Rent It
</div>
<div class="check-two fix">
<input type="checkbox" name="call" id="" value="cancel"/> Cancel Mortgage <br>
<input type="checkbox" name="call" id="" value="ownership"/> End Ownership <br>
<input type="checkbox" name="call" id="" value="give"/> Give It Back
</div>
</div>
<p class="captcha">
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
</p>
<input id="submit" type="submit" value="" />
<p class="submit-text">Ensure all fields are completed and correct, allowing you more benefits, while preventing abuse of our data.</p>
</form>
</div>
</div>
This is the mail script which sends me the email
<?php
/* Set e-mail recipient */
$myemail = "**MYEMAIL**";
/* Check all form inputs using check_input function */
$fname = check_input($_POST['fname'], "Enter your first name");
$lname = check_input($_POST['lname'], "Enter your last name");
$email = check_input($_POST['email']);
$phone = check_input($_POST['phone']);
$resort = check_input($_POST['resort']);
$amount = check_input($_POST['amount']);
$call = check_input($_POST['call']);
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
First Name : $fname
Last Name : $lname
E-mail: $email
Phone : $phone
Resort: $resort
Amount: $amount
Call : $call
End of message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: index.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
if (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
Here is the online url of the page
http://timesharesgroup.com/sell/index.html
You have two form elements with the same name. The second one overwrites the first one and you never receive it. You also forget your alternate phone number in your PHP code.
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="altphone" id="aphone" />
</label><br>
Your PHP:
$phone = check_input($_POST['phone']);
$altphone = check_input($_POST['altphone']);
Phone : $phone
Alt Phone : $altphone
Resort: $resort
Your alternative phone number is overwriting your phone number:
<label for="phone">Phone Number:
<input type="text" name="phone" id="phone" />
</label><br>
<label for="phone">Alternate Phone:
<input type="text" name="phone" id="aphone" />
^^^^^ here
</label><br>
Changing the name for the alternative number should fix that.