0

How can I fill out a form from the address field of my browser?
http://someform.php/fill out actionfield in form

What I want with this is to fill in this:

<input method="post" action="the input from addresfield of the browser">

This is if I want to use the same form but redigert anser to different e-mails. Why because we are several teachers using the same form and we use a QR code to get to the form, but we need to sort out which teacher instead of redirecting to the right one.

Oldskool
  • 34,211
  • 7
  • 53
  • 66

3 Answers3

0

You can use querystrings to achieve that. By the look of it, you have a PHP form. PHP has the $_GET superglobal to access anything from the querystring.

For example, you could link the form to: http://example.com/someform.php?action=add.php. Then in your form code you can do:

<form method="post" action="<?php echo $_GET['action']; ?>">

That way, whatever value you set in the ?action= bit of the URL will be set as the form action.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
  • Thanks for fast reply. I was a bit in a hurry when I asked. My form is in a html document so I tried this: http://index3.html?action=contactengine.php And I changed my
    "> Will this still be correct?
    – nine1one4u Jun 26 '15 at 08:32
0

if you develope with pure javascript i will give you some tricks about it. i think first you can read this:

How to get the value from the URL parameter?

then read this:

How to set form action through JavaScript?

Now you have some idea about your question. If you can not merge these issues, i give you an example.

.
.
.
<script type="text/javascript">
var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(pair[1]);
    }
  } 
    return query_string;
} ();
</script>
.
.
.
<script type="text/javascript">
//to set form's action
    window.onload = function() {
        document.myform.action = QueryString['action'];
    }

</script>
.
.
.
<script>
//to see the effect
document.write(QueryString.action);
</script>
.
.
.
<form method="post" name="myform">
<input type="submit" value="Submit">
</form>
.
.
.
Community
  • 1
  • 1
caslaner
  • 403
  • 3
  • 6
0

I did like your solution, but when I tried it it didn't work. I get this answer "The requested URL /dentrafikkskolen/< was not found on this server." And in the address bar it says:

    http://my_site/dentrafikkskolen/%3C?php%20echo%20$_GET[%27action%27];%20?%3E
    
I did put the "form metod="post" action=?php echo $_get['action']; ?" in the html site.

This is how the setup is: The for is inside a html site wich is sendt to contactengine.php that sends the e-mail and redirect to a thanks.php site.

<pre>
<form method="post" action="<?php echo $_GET['action']; ?>">
<fieldset>
<legend><span class="number">1</span>Info om deg</legend>
<input type="text" name="Name" placeholder="Ditt Navn *">
<input type="text" name="Mobil" placeholder="Ditt Mobil nummer *">
<input type="text" name="Dob" placeholder="Din Fødselsdag *">
<legend><span class="number">2</span>Ditt valg</legend>
<label for="valg">Hva ønsker du å ta:</label>
<select id="TofD" name="TofD">
<optgroup label="Førerkort:">
<option value="Moped" data-image="icon/moped.png">Moped</option>
<option value="Bil" dat-image="icon/bil.png">Bil</option>
<option value="B96">B96 Tilhenger</option> 
<option value="BE">BE Tilhenger</option>
</optgroup>
<optgroup label="Kurs:">
<option value="1hjelp">Førstehjelp</option>
<option value="tgk">Trafikalt grunnkurs</option>
<option value="last">Lastesikring</option>
</optgroup>
</select>      
</fieldset>

<input type="submit" value="Send" />
</form>

Contactengine.php

<?php
header("Content-Type: text/html;charset=UTF-8");
$EmailFrom = "elev@dentrafikkskolen.no";
$EmailTo = "jarle@dentrafikkskolen.no";
$Subject = "Ny elev";
$Name = Trim(stripslashes($_POST['Name'])) ; 
$Mobil = Trim(stripslashes($_POST['Mobil'])); 
$Dob = Trim(stripslashes($_POST['Dob'])); 
$TofD = Trim(stripslashes($_POST['TofD'])); 

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Navn: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Mobil: ";
$Body .= $Mobil;
$Body .= "\n";
$Body .= "Fødselsdag: ";
$Body .= $Dob;
$Body .= "\n";
$Body .= "Eleven har valgt: ";
$Body .= $TofD;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "Fra: <$EmailFrom>\r\nContent-    Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit");

// redirect to success page 
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error2.htm\">";
}
?>