full email id passing in url - php

i am new to php .i am trying to develop a application with html and php.
i passed variable from form to url.all code given below
<FORM METHOD="get" ACTION="action1.php">
Type your first name: <INPUT TYPE="text" NAME="FirstName"> <br/>
Type your last name: <INPUT TYPE="text" NAME="LastName"> <br/>
Type your email:<INPUT TYPE="email" NAME="email">
<INPUT TYPE="submit" VALUE="Click and See">
</FORM>
the output url is http://example.com/action1.php?FirstName=jon&LastName=Kuri&email=xyz%40abc.com
but i want it to be http://example.com/action1.php?FirstName=jon&LastName=Kuri&email=xyz#abc.com
How to do it.
Thanks in advance for any suggestion.
update:
<?php
$email="xyz#gmail.com";
$decode=urldecode($email);
?>
<FORM METHOD="get" ACTION="action1.php">
Type your first name: <INPUT TYPE="text" NAME="FirstName"> <br/>
Type your last name: <INPUT TYPE="text" NAME="LastName"> <br/>
Type your email:<INPUT type="hidden" NAME="email" value="<?php $decode; ?>">
<INPUT TYPE="submit" VALUE="Click and See">
</FORM>
This also does not give me the required result.here i am pre defining email value.

Urls are encoded, that's why # becomes %40, it comes from the way data is sent from the form/ If you use get method, this is how it will be formated in the url.
But don't worry, what you get in php is correct and decoded.

