How to make a suggestion box - html

I am trying to make a suggestion box so that way I can see what my viewers think would make my site better. Here is some code that I have.
<form id="form1" name="form1" method="post" action="">
<label>
<textarea name="input" id="input" cols="45" rows="5"></textarea>
</label>
</form>
<form id="form2" name="form2" method="post" action="">
<label>
<input type="submit" name="export" id="export" value="Submit" />
</label>
</form>`
But this is all I have. It seems to work client side but not server side. Can someone tell me what language and if you know the code that I would have to use that would be great.

Post to another HTML file action="myformresults.html"
Post to a server side scripting language like PHP action="myphpformresult.php" which will 'do things' and then render an HTML document or any other thing (like send as email).
You can call a Javascript function to handle the form.
I would recommend PHP.
You can access a post variable in PHP by name:
HTML <input name="postVar">
PHP $myVar = $_POST['postVar'];

all you need is writing a jquery code as follows in your html file: //note that i rewrite your html code as no need for two forms
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
function submitters(){
event.preventDefault();
$.post( "mail.php.txt", $( "#form1" ).serialize(),function( data ) {
$("#formcontainer").fadeOut("slow");
$("#formcontainer").html(data);
} );
}
</script>
</head>
<body>
<div id="formcontainer">
<form id="form1" name="form1" method="post" action="">
<label>
<textarea name="input" id="input" cols="45" rows="5"></textarea>
</label>
<input Onclick="submitters()" type="button" name="export" id="export" value="Submit" />
</form>
</div>
</body>
</html>
then in mail.php file something like
<?php
$input=$_POST['input'];
$to = 'youremail#domain.com';
$subject = 'the subject';
$message = $input;
$headers = 'From: website.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

Related

How to use value from input tag in the same form

I am looking how to reuse the value="typed_from_user" into another tag in the same formulary without using js, just PHP & HTML.
Is it even possible?
For example, here i want to reuse the word 'pizza'
<form>
<input name="hello" type="text" value="I want pizza">
<input name="order" type="text" value="pizza">
</form>
maybe something storing it in a variable?
<form>
<input name="hello" type="text" value="<?php echo $whatyouwant ;?>">
<input name="lunch" type="text" value="<?php echo substr($whatyouwant,7,5);?>"><!--cut it from letter 7, the word pizza-->
<input name="order" type="submit" value="submit">
</form>
yeah, supouse that we know where exactly starts the word pizza
This are the files i am using as tests
action.php
form.php
<?php
//action.php
$var = $_POST['hello'];
$var_lunch= $_POST['lunch'];
echo "hello: $var<br>";
echo "lunch: $var_lunch<br>";
?>
file form.php:
<html>
<header>
<title>test-page</title>
<!--bootstrap-->
<link rel="stylesheet" type="text/css" href="../../../css/bootstrap/bootstrap_v4.0.0.css">
</header>
<body>
<?php
$whatyouwant=777;
?>
<form method="post" action="action.php">
<input name="hello" type="text" value="<?php echo $whatyouwant ;?>">
<input name="lunch" type="text" value="<?php echo substr($whatyouwant,7,5);?>">
<input name="order" type="submit" value="submit">
</form>
</body>
</html>
OUTPUT:
hello: i want pizza
lunch:
If you are trying to get the input value form one text field to another text field only using PhP and HTML, I have to say that it is quite impossible. PhP is the server side language so to get the value from one field to another, it must first reach the server and then it display but will show error in PhP.
To achieve this, you have to use JS. You can achieve this from just a few lines of code using jQuery.

How to clear form data, after submit, but after data passed

I've been looking for over 2 days for solution to this problem of mine. Went through all the related posts on stack, but no luck. I have a form that accepts data, then passes on to a php procedure to process it which in turn calls on a html thank you page. I am not at all familiar with Javascript or JQuery but can make it work after spending some time. I am posting the codes here along with many suggestions that I tried to no avail. Any help that ends my misery is appreciated. Thanks.
HTML
<form method='post' action='contact-form-proc.php' name='contactform' id='contactform' onsubmit="setTimeout('clear_form()',200);return true">
<p>
<label for='fullname'>Your Name:</label><br/>
<input type='text' name='fullname' />
</p>
<p>
<label for='email' >Email Address:</label><br/>
<input type='text' name='email' />
</p>
<p>
<label for='mobile' >Mobile:</label><br/>
<input type='text' name='mobile' />
</p>
<p>
<label for='checkIndate' >Check in Date:</label><br/>
<input type='text' name='checkIndate'/>
</p>
<p>
<label for='comment' >Comment:</label><br/>
<textarea name='comment' cols='25' rows='3'></textarea>
</p>
<input type="image" src="submit.gif" name="submit"/>
<!--<input type='submit' name='submit' value='' id="submit" />-->
<input type="hidden" name="submit" value="Submit"/>
</form>
PHP
<?php
if(empty($_POST['submit']))
{
echo "Form is not submitted!";
exit;
}
if(empty($_POST["fullname"]) ||
empty($_POST["email"]))
{
echo "Please fill the form";
exit;
}
$name = $_POST["fullname"];
$email = $_POST["email"];
$mobile = $_POST["mobile"];
$checkindate = $_POST["checkIndate"];
$comment = $_POST["comment"];
mail( 'xxx#xxxxxx.com' , 'New form submission' , "New form submission: Name: $name, Email:$email, Mobile: $mobile, CheckIndate:$checkIndate, Comment:$comment" );
header('Location: thank-you.html');
?>
These are what I tried:
<script type="text/javascript">
/*$('#contactform').trigger("reset");*/
function clear_form() {
/* document.contactform.reset();
document.getElementById("contactform").reset();*/
/*$(window).load(function() {
$('#contactform input[type="text"]').val('');*/
$(window).load(function() {
$('#contactform').children('input').val('');
}
});
}
</script>
Thanks a ton for taking time out and trying to help me and all others with a solution to this weird problem.
I found a solution though. I kept everything as it is and additionally,
a. Wrote a function to reset the form(s)and,
b. Added that function to onload and onunload handler of the body element.
As below:
<script>
function clearForms()
{
var i;
for (i = 0; (i < document.forms.length); i++) {
document.forms[i].reset();
}
}
</script>
<body onload="clearForms()" onunload="clearForms()">
Hope it helps and stops many like me from wasting valuable hours and days. Regards.
try this one.
<script type="text/javascript">
$(document).ready(function(){
$('input').val('');
});
</script>
End you don`t have to call onsubmit action, document.ready would be enough.

