HTML Button: Redirect on click - php

<input type='submit' name='submit' value='Register' class='register' />
how do I make this link to a website on click?

Here's one way of doing it with your present code (submit-type button) using PHP's header() function.
(handler.php)
<?php
if(isset($_POST['submit'])){
header("Location: http://www.example.com/page.php");
exit;
}
And I'm assuming with the code you have in your question, resembling something to the affect of:
<form action="handler.php" method="post">
Username:
<input type='text' name='username' />
<input type='submit' name='submit' value='Register' class='register' />
</form>
Of course I didn't include the possible $username=$_POST['username']; that could be in your PHP, depending on how you will be using it.
EDIT
Upon reading mplungjan's comment have made a slight name change. I've yet to know why using the name submit is considered unsafe, after trying to find the (or a) reason why on Google. I'm hoping to get or find an answer to this affect.
(Edit-findings) See further information below that I found to date.
(handler.php)
<?php
if(isset($_POST['reg_button'])){
header("Location: http://www.example.com/page.php");
exit;
}
And I'm assuming with the code you have in your question, resembling something to the affect of:
<form action="handler.php" method="post">
Username:
<input type='text' name='username' />
<input type='submit' name='reg_button' value='Register' class='register' />
</form>
Findings:
Article(s) I've come across on the subject that mplungjan mentioned in comments:
Why is the NAME attribute considered unsafe?
Cross site scripting
On php-security.org
If you're going to use a PHP (server-side) method, consider using the following, as borrowed from this website's article on Cross site scripting.
<input name="foo" value="<?php print htmlspecialchars($foo); ?>">
and in your case:
<input type='submit' name='reg_button' value='<?php print htmlspecialchars($reg_button); ?>' class='register' />
Borrowed from mplungjan's comment:
1) never call a submit button name="submit"
2) use a link or a button <input type="button" onclick="location='somepage.html'" />
3) Just use name="Submit" or submitted and problems will be avoided.
(Thanks for the extra input mplungjan).

You have to understand the default behavior of the tag you're using. The submit input tag, sends the user to the form action. I'm not sure what you're trying to do, so I'm not sure if you're even using the right tag. Perhaps consider anchor tags?
My best guess, given the vague question is:
<form action="{URL}" method="post">
<input type='submit' name='submit' value='Register' class='register' />
</form>
or
Register

<input type="button" onclick="window.location='YourUrlHere'" class="register" value="Register"/>

You can use anchor tag for this problem, An anchor tag is used to redirect from one page to another page by just one click.
Here you can use this as follow:
<input type='submit' name='submit' value='Register' class='register' />
Note: href is the tag which contains the path of your desired destination.
That's it,
Keep coding... :)

You can go for a Register as just said or if you want you can also use the button tag <button onclick="myFunction()">Click me</button> where myFunction is your JavaScript code to an other page

Related

How can I submit parameters with an HTML script?

I am having trouble submitting parameters to a website via an html code simulating an XSRF attack. I have the html below in which I have set the parameters for the action including an account #, routing #, action, and a value that need to reverse engineer through source code that represents the users session.
When ran, the site either returns "Changes Saved" indicating a successful XSRF attack or returns "XRSF Blocked" indicating I did not derive the fourth value correctly.
However, when I log in to the site and execute the script, nothing is returned and even the page forms are unchanged. I think something in my syntax is probably slightly off. Can someone assist?
<!DOCTYPE html>
<html>
<meta charset="UTF-8"/>
<title>XSRF</title>
</head>
<body onload='document.forms[0].submit();'>
<form action='some_php_file.php' method='POST'>
<input type='hidden' name='action' value='save'/>
<input type='hidden' name='account' value='3192332'/>
</form>
</body>
</html>
Your inputs have no closing tags.
<input type='hidden' name='action' value='save'
<input type='hidden' name='account' value='3192332'
In order to post information, you need a submit input:
<form action='some_php_file.php' method='POST'>
<input type='hidden' name='action' value='save'/>
<input type='hidden' name='account' value='3192332'/>
<input type="submit" name="name" placeholder="placeholder"/>
</form>
Hope this helps :-)

Passing value with a button in the form

I am trying to pass a value through clicking a button that is inside a form.
Below is my code:
<form action=deleteProduct.php?skuCode=".$row["skuCode"]." method=get><input type=submit name=delete value=Delete></form>
But from the above code I wanted to get the skuCode=".$row["skuCode"].". Instead the value passed was delete=Delete.
How should I amend my code to get the skuCode in deleteProduct.php.
Try this one :
<form action="deleteProduct.php" method="get">
<input type="hidden" value="<?php echo $row["skuCode"] ?>" name="skuCode">
<input type="submit" value="Delete">
</form>
In the deleteProduct.php page, you can access the value by using $_GET['skuCode']
It seems you may be outputting it all in a single echo. In this case, the solution will require a few extra lines, so it'd probably be best to change it to:
//close off PHP if required
?>
<form action="deleteProduct.php" method="get">
<input type="hidden" value="<?php echo $row['skuCode'] ?>" name="skuCode">
<input type="submit" value="Delete">
</form>
<?php
//resume PHP if need be
Something to that effect should work.
I'm not 100% sure how your $row["skuCode"] part works.. I guess it's PHP? Either way, just insert the value however you need to, but that HTML should do it.
Fiddle:http://jsfiddle.net/rt9yc/
In this jsfiddle, when I click on the delete button with the network tools open in my inspector I see a request for: deleteProduct.php?skuCode=testSKU ("testSKU" being the dummy SKU I was using in the fiddle)

