saffa — 2014-03-08T10:17:14-05:00 — #1
Hi guys and girls.
First post on here.
Im not new to coding. Can code more than sufficiently in SQL, SAS, VB and Pascal (many years ago).
I have a basic form created where someone is required to enter a stock/share code into it.
I want to take this answer and add that to a website URL.
For example someone types share code SOL, i want that to feed into the website's URL and when the answer is submitted the formaction is then the modified URL containing the give share code of SOL.
So the original site is say... www.sharetracker.co.za/quote/
What I want to do is when someone enters SOL in the form, the formaction URL should read www.sharetracker.co.za/quote/SOL
But for the life of me I cannot reference the answer given in the form into the formaction URL.
Read up on php stuff and echo and the $ used to reference answers but I am lost when it comes to HTML and php coding rules.
Dont laugh here is what I tried.
$Cname = $_POST["Code"];
<form action=""http://www.sharenet.co.za/quote/" method="post">
<p style="color:rgb(0,0,0)">Stock of Interest (Supply share code): <input type="text" name="Code" ></p><br>
<input type="submit" formtarget="_blank" value="Submit" echo formaction="http://www.sharenet.co.za/quote/$code.">
See the red parts where I tried to echo and reference.
Any help would be greatly appreciated
rubble — 2014-03-08T10:29:34-05:00 — #2
<form method="post" action="http://www.sharenet.co.za/quote/<?php echo $code; ?>">
<input type="submit" value="Submit">
Your code is a bit mixed up as you are using get for the URL part and post as well.
You will need to get the code from the URL and it is not a variable; so this will not work.
// get the variable from the URL
$Cname = $_GET["code"];
rubble — 2014-03-08T10:38:55-05:00 — #3
Lets start again - you are submitting your form to a folder called quote and not a php page according to your URL. What is the php page called?
saffa — 2014-03-08T11:03:45-05:00 — #4
Oh sorry it reads"<form action="c:\site\code.php"
Now how do I tell the code to go fetch the submitted value from that file into the URL and then running that URL
As I said I can code in a few languages but html and php is greek to me
saffa — 2014-03-08T11:06:55-05:00 — #5
john_betong — 2014-03-08T11:19:15-05:00 — #6
The only way I can see to solve your problem is:
test to see if your $_POST['testing'] variable has been set.
if it is set
save $_POST['testing'] to $newUrl value.
redirect page with $newUrl
fall through and set the $newUrl ($_POST['testing']) parameter
<?php if(isset($_POST['testing'])): // $_SERVER['REQUEST_URI'] should be the page URL // $_SERVER['SCRIPT_NAME'] should ALSO be the page URL
$newUrl = 'http://' .$_SERVER['SERVER_NAME'] .'/' .$_SERVER['REQUEST_URI'] .$_POST['testing']; $newUrl = str_replace(' ', '-', $newUrl); // replace spaces with dashes $_POST['testing'] = NULL; // reset to prevent loop
header('Location: ' .$newUrl); // recall this page or send to another page endif; ?><!doctype html><head></head><body>
<h4>Cosmetic to display $_POST and/or $_SERVER parameters</h4> <pre style="background-color:#cff"> <br /> <?php print_r($_POST);?> <?php # print_r($_SERVER); // shows all parameters?> <br /> </pre>
<form action="?" method="post"> <p style="background-color:#cfc"> <br /> Set your URL parameter here: <input type="text" name="testing" value="parameter_goes_here" /> <input type="submit" formtarget="_blank" value="Submit" /> <?php // echo formaction="http://www.sharenet.co.za/quote/$code." ?> <br /> </p> </form></body></html>