Make a submit button send email with details in HTML

I have a form in HTML with a submit button:
<button type="submit" class="subscribe-submit" onclick="return foo()">Subscribe</button>
I would like it to have the details written on the form to be sent to my personal email address.
I have searched on Stack Overflow, Google, Bing and Yahoo but I couldn't find the answer
You can't do this with pure HTML. However, with a little PHP you can get your form ready to go.
Here's an example of a form handler PHP code in a separate file called form_handler.php:
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['comment'];
$mail_to = 'yourPersonalEmail#email.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the feedback.');
window.location = 'form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Something went wrong. Please try again or contact at myPersonalEmail#email.com');
window.location = 'form.html';
</script>
<?php
}
?>
And here's the HTML form in a file called form.html:
<html>
<head>
</head>
<body>
<form name="form" action="form_handler.php" method="POST">
<label class="name">Name</label>
<br>
<input name="name" type="text" required="required">
<br>
<label class="email">E-Mail</label>
<br>
<input name="email" type="email" required="required">
<br>
<label class="comment">Comment</label>
<br>
<textarea name="comment"></textarea>
<br>
<input type="submit" name="submit" value="Subscribe" align="center">
</form>
</body>
</html>
I suggest you learn a little bit about PHP and form handing. You might need to change the fields but I think you'll get the idea.

How to submit a contact form via custom button using "href" code?

For my website I'm working on a contact form, which works. But I want the submit button to be like other buttons on my site, meaning I want it to be styled like the code below.
However, I can't get it to submit via a "href" code.
I've tried applying answers on similar questions but haven't had any luck.
Any help would be greatly appreciated!
THE STYLE FOR THE SUBMIT BUTTON I WANT TO USE:
<div class="section-buttons">
<p class="button layer" data-depth="0.10" ><a href = "I WANT THIS TO SUBMIT THE FORM"
class="y1 knop roll swing"><span class="g1">SUBMIT</span><span class="g2">SUBMIT</span>
</a></p>
</div>
THE FORM CODE:
<form action="form.php" method="post" enctype="multipart/form-data">
<label></label>
<input name="name" required placeholder="Name">
<label></label>
<input name="email" type="email" required placeholder="E-mail">
<label></label>
<textarea name="message" cols="20" rows="5" required placeholder="Message">
</textarea>
<input id="submit" name="submit" type="submit" value="Submit">
</form>
EDIT:
Thanks a lot for the quick replies. Really appreciated.
Celt, your solution definitely brings me close to the solution.
It does indeed bring me to the form.php but it doesn't seem to submit the actual data to an email address.
Could it be that my PHP file (forms.php) does something wrong with the new code? I'm guessing the last part "if ($_POST['submit'])" doesn't quite work with this new approach? Any help?
Sorry for the noobness.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: website.com';
$to = 'email#email.com';
$subject = 'Email Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message
again.</p>';
}
}
?>
This should work for you:

mysql 404 error

have the following code:
<?php
if (isset($_POST['submitted'])) {
$reqwidth = $_POST['reqwidth'];
$reqside = $_POST['reqside'];
$reqrad = $_POST['reqrad'];
$sqlinsert = "INSERT INTO tirelist (width, sidewall, radial) VALUES ('$reqwidth','$reqside', '$reqrad')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to database";
}
?>
<html>
<head>
<title>Request Tire Size</title>
</head>
<body>
<h1>Request Tire Size</h1>
<form method="post" action="insert-data.php">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<legend>Request Tire</legend>
<label>Tire Width: <input type="text" name="reqwidth" /></label>
<label>Tire Sidewall: <input type="text" name="reqside" /></label>
<label>Tire Radial: <input type="text" name="reqrad" /></label>
</fieldset>
<br />
<input type="submit" value="Send Order Request" />
</form>
when i click send order request, I get a 404 error.
i noticed the page is called ~http://localhost/index.php?p=test2~, but when i click it redirects me to ~http://localhost/insert-data.php~
been trying for hours, wondering what i could do to fix it
Change
<form method="post" action="insert-data.php">
to have index.php?p=test2 instead.
In your form, you reference insert-data.php. Does that exist?
If you're trying to submit the form to the same file, you can try to use this:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Try this instead. form method="post" action="/insert-data.php"