I am working on a project that is developed using Kohana and due to some conditions I have no access to use NAME in the forms instead I have an option to use ID but I tried using the following method which didn't work.
<form action="sendmail.php" method="post">
<p><input type="text" size="30" style="border-radius:15px; border:2px solid #000; padding:5px;" placeholder="Name" id="contname" /><br />
<br />
<input type="text" size="30" style="border-radius:15px; border:2px solid #000; padding:5px;" placeholder="Email" id="contemail" /><br />
<br />
<input type="text" size="30" style="border-radius:15px; border:2px solid #000; padding:5px;" placeholder="Subject" id="contsubject" /><br />
<br />
<textarea style="border-radius:5px; border:2px solid #000; padding:5px; width:320px; height:120px;" id="contmessage" placeholder="Message"></textarea><br />
<br />
<input type="submit" value="SUBMIT" style="background-color:#9377dd; border-radius:10px; padding-top:3px; padding-bottom:3px; padding-left:16px; padding-right:16px;" /></p>
</form>
sendmail.php
<?php
$from = $_POST["contemail"];
$message = $_POST["contname"] . "<br/>". $_POST["contsubject"] . "<br/>" . $_POST["contmessage"];
mail("me#mail.com","From contact form",$message,"From: $from\n");
mail("me#mail.com","From contact form",$message,"From: $from\n");
header('Location: faq');
?>
Any alternate method please???
When you post the form then in server side you can access that field by their name. Now you are not using the name and instead of you are using the id then I will suggest you to use javascript ajax method to post the form. This is the only alternative method is available.
When you post a form, the form is converted into key/value pairs and sent to the server. For example...
<input name="MyName" value="MyValue">
Is sent to the server as
MyName=MyValue
Unless the browser can form a key/value pair it won't send the data - this is true whether you are missing the key (from the name attribute) or a value (for example a checkbox that is not checked).
You could iterate over the form using JavaScript and create a form post using a different attribute (such as your ID), but if you have access to add JavaScript to this form, it would be easier to just add names.
Related
What i'm trying to do here is to ask for the client to write his name, address, post code, etc. in a form, that will take him to the paypal payment(pay now button) and that also sends me the input values inserted.
The reason i ask for those things is because the job implies cleaning the windows, leave a paper with the price, the client goes to the website and pays via paypal, but to confirm his payment, i need the address. The payment confirmation will for between paypal and email is mostly the time sent and value, bc paypal does not give any client info.
I had an idea to only send the email when payment is completed, but it's on paypal so i don't know anything about it.
I have tried, using a script that calls two actions, but only one action takes place. I also tried having the inputs on another form, but the button calls both of them with a script, but still only one takes action.
I really need this, it's a must for the website and i just can't fo it, I have been trying so hard to find anything that works, and i did find similar problems but my problem still remained.
HTML:
<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" >
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="example#hotmail.com">
<!-- Payment Info -->
<input type="hidden" name="item_name" value="Window Cleaning">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0.50">
<input name="shipping" type="hidden" value="0.00">
<input name="cancel_return" type="hidden" value="http://localhost/Window_Cleaner/menu/payment_confirmation/cancel.html" >
<!-- Client Data -->
<!-- Set variables that override the address stored with PayPal. -->
<div id="divContainer" style="width: 90%;">
<input name="amount" placeholder="Amount">.50£<br>
<input name="first_name" placeholder="First Name" required>
<input name="last_name" placeholder="Last Name" required><br>
<input style="width: 72%; padding: 10px; margin: 5px;" name="address" placeholder="Address" required><br>
<input name="city" placeholder="City" >
<input name="zip" placeholder="Post Code" required><br>
</div>
<br>
<!-- Button Pay Now -->
<button class="paypalpaybutton" name="submit" >
<input style="width: 70px; height: 18px;" type="image" src="http://localhost/Window_Cleaner/pictures/paypal/pp.png" border="0" alt="PayPal – The safer, easier way to pay online!">
</button>
</form >
PHP:
<?php //For paypal Form
if(isset($_POST['submit'])) {
$amount=$_POST["amount"];
$fname=$_POST["first_name"];
$lname=$_POST["last_name"];
$address=$_POST["address"];
$city=$_POST["city"];
$zip=$_POST["zip"];
////////////////////////////////////////////////////////////////////////////////////////////////////
function sanitize_my_email($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
return true;
} else {
return false;
}
}
$to_email = 'example#gmail.com';
$subject = 'Payment of Marco\'s Window Cleaning Service';
//$message;
$headers = "From: $fname $lname <example#hotmail.com>";//this email is actually my own, as i dont ask for a email, not needed
$message = "I'm your client, $fname $lname and I have paid $amount £ for the Window Cleaning service you have provided me with.
Address: $address
City: $city
Post Code: $zip
**Always confirm the payment and its value on your own paypal account.
Regards, Marco's Window Cleaning";
mail($to_email, $subject, $message, $headers);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
?>
CSS:
#divContainer input{
width: 35%;
padding: 10px;
margin: 6px;
border-radius: 25px;
border: 0,1px solid black;
font-size: 16px;
}
#divContainer input:active{
border-radius: 15px;
}
#divContainer input:focus{
border-radius: 15px;
}
.paypalpaybutton{
cursor: pointer;
background-color: #3671b0;
border-radius: 35px;
width: 370px;
height: 40px;
border: none;
}
.paypalpaybutton:hover{
background-color: #3c7dc3;
}
Only one action can take place at a time.
Which one takes place first, and how it reliably triggers the second action to take place, is a design choice. There are multiple ways to do this, with their own complexities and tradeoffs.
The simplest solution is to create the form that sends you the email, and on the resulting page (or after an ajax/XHR/fetch call that submits the data) have a button so the user can pay. You will get emails for things the user has not paid for yet, and they may or may not follow through with a successful payment, either because they don't click to pay or because their payment is declined.
Having them submit a payment before filling out the form also has disadvantages, since you may receive payments and then not get the information you need.
To not have either of the above disadvantages and keep track of both things in a reliable way you need a server with a database and programming logic, which you need to write.
If you'd rather not write your own, third party tools/plugins may offer an off-the-shelf solution, which you can search for.
I have a hyperlink as shown:
<div style="clear:both"> <a color="grey" accesskey=""style="float: right" href="newbattle.php? userid= <?php echo $id0; ?>"> [<font color="grey">Attack</font>]</a><br></div> <br>
Is it possible, using only only php, to carry POST data? I want to put this
<input type="hidden" name="test" value="<?php echo $number;?>
So I can $_POST['test'] on the other page and get the $number. I can switch over to normal form but I really like what I have
No, that's not possible. If you want to submit a POST request, you should go through a <form> and submit it.
You cannot post through a hyperlink, unless you use JavaScript to capture the click event and simulate a click on a submit button.
But a better approach, I think, would be to make an actual submit button. With a bit of CSS you can style that button to look as if it was a hyperlink. That way, if the CSS fails, you've still got a working button, while if a JavaScript issue would occur, you have a disfunctional link with unexpected behaviour.
input[type=submit] {
display: inline;
border: none;
background-color: transparent;
color: blue;
cursor: pointer;
}
input[type=submit]:hover {
text-decoration: underline;
}
<form action="otherpage.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>">
<input type="submit" value = "Look, I'm a link!">
</form>
A link redirects user to another page, it's purpose is not for get/post requests.
If you want to send a post request on a click, you can do it with a submit button inside form. For example,
<form action="another_page.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>
<input type="submit" />
</form>
Style the button like a hyperlink and it will send a post request as expected.
You can do that using a form.
When the user clicks the link, the form is submitted with the "test" variable and the "userid" variable.
Here's the code:
<form method="post" action="newbattle.php" id="myForm">
<div style="clear:both">
<a color="grey" accesskey="" style="float:right;" href="" onclick="javascript:document.myForm.submit(); return false;">[<font color="grey">Attack</font>]</a>
<br/>
</div>
<br/>
<input type="hidden" name="userid" value="<?php echo $id0; ?>" />
<input type="hidden" name="test" value="<?php echo $number; ?>" />
</form>
For my specific problem, here's what I ended up doing.
href="newbattle.php?userid= <?php echo $id0; ?>&num=<?php echo $number; ?>"
I added the $number on to the hyperlink and then retrieved it with $_GET on the next page
If you want to access test value by $_POST you have to use form like this :
<form action="another_page.php" method="POST">
<input type="hidden" name="test" value="<?php echo $number;?>
<input type="submit" />
</form>
get.php :
<?php
$num = $_POST['test'];
echo $num;
?>
I am making a form that will save to an xml file using php. I have gotten everything to work great, but I want to automatically add a $ to the input field so the user does not have to. How can I start out with a $ as the first character? (Only dealing with whole dollars so I don't need to worry about decimals). This is the simple text input I have made.
<label>Price:</label><br />
<input type="text" name="txtPrice" />
Use ::before in CSS
label::before {
content:"$";
color: blue;
}
<label><input type="text" name="txtPrice" id='input' /></labl>.
Working Demo
Try this:
<label>Price:</label><br />
<input type="text" name="txtPrice" value="$" />
Or this:
<label>Price:</label><br />
$<input type="text" name="txtPrice" value="$" />
I was just having fun with this one, but it puts the $ in the box.
http://jsfiddle.net/NGH7d/3/
Not sure if this will work in IE6-8, also you probably need to adjust the numbers around.
<label class="money">$</label><input type="text" id="txtprice" name="txtPrice" id='input' />
label.money{
color: blue;
float:left;
position:relative;
left:12px;
top:3px;
}
#txtprice {
padding-left:12px;
}
I'm not sure how to ask what I'm looking for to search how-tos. I am building a form and one of the entries requires users to list an appliance, its voltage, watts, amps, phase, etc.
I'd like a simple row with "X" columns providing the text areas for one appliance and then the ability to click a link to 'add another appliance' using jquery/html.
I like using placeholder text to save space on the page. I can get all this set up just fine for a single entry like 'name' however I don't know how to implement an 'add entry' row. All of the data is stored via PHP in MySQL.
So A: What is the name of this type of form section. B: What is it called when we want to let the user add a row to this section?
I love making things harder than they really are. It's my specialty. I guess :)
EDIT: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit
Using this format with 5 columns per entry (though it will all be on one line/row) I'd like to have an "add entry" link which generates a new blank entry option.
#elecNeeds input[type=text], textarea {
font-size: 12px;
font-style: italic;
width: 15%;
height: 20px;
padding: 10px;
color: #212323;
background: #E3E3E3;
background: rgba(255, 255, 255, 0.5);
border: 2px #000 solid;
margin-bottom: 10px;
position: relative;
behavior: url(/js/PIE.htc);
}
<div id="elecNeeds">
<input type="text" name="appliance" placeholder="Type of Equipment">
<input type="text" name="voltage" placeholder="Voltage">
<input type="text" name="watts" placeholder="Watts">
<input type="text" name="amps" placeholder="Phase">
<input type="text" name="notes" placeholder="Notes">
<br /> Add an appliance
</div>
I don't know what's it called, but you probably want this - http://jsfiddle.net/uPWkf/1/
<form method="post" action="#" id="myForm">
<div id="nameFields">
<label>Watt <input type="text" name="watt0" /></label>
<label>Volt <input type="text" name="volt0" /></label>
<label>Amp <input type="text" name="amp0" /></label><br/><br />
</div>
<input type="submit" value="submit" id="submit" />
</form>
Add New Row
and the JS
var i = 1;
$("#addRow").click(function() {
$("#nameFields").append('<label>Watt <input type="text" name="watt' + i + '" /></label><label>Volt <input type="text" name="volt' + i + '" /></label><label>Amp <input type="text" name="amp' + i + '" /></label><br/><br />');
i++;
});
$('#myForm').submit(function() {
var values = $('#myForm').serialize();
alert(values);
});
I think You need to use $(selector).append('<code>'); function. For example:
Add
<table class="my_fuits">
<tr>
<td>Fruit</td>
<td><input type="text" name="fuits[]" /></td>
</tr>
</table>
and js(jQuery) code:
$(document).ready(function(){
// add one more row
$(".add").live('click',function(){
$(".my_fuits").append('<tr><td>Fruit '+$(".my_fruits input").length+'</td><td><input type="text" name="fuits[]" />[X]</td></tr>');
return false;
});
// remove row
$(".remove").live('click',function(){
$(this).parent().parent().remove();
return false;
});
});
Is this method sufficient?
<?php
// User pressed "Register"
if (!empty($_POST['name']) && $_POST['email']) {
if (!empty($_POST['antispam']))
exit("bye");
}
?>
<form>
<input type="hidden" name="antispam" value="" />
Accname: <input type="text" name="name" value="" />
Email: <input type="text" name="email" value="" />
......
</form>
In all basic sense of the idea, sure. Only thing I would recommend for your simple implementation is that most spam scanners that you're trying to block out look for fields titled "username", "name", "user", etc ..
So, isntead of naming your honeypot "antispam" I would name it "username" or something similar that does not conflict with your existing form.
probably the best name for a form-field designed to trigger a spam bot would be url
The chances of a bot parsing the html for type=text attributes or textarea tag a and ignoring all others are quite reasonable.
Your chances of trapping a spambot can be improved with a few extra lines of code:
styles.css:
#commentUrl {
display: none;
}
script.js:
function setFlag() {
document.getElementById('commentUrl').value = 'Javascript check ok';
}
form.html:
<form onsubmit="setFlag();" method="post" action="comment.php">
<label for="commentName">Accname:</label>
<input type="text" id="commentName" name="comment_name" value="" />
<label for="commentEmail">Email:</label>
<input type="text" id="commentEmail" name="comment_email" value="" />
<label for="commentUrl">Url:</label>
<input type="text" id="commentUrl" name="comment_url" value="http://" />
</form>
comment.php:
<?php
if ($_POST['comment_url'] <> 'Javascript check ok' && $_POST['comment_url'] <> 'http://') {
// Let's increase their server load.
header('Location: http://' . $_SERVER['REMOTE_ADDR'] . '/', 307);
}
?>
Because you use three different languages you improve the chances of catching the spammer considerably.
You could improve the javascript by dynamically appending the <link rel="stylesheet" dynamically to the DOM for example.
I wouldn't recommend making the input type hidden or let it have something with "spam" in it. The best way would be to give it a neutral name ("message" maybe) and hide it from the page via css. Additionally I would measure how long it took to fill out the form (as this will be very fast or very slow by robots) by adding a timestamp field (and again give it a neutral name and maybe encode it).
I would not use a hidden field as bots might be looking for only elements of type="text". The naming should be something common but something you have no use for, examples being:
firstname
lastname
email
username
password
bio
description
You should change your input from
<input type="hidden" name="antispam" value="" />
to something more along the lines of
<input type="text" name="username" value="" style="display:none; height: 0; width: 0; border: none; background: transparent; margin: 0; padding: 0;" />