i am submitting form using get method to a url which already contain parameter like
localhost/myfile.php?section=console
my form code is
<form method="GET" action="<?=basename($_SERVER['PHP_SELF'])?>/section=console">
<input type="text" name="cmd" />
<input type="submit" value="execute" />
</form>
when i submit this data through post type it submit data then it submit like myfile.php?cmd=blahblah
but i want to submit it to myfile.php?section=console&cmd=blahblah.
i can do this by using hidden field but i am insearch of other better way
Simply add a hidden field into your form
<input type="hidden" name="section" value="console">
If you are not interested in using hidden fields then rewrite your form like this
<form method="GET" action="<?php basename($_SERVER['PHP_SELF']) ?>/?section=console">
You should use a hidden input within your form
<form method="GET" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="hidden" name="section" value="console">
<input type="text" name="cmd">
<input type="submit" value="execute">
</form>
Related
I have the following form that is dynamically generated:
<form action="index.php?route=module/print_wizard/showPrintSheet&token=4ef5f4af6ba25d6096357fdb4809e819" method="post" enctype="multipart/form-data" id="form">
<input name="[print][6][1]" type="hidden" value="on">
<input name="[print][6][3]" type="hidden" value="on">
<input name="[info]" type="hidden" value="INV-GIS-00002-3">
<input name="[layout_override][6][1]" type="hidden" value="">
<input name="[layout_override][6][3]" type="hidden" value="">
<input name="[bundle_override][6][1]" type="hidden" value="">
<input name="[bundle_override][6][3]" type="hidden" value="">
<input name="[run_id]" type="hidden" value="14040455">
<button type="submit">Export</button>
</form>
My PHP code is:
var_dump($_POST);
echo "<HR>".$this->request->server['REQUEST_METHOD'];
I have done this a million times before and can not for the life of me figure out why my $_post array is empty. I have changed my post to a get and all the fields and values are passing, but I need to use a post. Do I need to have one visible form element? Please help!
You are not using valid names for your form fields:
<input name="[print][6][1]" type="hidden" value="on">
is not valid as it just has an array index but no name.
If you change it to for example:
<input name="print[6][1]" type="hidden" value="on">
it will work without any problems.
So I am having an issue. I used POST to send data to a new page. I use get to send data to a function but it seems the POST data get wiped. Here some code to help explain.
POST CODE to send to form vieworder (works perfect!)
<form method="post" action="vieworder.php">
<input type="hidden" name ="user_id" value="<?php echo $_SESSION['user_id']; ?>">
<input type="hidden" name ="id" value="<?php echo $data1[$x]['id']; ?>">
<input type="submit" name="submit" value="View"> </td>
</form>
So on the vieworder page I want used to be able to update the data using this form.
This form works as well except i need that value "id" from the orginal post. It works and the "id"has the data until I use this form.
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type="submit" value="Approve" action="">
</form>
I would also prefer to use the POST method but using GET was my first solution to no deleting the data from POST.
Anyways I then just send the data to a function to update two fields.
Any way to get correct the code?
<?php
$id=$_POST['user_id'];
?>
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type='hidden' value='<?php echo $id;?>'>
<input type="submit" value="Approve" action="">
</form>
I have this javascript line
<script type="text/javascript">document.write(top.location);</script>
and this code
<form action="rating.php" method="post">
<input type="hidden" name="url" value="xxxx" />
<input type="submit" />
</form>
<?
echo $_POST["url"];
?>
Please, How i can add the value of javascript (xxx) in the hidden field?
Also does it possible to let <input type="submit" />have automatic submit ?
Thanks
Do you mean this, in order to feed the hidden field?
<input type="hidden" name="url" value="<? echo $_POST["url"]; ?>" />
Regarding submit, you can use javascript to handle the submit event:
If you add the attribute name="FORMNAME" inside the <form ... > tag, you can use:
document.FORMNAME.submit();
for submitting the form, without using the submit button.
In order to feed a hidden field through javascript, use:
document.FORMNAME.url.value = top.location;
I have a very simple GET form with one text field:
<form action="blah" method="get" name="blah" onsubmit="blah">
<input type="text" name="page" value="blah" />
</form>
What I want is to get the current submitted value from the url:
$page_value = $_REQUEST["page"];
but this will only get the previous submitted value, not the current one.
<form action="blah" name="blah" onsubmit="blah">
<input type="text" name="page" value="<?=htmlspecialchars($_GET['page'])?>" />
</form>
I'm trying to build a form using php & jquery, but I'm a little confused as to what to do with the jquery portion of it...
Basically, when the user submits the first form, I want to direct them to the "next step" form, but I want to retain the values submitted from the first one in a hidden input field...
If someone can either show me how or point me to a good tutorial, I'd appreciate it...
I don't have any of the php or jquery yet, and this is just a simplified version of the html markup...
//first.php
<form name="form1" method="post" action="second.php">
<input type="text" name="name" value="" />Name
<input type="submit" name="step1" value="Next" />
</form>
//second.php
<form name="form2" method="post" action="process.php">
<input type="hidden" name="name" value="{$_POST['name']}" />
<input type="text" name="message" value="" />message
<input type="submit" name="step2" value="Finish" />
</form>
<input type="hidden" name="name" value="{$_POST['name']}" />
should be,
<input type="hidden" name="name" value="<?php echo $_POST['name']}; ?>" />
and also sanitize the input, if you want
I don't no if there is a better way to do that.
But, when I need to do such thing, I do in this way:
<script>
<?php
foreach($_POST as $key => $valule)
{
echo "$('$key').val('$value')";
}
?>
</script>
So, in your nextstep file, all you'll need to do is set up the hidden fields and then just loop through the post vars and set each one via jquery.