How to submit HTML label using a URL parameter? - html

I have the following code:
<input type="submit" class="button" value="<?php yourls_e( 'shorten!!!!! ヾ(≧▽≦*)o', 'isq_translation'); ?>">
(dont mind the php it is just for translation)
I want to be able to submit this input through a URL parameter. Example: https://example.com/?submit=true or something like that. Is there a way to do this?

Give the input a name. It can't be a successful control without one.

Related

php mail / submit a variable span

I am trying to submit a <span> value to be mailed through php.
I want to submit the variable span res1:
<form method="POST" name="results" action="message.php">
<span id="res1">Mail This:*this part varies*</span>
</form>
using this handler:
$body .= $_REQUEST['#res1']." \n";
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
I'd prefer for the <span> to not be in the form; i'm not sure if this is possible though?
Excuse my ignorance - never worked with server side stuff before! Thanks to anyone who can help me!
How does this part varies get to the span? Use the same instruction to add a
<input type="hidden" name="res1" value="the same value you put in the span"/>
Then, in your PHP code you can get the value with $_REQUEST['res1'] or $_POST['res1'] -- note the removed hash.
Update
For anybody who might make a similar mistake, here is what would work and what wouldn't.
HTML forms only send the values of form controls when submitted. They are:
inputs of various types (text, password, radio, checkbox, hidden, file, submit, image, or newer HTML5 inputs like email, etc.)
selects
textareas
Furthermore, the value of an input is only submitted if it has been assigned a name. So if the following inputs are in a form, on submitting the form whatever value bugs may have will be submitted, but nothing will be submitted for bunny:
<input type="text" name="bugs"/>
<input type="text" id="bunny"/>
So, putting any element between <form> ... </form> does not cause the text inside it to be submitted. For a value to be submitted it should be one of the above form controls AND it should have a name property set.
You can do this:-
<form method="POST" name="results" action="message.php">
<input type="hidden" id="res1" value="some text" />
</form>
You can use javascript to access and change "res1"
document.getElementById("res1").value=some variable or textbox content;

how to: question mark in form action

I want to use a button to link to a page. However, the page url is something like domain.com/page?action=register.
I really need this action added to my:
form action="domain.com/page?action=register"
Form attribute, but when I try it with these settings, it will only go to domain.com/page
I've tried encoding the ? into %3F but that doesn't work.
Any help?
The ? values are set by the form, as long as the form's method is set to "get" (rather than "post", which doesn't submit the values in the URL). So, if you want to submit a form to page?action=register, you'd do the following:
<form action="domain.com/page" method="get">
<input type="hidden" name="action" value="register">
It will also pass the other form values along in the URL, creating something like:
domain.com/page?action=register&first_name=john&last_name=doe
EDIT: As #ninetwozero mentioned in a comment, the scenario you describe above should work:
<form action="domain.com/page?action=register" method="post">
[rest of form]
I just tested the above and it passed both the ?action=register and the form values from my form. So, whichever you prefer.
Is "domain.com/page" the page that has the form and button?
Make sure that your button is like this:
<input type="submit" />
Not
<input type="button" />
Otherwise, you could actually use input type "button" with a javascript redirect.
<input type="button" onclick="location.href="domain.com/page?action=register" />
In fact, why use a bunch of form elements if all you want is a button to send you to another url?
<form>
<input type="button" onclick="location.href="domain.com/page?action=register" />
</form>
Not sure if you even need the tags really. Try it.

Stop the 'submit' button value from being passed via GET?

I'm trying to pass form information via GET - this is important so that people can send the filtered data from their form selections to other people.
The problem is, using the code below, it not only passes the filter information, but also the submit form value like so: index.php?month_filter=Feb&year_filter=12&Submit=Filter+Table
<form name="filter_form" action="<?php echo CURRENT_PAGE ?>" method="get">
<input name="Submit" type="submit" class="button" value="Filter Table">
Long shot, but is there a way to remove the submit button from the URL? Thanks!
If you remove the name attribute, it will not get passed through in GET/POST.

onclick="myform.submit()" doesn't work; says method doesn't exist

I'm trying to trigger a form submission from clicking on a link, and I'm using this as a guideline:
<form name="badger" action="http://www.quietdean.com">
</form>
submit
I have
<form name="epb" method="post" action="entry.php">
//I'm using CSS to make the link look like a button without being ugly like a button
<a class="edit_button" href="#" onclick="epb.submit()">Edit</a>
<input type="hidden" name="pid" value="<?php echo $contents[0] ?> ">
<input type="hidden" name="descrip" value="<?php echo urlencode(htmlspecialchars($contents[1], ENT_QUOTES)) ?>">
</form>
All of the html is generated correctly by the php (I've run this in multiple browsers), including the values of the hidden inputs, but when I click on my link I get the following error:
Uncaught TypeError: Object #<HTMLCollection> has no method 'submit'
Can anyone help me figure out what's going wrong here?
I've tried putting the link outside the form as well but that doesn't fix it.
I've also tried taking out the class attribute of the <a>, but it still gives me the same error.
I've now also tried document.forms['epb'].submit() to no avail.
This line needs to be closed:
<input type="hidden" name="descrip" value="<?php echo urlencode(htmlspecialchars($contents[1], ENT_QUOTES)) ?>">
It's corrected here.
Then take a look at what #m.edmonson and #Vitor42 said. It's correct.
badger isn't an object, but just the name of the form... You should get that form as an object, and then invoke submit() on it.
Try adding badger as an id to the form (<form name="badger" id='badger' action="http://www.quietdean.com">) and using document.getElementById("badger").submit();. I don't think badger is being found, or if it is it's not the element you are thinking it is. Also make certain there aren't any other elements on the page that have an id of 'badger'.
You need your onclick attrubte to look like this:
onclick="document.forms['epb'].submit();"
Add id="epb" to your form, and then do this:
submit
I got the same error, while the problem was the following:
I typed <from> tag instead of <form>.
-.-"

html append text value to form action

I have a form, text input and a submit button. How do I append the value of the text box to the form action i.e.
action="https://www.mywebsite.com/" & txtSessionId
The form looks like this:
<form name="form1" method="post" action="https://www.mywebsite.com/">
<label>Your Sessions ID:
<input type="text" name="txtSessionId" id="txtSessionId">
</label>
<label>
<input type="submit" name="btnContinue" id="btnContinue" value="Continue">
</label>
</form>
I want the link to look like this: https://www.mywebsite.com/123456
where 123456 is typed into the text box by the user.
Thank you
You'd have to either use javascript or something server-side to do that (or both).
Javascript:
<form name="form1" method="post" action="https://www.mywebsite.com/"
onsubmit="location.href = this.action + this.txtSessionId.value; return false;">
Server-side (PHP)
if (!empty($_POST['txtSessionId']))
{
header('Location: https://.....' . (int)$_POST['txtSessionId']);
exit();
}
The correct behavior is to send the input field to the existing form, process it, and redirect. You don't know if the user sent a valid input value yet!
In this cases I always recommend javascript unless accessibility is an strict requirement for you.
I assume you are using something like mod-rewrite on your server if you are accepting URLs like this. So, why not just write a rule on there to check if txtSessionId is set and then re-write it to whatever you'd like?
I don't know how to write mod-rewrite rules all that well, but, I definitely know you can do it.
If you're using PHP, Greg did present a fairly viable alternative to using mod-rewrite (or something similar).