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>
Related
I am trying to create a button, which downloads a file, and this file is created based on php variables.
The "instruction" to show this html code is inside a php file.
So far, I've got this ( donĀ“t think it's ok ):
Inside the php this generates an email:
$addressforics = get_valueFromStringUrl($_SERVER['HTTP_REFERER'], 'address');
ob_start();
<form method="post" action="/download-ics.php">
<input type="hidden" name="date_start" value="2017-1-16 9:00AM">
<input type="hidden" name="date_end" value="2017-1-16 10:00AM">
<input type="hidden" name="location" value=$addressforics>
<input type="hidden" name="description" value="This is my description">
<input type="hidden" name="summary" value="This is my summary">
<input type="hidden" name="url" value="http://example.com">
<input type="submit" value="Add to Calendar">
</form>
$my_var = ob_get_clean();
How to insert the php variable $addressforics into the HTML code ( which is inside the same php code, where $addressforics is defined )?
You have to write the php code between <?php and ?>, as documented here.
Something like..
<?php
$addressforics = get_valueFromStringUrl($_SERVER['HTTP_REFERER'], 'address');
ob_start();
?>
<form method="post" action="/download-ics.php">
<input type="hidden" name="date_start" value="2017-1-16 9:00AM">
<input type="hidden" name="date_end" value="2017-1-16 10:00AM">
<input type="hidden" name="location" value="<?php echo $addressforics; ?>">
<input type="hidden" name="description" value="This is my description">
<input type="hidden" name="summary" value="This is my summary">
<input type="hidden" name="url" value="http://example.com">
<input type="submit" value="Add to Calendar">
</form>
<?php
$my_var = ob_get_clean();
?>
to write php value into html element
<input name="test" value="<?php echo $a ; ?> ">
or
<?php echo "<input name='test' value='".$a."'>"; ?>
I am creating a pizza ordering site with php. Now I want to echo the variable passed through the URL within the form. I know how to retrieve this data: <?php echo $_GET["numpizzas"]; ?>. But I don't know the proper way to add it to my html form field. any help is much appreciated
<?php
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="<?php echo "hi"; ?>" >
//Money field does not populate with number, I just see <?php echo $_GET[
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
?>
<?php echo $_GET["numpizzas"]; ?>
I also tried storing the integer in a variable $howmanypizzas = $_GET["numpizzas"]; ?>but it still doesn't show up as the field value.
<?php echo $_GET["numpizzas"]; ?> does not only retrieve the data. echo also outputs it to the html response (the screen)
since you are allready passing your html with an ECHO, you can do:
<?php
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="'.$_GET["numpizzas"].'" >
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
?>
Explanation: echo is a function that recieves a string and outputs it to html.
So, with the concatenation operator . you can inject the $_GET["numpizzas"] variable into your html, as a string, and pass it to the echo function, wich outputs it to the browser.
Another way to solve it is to only invoke PHP where you need to process your logic, just like #pavithra answer, wich also works.
You're already echoing and trying to echo inside of that. You need to concatenate your variable with the string that you are echoing, see PHP Strings:
echo
'<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label><input type="text" name="money" value="' . $_GET["numpizzas"] . '">
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>';
You might also consider Heredoc syntax.
<input type="text" name="money" value="<?php echo $_GET["numpizzas"]; ?>" />
but i dont get why do you get this is as a get variable.hope this works
<form action="pizza.php" method="post">
<h1>Thanks for Ordering. Please submit your delivery info.</h1>
<label>Name:</label> <input type="text" name="name">
<label>Address:</label> <input type="text" name="address">
<label>Phone:</label> <input type="text" name="phone">
<label>Money: </label> <input type="text" name="money" value="<?php echo $_GET["numpizzas"]; ?>" />
<label>Feedback:</label> <input type="text" name="feedback">
<input type="submit" value="Submit">
</form>
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>
Im having issues with a ''profile'' page where users will be able to change their username, email, name, password and so on but it seems to have conflicts when i have more than 1 form on the page as they all work individually?
I could be missing something obvious so if anyone could help id much appreciate it.
Base
<?php
require 'core/init.php';
include 'includes/overall/header.php';
?>
<h1><p>Hello <?php echo escape($user->data()->username); ?></a>!</p></h1>
<h4><p>You joined the MMOunition community <?php echo escape($user->data()->joined); ?></a></p></h4>
<alert_banner>
<?php
if(Session::exists('home')) {
echo '<p>', Session::flash('home'), '</p>';
}
?>
</alert_banner>
<br />
<form action="changeusername.php" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changepassword.php" method="post">
<div class="field">
<label for="password_current">Current password:</label>
<input type="password" name="password_current" id="password_current">
</div>
<div class="field">
<label for="password_new">New password:</label>
<input type="password" name="password_new" id="password_new">
</div>
<div class="field">
<label for="password_new_again">New password again:</label>
<input type="password" name="password_new_again" id="password_new_again">
<input type="submit" value="Change">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
</br>
<form action="changename.php" method="post">
<div class="field">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo escape($user->data()->name); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<br />
<form action="changeemail.php" method="post">
<div class="field">
<label for="email">Change email address:</label>
<input type="text" name="email" id="email" value="<?php echo escape($user->data()->email); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</div>
</form>
<?php
include 'includes/overall/footer.php';
?>
Hello You haven't mentioned what problem you actualy facing but this seems like the problem is the unique identification of a form at server side
Please see this post
Multiple HTML Forms on One Page
Hope this will help ;)
Have each form action set to the current page, and use hidden inputs to determine what action is being taken. Using this method will prevent the user from being dropped onto a different page, and puts the action being taken into a variable that you can use or manipulate.
If you want to have separate PHP scripts for actual functions, use includes or requires.
<form action="" method="post">
<div class="field">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="<?php echo escape($user->data()->username); ?>">
<input type="submit" value="Update">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<input type="hidden" name="action" value="changeUsername">
</div>
</form>
Then the PHP script gets the action from the POST and uses a switch to determine which functions to call.
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
switch ($action) {
case "changeUsername":
changeUsername();
break;
case "changePassword":
...
As mentioned, if you want to have these functions in separate php files, you can use include or require.
This conveniently drops the user right back on the same page when they update information, so that they can make additional updates.
<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.