add query on href using input

I have an
<input type=text name=search />
and I wanted to add the value of input to my href
<a href='index.php?search=$search>submit</a>
But I think that won't work on php alone right?
How can I add the value of my input to my href as it clicks?
NOTE: need to appear in the browser url menu this way
index.php?search=anyvalue
as soon as they click it. because I'm using pagination
Straight HTML - no PHP or JavaScript Needed
<form action="index.php" method="get">
<input type="text" name="search" />
<button type="submit">Submit</button>
</form>
Once clicked it will take the user to: index.php?search={value of input}
For pagination to work it would be:
Page 2
Page 3
try this:
<form method="get" action="index.php">
<input name="search" type="text" />
<input type="submit" />
</form>
If that's not what your looking for just elaborate a bit on what you are trying to achieve.
you must open a php tag like this:
<a href='index.php?search=<?php echo $search;?>' >submit</a>
but it work after submitting the form.
use javascript

PHP $_POST is empty on IE9 and IIS7

The following form causes an empty $_POST variable on IE9.
<form id='login' action='login.php' method='POST' accept-charset='UTF-8'>
<input type='text' name="username" id='username' />
<input type='password' name='password' id='password' />
<input type="text" name="store" />
<input type='submit' name='Submit' value='Submit' />
</form>
The form works perfectly on Firefox and Chrome. All variables appear in the $_POST variable with no issues.
On IE9, however, the form is submitted properly, but $_POST is the empty array. I.e., in login.php:
print_r($_POST);
prints the empty array. I'm trying to figure out what could be different about IE9 that's making it behave differently from Firefox and Chrome and I can't figure it out.
I found mention of some module under Apache that's causing people problems, but I'm running IIS7, not Apache, so that's not it. Someone on a Ruby forum mentioned setting a DisableNTLMPreAuth to 1 in the registry, but that hasn't fixed it either.
Any help is appreciated.
accept-charset is not support in Internet Explorer. Remove it and see if that solves you're problem.
I think this is to do with a double hit - i.e. that IE is re-reloading the page somehow. Have you got some client side stuff (jQuery?) that re-reloads the page by accident as a bug? Try posting to a completely new page and writing <?PHP die ('<pre>'.print_r($_REQUEST,true).'</pre>');?> on the top line and seeing what happens.
plz enter "name" attribute for form.
<form id='login' name='login' action='login.php' method='POST' accept-charset='UTF-8'>
<input type='text' name="username" id='username' />
<input type='password' name='password' id='password' />
<input type="text" name="store" />
<input type='submit' name='Submit' value='Submit' />
</form>
The reason is you are not maintaining the session. In Firefox and Chrome are much smart and they maintain the session irrespective of the Development of the Code, which gives users a good things. But in IE6-9, IE Can't maintain session, developer has to check it and if the session is not maintained every page loaded is a new session and thus there is no post.

Submit form using only PHP? Without JavaScript?

I have a form
<form method='post' action='action.php' name='myForm'>
<input type='' name='id' value='id'>
<script>document.myForm.submit();</script>
</form>
Can I submit this form without using JavaScript - only PHP without clicking on the submit button, automatically?
This form must be auto submitted on page load, but not using JavaScript (without onload)
The act of form submission is done on the client side (browser) and has very little to do with PHP (server side).
You could add a submit button like <input type='submit' value='click here to complete step' />
A form must be submit, by the client side. On client-side, there's only two way: by Javascript or by human (clicking on the submit button).
Why not just use the <input type="submit" /> like the following:
<form method='post' action='action.php' name='myForm'>
<input type='text' name='id' value='id' />
<input type='submit' name='submission' value='Submit id'>
</form>
add a submit button.
<input type="submit" value="Submit" />
Unfortunately, what you are trying to do is not possible. The best you can do is probably this:
<form method='post' action='action.php' name='myForm'>
<input type='' name='id' value='id'>
<input type='submit' id='submit-button' />
<script>domument.getElementByID('submit-button').style.display="none";document.myForm.submit();</script>
</form>
A submit button is displayed when client side scripting is disabled. When it's enabled, the submit button is immediately hidden and the form is automatically submitted.
EDIT
Or you could simply include the PHP file. <?php include action.php; ?>. You won't have access to the _POST array, but considering, the client hasn't had chance to enter any data, that won't really matter.

Categories