Is there a way to get the value of the name attribute in the form tag? I'm using PHP and don't see it in $_POST.
Is there a way to get the value of the name attribute in the form tag? I'm using PHP and don't see it in $_POST.
No, the form's name attribute is never set to sent to the server as part of the POST data.
The easiest way around this would be adding a hidden form element <input type="hidden"> containing the name.
<form name="myform" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="frmname" value=""/>
</form>
<form name="wut">
<input type="hidden" name="name" value="wut"/>
</form>
Related
<form id="form1" name="form1" align="center" action="http://www.test.org/add-listing/?listing_type_id=test" method="POST" enctype="multipart/form-data">
<input type="file" Value="UPLOAD RESUME" id="UploadResume" name="UploadResume" >
<br>
<input type="submit" Value="Upload Resume" id="SubmitResume" >
</form>
I am trying to post form data to another page; however, it seems like it is trying to go to
http://www.test.org/add-listing
instead of
http://www.test.org/add-listing/?listing_type_id=test
is there something i'm missing here?
You form method is POST so you can't pass data through GET (URL)
If you want to pass that value, you can use hidden inputs :
<input type="hidden" name="listing_type_id" value="test">
You will be able to get it on the other side with $_POST["listing_type_id"]
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>
How do I pass hidden information about a form?
<form action="index.php" method="post">
<textarea rows="2" cols="30" NAME="com" >
</textarea>
<input type="submit" name="com_submit" value="com" />
</form>
I need see that the comment is passed for which type of post so I need to pass the value of variable $type also by this form so how should I do that?
I am a beginner so i am sorry if i am asking any stupid question?
Use a hidden field:
<input type="hidden" name="form_type" value="theFormType" />
The user will not see hidden inputs on the form.
If the value of the hidden form comes from php, you can use this:
<input type="hidden" name="form_type" value="<?php echo $type ?>" />
if i understand correctly you want to use the hidden input
hidden input a great summary from w3schools
Is there an easy way to find out the source of a post variable in PHP?
Form on example.com/formone.php
<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>
Form on example.com/formtwo.php
<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>
I understand that I could use a hidden input, but I was wondering if PHP had a method to test the source of the POST.
While you could potentially use the HTTP_REFERER server variable, it is not very reliable. Your best bet would be to use a hidden field.
Another alternative would be to switch out your submit input for a submit button. This way you can pass a value with it, retain the button's label, and test for that inside your test.php page:
<button name="submit" type="submit" value="form1">Submit</button>
In your PHP file you would then test:
if( $_POST['submit'] == "form1" )
// do something
I use a form to send some data to my welcome.php file:
<form action="welcome.php" method="post">
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
But, is it possible to send other variables instead of just form element values? Let's say I want to send the number 100 to welcome.php as well.
You would probably use a hidden input:
<form action="welcome.php" method="post">
<input type="hidden" name="myNumber" value="100" />
Name: <input type="text" name="txt" />
<input type="submit" />
</form>
That would send the myNumber $_POST value to welcome.php.
Modifying the action like this: welcome.php?myNumber=100 would mean that you are sending a GET variable in addition to the POST variables inside the form.
NOTE: You could theoretically use both, but I believe that would only put the $_POST value in the $_REQUEST object. You should confirm that before relying on that behavior.
If I understand correctly:
<input type="hidden" name="myNumber" value="100" />
Right?
other then hidden fields or form element you can use AJAX to send other variables into the post.
where you can pass url with your new variables other than form fields.
Thanks.
You can hardcode that into your action:
<form action="welcome.php?number=100" method="post">
This should work:
<form action="welcome.php?number=100" method="post"/>
or use a hidden form input
<input type="hidden" name="number" value="100" />
You can use html hidden field or store the value what you want in session or cookie varible