Currently I am using a hidden form (for reasons decided upon by others, not myself) to act as a link so it can post data with itself. This "link" always opens in the same window, and the general tricks I have tried don't let it open in a new tab instead. This is the current code, any tips?
<tr><td>
<form method="post" action="myPage.php" class="inline">
<input type="hidden" name="submit_parassmHidden" value="extra_submit_value">
<button type="submit" name=".$dataIAmPassingToNextPage." value="submit_value" class="link-button">"
.$linkTitle."</button></form>
</td>";
^Took out the escape slashes to be easier to read, its in PHP, its echo so it shows as regular HTML.
Things like target="_blank" dont seem to be working for me or I am putting them in the wrong place. Anyone have ideas on how I could do this?
EDIT: Since people are saying I can't be doing both, this is what I am doing. It LOOKS like a normal link, there is no form, it IS HIDDEN.
"Ok you're saying 2 different things here. The form is either hidden or you can see the submit link. Both can't be true" <- From comments. Clearly it is true, the form is hidden, and you can see the submit link. However I want these "Links" (which are really buttons in disguise) to open in the new tab.
Unfortunately you have not another option.
target="_blank" or button with formtarget="_blank" in HTML5 (like #CD001 comment) is the solution.
_blank Opens the linked document in a new window or tab depending on the user's browser configuration.
But I saw a little trick here: https://stackoverflow.com/a/15551850/2951051
someone who say to use target="_tab" even if not exist (I dont know if it really work)
<tr><td>
<form method="post" action="http://stackoverflow.com" class="inline" target="_blank">
<input type="hidden" name="input_name" value="extra_submit_value">
<button type="submit" name="form_name" value="submit_value" class="link-button">test</button></form>
</td>
Related
I'm relatively new to Delphi, so if the title doesn't match the contents of the question, my apologies. I'm looking to automate a process on a site that submits a form. I believe I've isolated the code from the site which handles this (values edited for account security) which is:
<form action="action.php" method="post">
<p class="center">
<input type="hidden" name="StringOne" value="StringOneB" />
<input type="hidden" name="StringTwo" value="StringTwoB" />
<input type="hidden" name="StringThree" value="StringThreeB" />
<input type="image" src="img/imageone.jpg" />
</p>
</form>
It is the only form on the page. The form is usually submitted via clicking imageone.jpg. The values of the three inputs are generated dynamically. How would I automate submission of this form? I planned to use the internet explorer OleObject. My code currently looks like
procedure TForm1.Button1Click(Sender: TObject);
var
IE: variant;
begin
IE:= CreateOleObject('internetExplorer.Application');
IE.visible := true;
IE.navigate('http://thesite.com');
I have attempted to use the following (each line is a separate attempt):
IE.Document.GetElementByID('StringOne').setAttribute('value', 'StringOneA', 0);
//above won't work because input has no ID
IE.Document.GetElementByName('StringOne').setAttribute('value', 'StringOneA', 0);
//does not appear to be understood
IE.OleObject.Document.forms[0].submit();
IE.OleObject.Document.forms[1].submit();
//does not appear to recognise the form
I've tried countless other lines of code, but none have been fruitful. Can this be done and if so, how? If any code could be explained, it would be helpful, as I am not well versed in OleObject automation. I can ham-handedly get the values from the HTML source, the main focus of the question is simply submitting the form assuming I have the values. Anything else is a bonus. If anything needs to be clarified, just say.
I have made a small HTML search bar that is supposed to be capable of going to any page within the website. The only problem is, it won't leave that page, and if it does, it says the file is not found. Here is the code I have associated with it so far:
<form method="post" action="" name="search">
<input name="search" >
<button type="submit" name="Submit" onclick="window.location='http://localhost:8080/filefolder/<?php echo "'".$_POST[search]."'" ?>'">
Submit</button>
</form>
When you type anything into the search bar, and you click submit, the page just reloads and empties the search bar which is really frustrating.
So this is all that I have associated with the current search bar. What exactly am I doing wrong with it? I even added JavaScript telling the search button to send it to the page typed out. Can someone help me with this? Thank you.
Your code includes extra quotes which I don't believe you intended to have.
For example:
http://localhost:8080/filefolder/<?php echo "'".$_POST[search]."'" ?>'">
Is resulting in:
http://localhost:8080/filefolder/'search''">
As you can see this will break the javascript syntax when it tries to read that string.
Rewrite it as:
http://localhost:8080/filefolder/<?php echo $_POST['search'] ?>'">
Also add a return false to the end.
<button onclick="window.location.href='value_for_url'; return false;" />
When a form has multiple image inputs and the server side uses their names and/or values to distinguish which one was clicked, it works perfectly in FireFox. However, people often write the whole thing before finding out that HTML specifies that nothing has to be sent, and thus some browsers are not sending it.
It's not about sending any random object, but sending a pair as input_name=input_value. The best worst-case scenario example here would be what I've encountered: A list of elements all in one form and all accompanied by buttons with name="delete" value="<item_id>"
What can I do to fix this problem?
Per the HTML spec, clicking on an IMAGE input will return the parameters:
name.x=x-value and name.y=y-value where "name" is the value of the name attribute
with x-value and y-value corresponding to the click position.
Sure, the server code to deal with this will be a little annoying, but you could just check all the query parameter keys with a regular expression:
/^(.*)\.[xy]$/
to search for the IMAGE input keys to determine which IMAGE was clicked.
I tried with this sample:
<form action="#" method="GET">
<input type="text" name="t" value="Text here"><br>
<input type="image" name="a" value="1" src="http://sstatic.net/so/img/logo.png"><br>
<input type="image" name="b" value="2" src="http://www.gravatar.com/avatar/c541838c5795886fd1b264330b305a1d?s=32&d=identicon&r=PG"><br>
</form>
And I get the following urls:
FF 3.6: x.html?t=Text+here&b.x=19&b.y=17&b=2#
IE 8: x.html?t=Text+here&b.x=22&b.y=18
IE 7: x.html?t=Text+here&a.x=185&a.y=51
Opera 10: x.html?t=Text+here&a.x=107&a.y=53#
Chrome: x.html?t=Text+here&b.x=20&b.y=17&b=2#
So it seems that all the browsers are sending something image related, even if it isn't the image name directly. Since you need to scan for all the image names that you expect to see you can just scan for imagename.x instead. This seems to be how the spec indicates it should work.
The problem was half solved up to now: like here
But it didn't allow to get the value!
The correct answer is:
$('input[type=image]')
.unbind('mousedown')
.mousedown(function(){
$(this).after('<input type="hidden" name="'+$(this).attr('name')+'" value="'+$(this).attr('value')+'" />');
});
This code creates a hidden duplicate of the input when user starts clicking it. The unbind('mousedown') is to secure it happens once even if You put the code in multiple places in a weird application and it might be called more than once.
I recommend putting it in $(document).ready();
I think I am/was having a similar problem. I wanted to click on an thumbnail and have it enlarged on a different page. I was trying to do this with PHP alone but I finally had to use the tag with the . Worked great for FF3 and safari but the INPUT IMAGE values did not post for IE9 or FF9.
My work around was to put each image in its own form and then also use a hidden input to send the needed data.
<table>
<tr>
<td>
<form method="post" class="form_photo">
<input type="image" name="img_photo" value="does nothing in IE9 or FF9" />
<input type="hidden" name="photo" value="nameoftheimage.jpg" />
</form>
<form method="post" class="form_photo">
<input ...>
<input ...>
</form>
<form> ...
</td>
</tr>
Then I discovered the forms displayed vertical, making it very odd. CSS to the rescue.
.form_photo { display:inline; }
seems to have solved the vertical problem. Now the user can click on the thumbnail and the value now passes in all the browsers I have access to testing.
Using the type="image" is problematic because the ability to pass a value is disabled for some stupid lack of reason. Anyways & although it's not as customizable & thus as pretty, you can still use you images so long as they are part of a type="button".
<button type="submit" name="someName" value="someValue"><img src="someImage.png" alt="SomeAlternateText"></button>
Is it ok to write like this?
<input type="button" value="New booking" />
The link should look like a button but it should open in the right part of the page. If its wrong, is there any other way to do it?
The above code works fine. i just don't know if its the correct way to do it.
Thanks
No, this is not allowed according to the HTML5 specification.
The <button> element is considered "interactive content".
The <a> element must contain "no interactive content".
The button will probably show up, but since you're violating the specification it may not behave as you want. You should avoid doing this.
The most reliable to way to make a button bring the user to a page is to create a <form> that targets that page, and make the button submit that form.
<form action="add-lead-new.php"><input type="submit" value="New Booking" /></form>
no, the button itself wont do anything - it's only usefull with javascript to trigger any functions.
you should use css to make some of your links like a button: http://www.zurb.com/article/266/super-awesome-buttons-with-css3-and-rgba
<input type="button" value="New booking" onclick="self.frames['rightframe'].location.href='add-lead-new.php'"/>
would be ok
It's better to just use CSS, but if you're really stuck on using a physical button, you can create a dummy form with no data:
<form action="href"><input type="submit" value="Click Here" /></form>
Yours is working but this is better,
<input type="button" value="New booking" onClick="top.frames['rightframe'].src='add-lead-new.php'" />
This is what worked for me.
<a><?php echo( "<button onclick= \"location.href='inc/name_of_php_file.php'\">your buttons name goes here</button>");?></a>
In other words nest your desired php code block inside an anchor element to 'link' it. Then add the php code block and inside that code block you'll want to add an echo(). Inside that echo you want to add your HTML code like normal. As if you weren't even writing in PHP.
Edit the folder name and file to your desired location. And then finally edit what text you want your button to show your viewers.
onclick= \"location.href='folder_name_goes_here/name_of_php_file_goes_here.php'\">your buttons name goes here
This should link to your page with your desired caption.
Please keep in mind the \" as this is utterly important. Without \ in front of the " your code wont read correctly due to the many "s found nested inside each other. \ allows HTML to ignore the first " as an end to the echo Sting.
I try to create an upload progress bar with PHP and jQuery. However, I have a problem when I bring it to the form data. The code is similar like this:
<form method="post" action="upload.php" enctype="multipart/form-data" id="upload-form" target="upload-frame">
Suburb:<input type="text" name="txtSuburb" id="txtSuburb">
Picture:
<input type="hidden" id="uid" name="UPLOAD_IDENTIFIER" value="<?php echo $uid; ?>">
<input type="file" name="file">
<input type="button" name="submit" value="Upload!">
<iframe id="upload-frame" name="upload-frame">
</iframe>
<input type="submit" name="DataSubmit" value="Submit Data"/>
</form>
As you can see, I got 2 submit buttons. If I keep the form like this then the form can't submit data to server. It just submits the file to iFrame. If I change the action and target of the form then the upload progress function will not work.
Could anyone please help me to find the solution for this?
I want the user can click on upload button to upload their file. Then they can take the rest to fill the form. When everything is done, they can click on another submit data button to submit their data (included the file) to the server.
Make sure that you have only one input element of type submit within your form.
If you want the first button to trigger some Javascript, use a regular input element or even a styled link and attach a Javascript event to it's onclick event, then prevent it's default behavior, e.g. by returning false.
Like this only the second button will actually submit your form which should do what you're describing.
In general I'd second #Treffynnon's suggestion to use a existing library for this purpose. These hacks have a tendency to get pretty nasty, especially when it comes to crossbrowser compatibility.