You are simply seeing certain characters encoded to be URL safe (like #).
When you examine the data server-side it will look like the original data on the form. You don't have to decode anything, PHP does it for you automatically.
From the docs:
The superglobals $_GET and $_REQUEST are already decoded.
Try to echo $_GET['email'] in PHP and you'll see xyz#abc.com again.

Your code is incorrect as you are decoding an already decoded email.
<?php
$email="xyz#gmail.com";
$decode=urldecode($email);
// # should be encoded as %40
?>
should be:
<?php
$email="xyz%40gmail.com";
$decode=urldecode($email);
// returns "xyz#gmail.com"
?>
As stated in other answers, php will in most cases take care of this for you, however if you're trying to test your code with strings the above is necessary. Alternatively you could encode your email string too:
<?php
$email="xyz#gmail.com"; // no encoding here
$decode=urldecode(urlencode($email));
// returns "xyz#gmail.com"
?>

Related

Php send post vars in form

if i put this : NO WORKS
<?php
if($_POST['send']=="ok")
{
print $_POST['opt']['nombre']
}
?>
<form action="" method="post" style="margin:0px;">
<input type="text" name="opt['nombre']" value="Hello" />
<input type="hidden" name="send" value="ok">
</form>
If i Put this : WORKS
<?php
if($_POST['send']=="ok")
{
print $_POST['opt']['nombre']
}
?>
<form action="" method="post" style="margin:0px;">
<input type="text" name="opt[nombre]" value="Hello" />
<input type="hidden" name="send" value="ok">
</form>
Why Happend this , the only change it´s in input file this opt['nombre'] by opt[nombre]
I don´t understand why happend this, it´s possible fix this problem because i want put opt['nombre'], and i think it´s the right
When works the result i get it´s "Hello" but only change this symbol inside tags as [''] by []
DIFFERENCES WORKS AND NO WORKS WHEN SEND POST FORM :
SEND FORM AND DON´T GET HELLO
<input type="text" name="opt['nombre']" value="Hello" />
SEND FORM AND GET HELLO
<input type="text" name="opt[nombre]" value="Hello" />
DIFFERENCE PUT INSIDE [] QUOTES AS 2 OR DON´T PUT, THANK´S
var_dump($_POST) and take a look at the keys. You'll see the difference. The single quotes in the HTML name attribute become part of the string key in the PHP array when you do it the first way. You'd have to access it with the single quotes as part of the string to get it.
print $_POST['opt']["'nombre'"];
Or better yet, just do it the second way, so your PHP code won't have to use a silly key like that. :-)

What is the difference between POST and GET in HTML/PHP [duplicate]

This question already has answers here:
When should I use GET or POST method? What's the difference between them?
(15 answers)
What is the difference between POST and GET? [duplicate]
(7 answers)
Closed 9 years ago.
I am coding a PHP script, but I can't really seem to get it to work. I am testing out the basics, but I don't really understand what GET and POST means, what's the difference? All the definitions I've seen on the web make not much sense to me, what I've coded so far (but since I don't understand POST and GET, I don't know how to get it to work:
<form name="mail_sub" method="get">
Name: <input type="text" name="theirname"> <br />
Email: <input type="text" name="theirpass"> <br />
<input type="submit" value="Join!" style="width:200px">
</form>
<?php
if (isset($_POST['mail_sub']))
{
echo $_POST['theirname'];
}
?>
$_POST isn't working for you because you have the form method set to get.
<form name="mail_sub" method="post">
There's plenty of better info online as to the difference between post and get so I won't go into that but this will fix the issue for you.
Change your PHP as well.
if ( isset( $_POST['theirname'] ) ) {
echo $_POST['theirname'];
}
To answer the question:
GET and POST are one of the many request types in the standards of internet.
The difference is that GET can't post data, parameters will be appended to the url (url-parameters) which has it's limitations. POST does post parameters/data.
The standard is:
GET for getting data.
POST for creating data.
PUT for updating data.
DELETE for removing data.
replace
isset($_POST['mail_sub'])
by
isset($_POST['theirname'])
The main difference between GET and POST requests is that in GET requests all parameter are part of the url and the user sees the parameters. In POST requests the url is not modified and all form parameter are hidden from the user. If you have no file uploads or very long field parameter use GET. Use POST when going in production.
Post is like "sending" the data to the page without giving the user having any interaction with it, when Get shows the parameters in the URL and making it public for the user. Get is more often used on "unsecure" type of datatransactions like for example a searchform and POST is used when you want to make more secure things like a login form.
Using a Get will give you like
index.php?parameter=hello&parameter2=world
In your example you should use either POST in the method attribute in the formtag or $_GET in the php section
So either
<form name="mail_sub" method="post">
Name: <input type="text" name="theirname"> <br />
Email: <input type="text" name="theirpass"> <br />
<input type="submit" value="Join!" style="width:200px">
</form>
<?php
if (isset($_POST['theirname']))
{
echo $_POST['theirname'];
}
?>
or
<form name="mail_sub" method="get">
Name: <input type="text" name="theirname"> <br />
Email: <input type="text" name="theirpass"> <br />
<input type="submit" value="Join!" style="width:200px">
</form>
<?php
if (isset($_GET['theirname']))
{
echo $_GET['theirname'];
}
?>
GET - If form method is GET then on submitting the form, Form will be submitted to
xyz.com/submit.php?theirname=john&theirpass=password // CHECK HERE - form elements are in URL so not so secure
and can be checked by PHP
as
if(isset($_GET['their']))
{
$name=$_GET['their']; //name will return John
}
POST - If form method is POST then on submitting the form, Form will be submitted to
xyz.com/submit.php // CHECK HERE form elements are not in URL
and can be checked by PHP
as
if(isset($_POST['their']))
{
$name=$_POST['their']; //name will return John
}
you used method as GET in form,so your code should be like this
<?php echo $_SERVER['PHP_SELF'];?>//the form and action will be same page
<form name="mail_sub" method="get" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="theirname"> <br />
Email: <input type="text" name="theirpass"> <br />
<input type="submit" value="Join!" style="width:200px">
</form>
<?php
echo $_GET['theirname'];
?>
Replace Your Code:
<form name="mail_sub" method="post">
Name: <input type="text" name="theirname"> <br />
Email: <input type="text" name="theirpass"> <br />
<input type="submit" name="submit" value="Join!" style="width:200px">
</form>
<?php
if (isset($_POST['submit']))
{
echo $_POST['theirname'];
}
?>

I cant post my textbox value to another page

Hi this is my first aplication .It is self explained code. I think I have missed out something I am trying to change some chars to other but I think I couldnt .because I am just getting a blank page
this is control.php
<?php
function donustur($karakter){
$tk=array("ç","ş","ö");
$ik=array("c","s","o");
$ykarakter= str_replace($tk,$ik,$karakter);
return $ykarakter;
}
$ad=donustur($_POST['adi']);
$mesaj=donustur($_POST['mesaj']);
echo "ad : ".$ad;
echo "ad : ".$mesaj;
?>
this is index.php
<form action="control.php" method="post" enctype="text/plain">
adi : <input type="text" value="adi" size="10" /><br />
soyadı<textarea cols="30" rows="30"
wrap="virtual" maxlength="10" name="mesaj"></textarea><br />
<input type="submit" value="submit" />
</form>
You have at least two problems.
First, see the documentation for plain text form data:
Payloads using the text/plain format are intended to be human readable. They are not reliably interpretable by computer
PHP cannot interpret form data submitted as plain text.
Remove the enctype attribute to use the default encoding type (application/x-www-form-urlencoded).
The only time you should specify the enctype is when you are including file inputs in the form, in which case you need to use multipart/form-data.
Second, a form control can only be successful if it has a name. Add a name attribute to your text input.
<input type="text" name="adi" value="adi" size="10">
Finally, even with those problems, I don't think you should get a blank page. (I don't think any of the errors are critical enough to make PHP bail out). You should get output of:
ad : ad :
If you don't, then the odds are that the file is not being processed with PHP at all. Make sure that you are:
Running a web server that supports PHP
Loading the HTML documents by pointing your browser at http://yourserver/ and not something like file:///c:/foo/bar/index.php
I cleaned it up as best I could considering I don't understand the base language. Hope this helps!
control.php
<?php
function donustur($karakter){
$tk=array("ç","ş","ö");
$ik=array("c","s","o");
$ykarakter= str_replace($tk,$ik,$karakter);
return $ykarakter;
}
if (isset($_POST['adi']) $ad = donustur($_POST['adi']);
if (isset($_POST['mesaj']) $mesaj =donustur($_POST['mesaj']);
echo "ad : ".$ad;
echo "ad : ".$mesaj;
?>
index.php
<?php
<form action="control.php" method="post">
adi : <input type="text" value="adi" size="10" /><br />
soyadı: <textarea cols="30" rows="30" wrap="virtual" maxlength="90" name="mesaj"></textarea><br />
<input type="submit" value="submit" />
</form>
?>

keep form value after submit it

I know there are lots others question like this and i found 1.000 answer on the web but none of those work with my code :(
So can someone help me with how to keep email value after submit?
<form name="login-registration" onSubmit="return validateForm()" method="post" action="" >
<label>Email</label>
<input type="email" name="emailinput" id="emailinput" value ="" />
<p id="emptyEmail" class="hidden">Email field is required</p>
<p id="invalidEmail" class="hidden">Email you insert is invalid!</p>
<label>Your password</label>
<input type="password" name="pswinput" id="pswinput" value=""/>
<p id="pswMinMax" class="hidden">Password should be from 4 to 8 caracters</p>
<p id="pswLettNum" class="hidden">Password should be letters and numbers. No special caracters are allow</p>
<label>Repeat password</label>
<input type="password" name="pswrepeatinput" id="pswrepeatinput" value="" onblur="isValidPswRep()"/>
<p id="pswR" class="hidden">Your passwords is different</p>
<input type="checkbox" id="policy" name="policy" value="policy" /> <label>I agree</label>
<p id="checkN" class="hidden">You must agree to our term</p>
<input type="submit" name="submit" value="Login" />
</form>
I try to put some code like:
<input type="email" name="emailinput" id="emailinput" value = "<?php echo htmlspecialchars($_GET['lastname']); ?>" />
But that php line is just displayed inside the field input.
try using $_POST['lastname'] instead of $_GET['lastname']
1)If i am not wrong,i don't see any field with name="lastname" in your code above.
2)Use $_POST because you are posting your form data with method="post".
Assuming that your file have .php as extension and php is installed on your server i would like you to notice that you have an error because you used a POST form while when you apply value to your input field you are trying to use $_GET Further more you did not assign lastnameto any input field, so use emailinput as you apply to this field name="emailinput". You should change htmlspecialchars($_GET['emailinput']); to be htmlspecialchars($_POST['emailinput']);
So your code would look like this
<input type="email" name="emailinput" id="emailinput" value = "<?php echo htmlspecialchars($_POST['emailinput']); ?>" />
This should print your variable inside your input field
There are at least 2 problems there.
The fact that the php is displayed inline suggests that either you have wrong file extension (like the comments suggested), either file is not included in your "know how to read by php" (for lack of a better way to say it, my English is not perfect) directory.
You echo a get when you sent a post (as other answer suggested)
Also... WHY DOES YOUR QUESTION HAVE JS TAG (sorry for caps, wanted to be sure it sticks out)?

How do I retrieve a PHP variable in my HTML code?

I call a PHP script from my HTML form submit.
Then I process the values retrieved from this HTML form in the PHP script and now I want to display these values in another HTML form that I am calling from this PHP script.
How do I retrieve this variable?
Note: I tried echo but I think I actually want to display this value in the form (HTML) and not break it again in a PHP tag.
I'm not sure what you mean by "not breaking it again with a PHP tag". HTML on its own cannot access PHP variables. This is because PHP is a server-side language and HTML is a client side language. But here is the simplest way to print php variables retrieved from a form.
<form>
<p>Your name: <?php echo $_POST['name'] ?></p>
</form>
This is assuming that there was a form that submitted a field called 'name' using POST.
You can process the name in a php script at the top of the file and then simply echo it when you're printing the html. This way, you won't have too much php code mixed in with the HTML (which makes it look cleaner).
Once you got the values in the PHP script, are you calling a new script? If so, you might wanna save the values in $_SESSION["varible_name"]. If not, you just have to echo it.
It depends on how you are accessing your form data, either through $_POST or through $_GET. For simplicity, I'll assume your using $_GET and modify this example for more clarity.
So lets say you have a form hosted on welcome.php:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Now the results will be returned back to the same page, so you want to modify the page to say:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" value="<?php echo $_GET["fname"]; ?>"/>
Age: <input type="text" name="age" value="<?php echo $_GET["age"]; ?>" />
<input type="submit" />
</form>
Though you'll notice that we're using the same page, and we can only have one version of the page, so we want to render if upon the condition that our variable has been set.
if (isset($_GET["fname"])){
//code to print second form
}
else{
//code to print first form
}
Or, in another way (using the ternary operator):
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" value="<?php echo ((isset($_GET["fname"]))?$_GET["fname"]:""); ?>"/>
Age: <input type="text" name="age" value="<?php echo ((isset($_GET["age"]))?$_GET["age"]:""); ?>" />
<input type="submit" />
</form>

Categories