url rewrite for submit in php - php

Do anyone know how can I rewrite a URL in php for the submit action?
Example:
I have a code as following:
I call to the page by using the following link www.assignment.com (I have set the index to test.php) and test.php will display the following code.
<form action="test.php" method="post">
<input type="text" name="phone" value="">
<input class="submit_btn" type="submit" name="submit" id="submit" value="SUBMIT">
</form>
when I clicked on the submit button, it will post to test.php to do the action and the display the same input page. However once submit button been clicked, the url link will become www.assignment.com/test.php. any way that I can rewrite the url to www.assignment.com after submit instead of www.assignment.com/test.php?

If your test.php is run when http://assignment.com/ is loaded, you could just change the form target to:
<form action="/" method="post">

You could use header("Location: www.assignment.com"); at the end of your test.php script.

Related

Making File when Href clicked

I want to make a file when the link is clicked. Can I do this using PHP?
Click Here
Use a form to do this and when it is submitted direct it to the php script that will create the file.
<form method="post" action="/make_file.php">
<input type="submit" Value="Click here">
</form>

Passing variable in a URL not working

So as usually I put in information in the url leading towards another page like this:
<form action="index.php?type=question">
<input class="log-btn extra" type="submit" value="Home">
</form>
Usually it always works, I even copy pasted it because I've used the exact same url before and on the other page it works but doesn't on this one it just returns empty after the questionmark like this:
index.php?
When you want to misuse a Button as a link with URL query parameters you can do it in two ways.
In your example you try to set query parameters in the action attribute of the form. That is working as long as the method is not get, because get-parameters and URL query is exactly the same thing and submitting the form will overwrite the query with the get parameters of the form elements.
<form action="home.php?type=question" method="post">
<input class="log-btn extra" type="submit" value="Home">
</form>
You can also set <form method="get"> and use a button:
<form action="home.php" method="get">
<button type="submit" name="type" value="question">Home</button>
</form>

Button functioning as link does not work with $_GET

I am using a button to function in the same way as a hyperlink:
<form action="intro.html"><input type="submit" value="CLICK HERE TO ENTER" ></form>
This works for static links, but does not work with PHP $_GET arguments.
<form action="wrong_choice.php?stage=0"><input type="submit" value="Wrong Choice!" ></form>
Clicking that will proceed to "wrong_choice.php" but not "wrong_choice.php?stage=0"
How can I fix that?
Thank you
Better to use:
<input type="button" value="Wrong Choice!" onClick="document.location.href('wrong_choice.php?stage=0');" />
If you do not want javascript, add method to form, delete parameter from action and add input with type hidden, which stands for parameter.
Action does not accept query string!
If you want to append data into the form which isn't part of the inputs filled by the user, add inside the <form>
<input type="hidden" name="stage" value="0" />
Action is what you want to do with the information in the form: you want to send the form in a email or send the information to another script to manage or comeback to same script.
If you want pass arguments in the form you should put them in form's fields like that:
<form action="wrong_choice.php>
<input type='hidden' value='0' name="stage">
<input type="submit" value="Wrong Choice!" >
</form>
Thanks

How to post form variables with javascript, just like a type="submit" button

I'm a noobie programmer and I wonder how to properly submit a form with javascript.
I made some test code to show you what I mean:
<?php
if (isset($_POST['message']))
{
echo $_POST['message'];
}
?>
<script>
function formsubmit()
{
document.getElementById('form').submit();
}
</script>
<form id="form" name="form" action="" method="post">
<input id="message" name="message" value="hello world">
<input id="submit" name="submit" type="submit">
</form>
Click me<br/>
<input type="submit" onClick="formsubmit()" value="Click me">
When you push the "submit" button inside the tags - the php code will echo "hello world".
When submitting the form with JS the values won't post to the page. What am I doing wrong?
Thanks in advance.
I've searched the whole afternoon for a solution, but cause of my lack of knowledge about programming I failed to find it.
Believe it or not, but the main problem lies here:
<input id="submit" name="submit" type="submit">
If a form contains an input element with name (or id) of submit it will mask the .submit() method of the form element, because .submit will point to the button instead of the method. Just change it to this:
<input name="go" type="submit">
See also: Notes for form.submit()
The smaller problem is here:
Click me<br/>
An empty anchor will just request the same page again before calling formsubmit(). Just add href="#".
The problem here is that the id and name of the input element on your form is called submit.
This will mask the submit function for the form. Change the name and id and you will be able to use javascript to submit the form.
try setting the href of the to '#'. I would guess what is happening is that by clicking on the link, it submits the form and immediately changes the url to the same page you are on cancelling the form submit before it has a chance to go.

Loading form values from one IFrame to another

What I want to achieve is the following. A search is made from one IFrame "the form is loaded into this frame via the src atribute of iframe" the search query is then passed to another IFrame that redirects to a url with the query eg. www.test.com/index.php?query=test
Is this possible?
Currently my code looks as such
<iframe src="abc.php" name="iframe1">
</iframe>
<iframe name="iframe2">
<?php
var_dump($_GET);
?>
</iframe>
abc.php contains the following
<form method="get" action="#" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>
Untested (don't have PHP installed on this machine).
You are passing your submission form back to itself, and loading the result into iframe2, which is why you just see that form again in the other frame. So what you need to do is put your form processing logic into a second .php file, instead of inside your iframe tags, and then have the form's action be abcd.php (or whatever) and keep the target as iframe2.
Try this.
<form method="get" action="<?php $_SERVER['PHP_SELF']?>" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>

Categories