<form method="POST" name="send"
<input type="hidden" name="title" value="<?php echo ($pro->title;?)">
</form>
I dont want people to see the hidden informations , Is this the best way to pass the variable over to my controller?
This the code in my controller
$this->email->subject('subject '.$_POST['title'].' ' );
Thank you!
<form method="POST" name="send"
<input type="hidden" name="title" value="<?php echo ($pro->title;?)">
should be
<form method="POST" name="send">
<input type="hidden" name="title" value="<?php echo $pro->title; ?>" />
For this i will suggest you to use SESSION because hidden fields can be changed.
Related
When I click submit, the data is submitted to the database but the URL id of the book disappears to ----book.php
I want the URL to go back to the id of the page e.g. ----book.php?id=3
Is it possible to keep the first line as action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" and add the value="<?php echo $book_id ?>"?
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" value="<?php echo $book_id ?>" name="book_id" />
<p>Author: <input type="text" value="<?php echo $_SESSION['author']; ?>" name="author" id="author" readonly /></p>
<p>Summary: <input type="text" name="summary" value="<?php echo $summary;?>" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
PHP code:
if (isset($_GET['id'])) {
$book_id = $_GET['id'];
}
Please try this code:
// save values in DB
header('Location: book.php?id=' . $book_id);
exit;
It is because $_SERVER["PHP_SELF"] contains only URL . It does not contain get queries . To solve the problem leave your action empty
e.g
<form method="post" action="">.....
You send a POST form but are trying to retrieve a GET value. Additinally, the parameter is named book_id, not id.
Use $book_id = $_POST['book_id'];
if (isset($_GET['id'])) { also won't work, for the same reasons.
There is no name with "id"
If you want to get the book id:
if (isset($_POST['book_id'])) {
$book_id = $_POST['book_id'];
}
OR modify the HTML like this:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input type="hidden" value="<?php echo $book_id ?>" name="id" />
<p>Author: <input type="text" value="<?php echo $_SESSION['author']; ?>" name="author" id="author" readonly />
</p>
<p>Summary: <input type="text" name="summary" value="<?php echo $summary;?>" /></p>
<p><input type="submit" name="submit" value="Submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
On the other hand, if you have problems with POST, just modify the first line of HTML for this one:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . echo $book_id; ?>">
You can use anyone of these:
PHP_SELF returns just URL. Use REQUEST_URI that returns URL with query string:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["REQUEST_URI"]);?>">
[you can also omit action values - that will have same behavior]
or if you want just id, then use:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) . "?id=" . $_GET['id'];?>">
Note: Use validation wherever necessary. I just gave you an idea.
In this page : page.php?id=value
I've this html's code:
<form action="" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
It's redirect me to: page.php?key=value , i want to redirect to: page.php?id=value&key=value , how i can do it? I must redirect it to this page with PHP ?
simply,
<form action="page.php" method="get">
<input type="hidden" name="id" value="<?php echo $value ?>">
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
You can have the id as a hidden input in your form
<form action="" method="get">
<input type="hidden" value="<?php echo $my_id; /*Suppose this variable contain your value */ ?>" name="id" />
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
put everything you want on the next page in your form:
<form action="page.php" method="get">
<input type="text" name="id" value="<?php echo $_REQUEST['id'];?>" />
<input type="text" name="key" />
<input type="submit" name="send />
</form>
Really though, you should be using POST to send data, and the above code is NOT secure (allows anything in a url to easily end up in a form that could create some sql injection or XSS type issues.
You need to have the form's action set to the page you want it to submit to. If it is blank it will just submit to the same page.
<form action="page.php?id=value&key=value" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
I have tried to put this code in my webpage but I have this error :
Parse error: syntax error, unexpected '?' in E:\MyServer\htdocs\...(line 1 from this script)
CODE :
<form action='delete.php?name="<?php echo $contact['name']; ?>"' method="post">
<input type="hidden" name="name" value="<?php echo $contact['name']; ?>">
<input type="submit" name="submit" value="Delete">
</form>
this code is in a .php page
Thanks.
Try to format it properly:
<form action="delete.php?name=<?php echo $contact['name']; ?>" method="post">
<input type="hidden" name="name" value="<?php echo $contact['name']; ?>">
<input type="submit" name="submit" value="Delete">
</form>
How to get the value you pass through your form:
Welcome <?php echo $_POST["name"]; ?><br>.
EDIT
Also you should add this in delete.php file:
if(isset($_POST['name'])){ $name = $_POST['name']; }
See : http://www.w3schools.com/php/php_forms.asp
You need to drop the double quotes around the variable name and move them to the actual element property.
<form action='delete.php?name="<?php echo $contact['name']; ?>"'
^ ^
It then becomes
<form action="delete.php?name=<?php echo $contact['name']; ?>"
<form action="delete.php?name=<?php echo $contact['name']; ?>" method="post">
<input type="hidden" name="name" value="<?php echo $contact['name']; ?>">
<input type="submit" name="submit" value="Delete">
</form>
This should work ..
Do you need to send the data via GET and POST to delete.php?
<form action='delete.php' method="post">
<input type="hidden" name="name" value="<?php echo $contact['name']; ?>">
<input type="submit" name="submit" value="Delete">
With this you can then just do $_POST['name'] to get your contact name...
Sorry if I have missed something but cannot see why you would need it passed twice
How do I check the url if it has a parameter or not before passing?
I need to pass the value of s on current page.
When passing on current page 'index.php' it would look like this index.php?s=value
How can i pass the value if the url has parameters like index.php?page=1 or index.php?orderby=asc so when i press the search button it would be something like this index.php?page=1&s=value or index.php?orderby=asc&s=value
<form method="get">
<p class="search-box">
<label class="screen-reader-text" for="user-search-input">Search Members:</label>
<input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search">
<input type="submit" name="" id="search-submit" class="button" value="Search Members">
</p>
</form>
Use php, you can output the param in the form as a hidden value, e.g. to keep the page param
<form method="get">
<input type="hidden" name="page" value="<?php echo htmlspecialchars(isset($_GET['page'])? $_GET['page']:''); ?>" />
Keep the htmlspecialchars when using $_GET['page'], or you will face XSS attacks.
Here, in action whole url will be placed.
<form method="get" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
You should keep current page as a `action along with query string, so that extra parameters will be added at last.
YOu have to include the page incomming parameters in the "action" attribute of you tag.
<?php
if(isset($_GET['s'])
{
*dostuffwiths
"echo <input type='hidden' name='s' value='$s'>";
}
else
{
echo "<input type='hidden' name='s' value='$s'>";
}
?>
Try this
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="GET">
<p class="search-box">
<label class="screen-reader-text" for="user-search-input">Search Members:</label>
<input type="search" id="user-search-input" name="s" value="" size="30" placeholder="Search">
<input type="submit" name="" id="search-submit" class="button" value="Search Members">
</p>
</form>
I met a trouble with a form.
In fact I have a php dynbamic page which has 1 parameter (and id), I'm trying to get an other parameter, so I have this fom:
<form action="index.php?p=employee-monitoring&id=<?php echo $_GET['id'] ; ?>" method="get">
<fieldset>
<legend>CHOISIR UNE DATE</legend>
<label>Date:</label>
<input type="date" name="date" onblur="form.submit()" />
</fieldset>
</form>
But when I choose a date it redirection me to index.php and there is no parameter on the date, for example it redirect me to this page /index.php?date=
I do not understand what did I wrong have done.
receive all my utmost Respect.
Kind Regards.
SP
Add a hidden field and remove &id=<?php echo $_GET['id'] ; ?> from the action attribute.
<form action="index.php?p=employee-monitoring" method="get">
<fieldset>
<legend>CHOISIR UNE DATE</legend>
<label>Date:</label>
<input type="date" name="date" onblur="form.submit()" />
<input type="hidden" name="id" value="<?php echo $_GET['id'] ; ?>" />
</fieldset>
</form>
Actually, you should pass p=employee-monitoring the same way:
<form action="index.php" method="get">
<fieldset>
<legend>CHOISIR UNE DATE</legend>
<label>Date:</label>
<input type="date" name="date" onblur="form.submit()" />
<input type="hidden" name="id" value="<?php echo $_GET['id'] ; ?>" />
<input type="hidden" name="p" value="employee-monitoring" />
</fieldset>
</form>