-2

I want to send a variable via POST. The variable should not be in the URL like in this formular:

    <form action="index.php?content=contact" method="POST">
        <a class="article-input-a">Name:</a><br><input name="name" type="text"  maxlength="30"><br>
        <a class="article-input-a">E-Mail Adresse:</a><br><input name="email" type="text"  maxlength="30" placeholder="beispiel@email.de"><br>
        <a class="article-input-a">Website:</a><br><input name="website" type="text" maxlength="40" placeholder="www.beispiel-website.de"><br>        
        <button class="button" name="submit" type="submit">Beitrag erstellen</button> 
</form>

In this formular i can send the variables, but i dont see them in the URL. And i can get the variables over $_POST['name']. Now i want to send the variable $random with the formular submite button.

I hope you can undestand me.

Skeptar
  • 27
  • 3
  • Are you *wanting* to see the variable in the URL? If so, use GET. If not, use a `` input. – Jonathan M Feb 09 '15 at 19:40
  • Have you looked here?: http://stackoverflow.com/questions/18820013/html-form-php-post-to-self-to-validate-or-submit-to-new-page – David Dietz Feb 09 '15 at 19:42
  • you're using POST. the form fields will never show up in the url, because they'll be in the message body. – Marc B Feb 09 '15 at 19:48

3 Answers3

2

To see them in your URL you need to use GET not POST.

   <form action="index.php?content=contact" method="GET">
    <a class="article-input-a">Name:</a><br><input name="name" type="text"  maxlength="30"><br>
    <a class="article-input-a">E-Mail Adresse:</a><br><input name="email" type="text"  maxlength="30" placeholder="beispiel@email.de"><br>
    <a class="article-input-a">Website:</a><br><input name="website" type="text" maxlength="40" placeholder="www.beispiel-website.de"><br>        
    <button class="button" name="submit" type="submit">Beitrag erstellen</button>   

To send the variable, add

<input type=hidden name='random' value="<?php echo $random; ?>">

This will make a hidden variable that will be submitted.

Then access using $_GET['random']. But it will be in your URL as ?Name=&E-Mail=&Website=

Antony D'Andrea
  • 991
  • 1
  • 16
  • 35
0

if i understand correcty you want hidden inputs

<form action="index.php?content=contact" method="POST">
    <a class="article-input-a">Name:</a><br><input name="name" type="text"  maxlength="30"><br>
    <a class="article-input-a">E-Mail Adresse:</a><br><input name="email" type="text"  maxlength="30" placeholder="beispiel@email.de"><br>
    <a class="article-input-a">Website:</a><br><input name="website" type="text" maxlength="40" placeholder="www.beispiel-website.de"><br>        
    <input type="hidden" name="content" value="contact" />
    <input type="hidden" name="verName" value="varValue" />
    <button class="button" name="submit" type="submit">Beitrag erstellen</button>   
</form>

sending variables as part of the url is a GET request, not a POST request

then you access like

$_POST['varName']
Ricardo Garza V.
  • 899
  • 1
  • 11
  • 26
0

to send that variable, you need to create a hidden field, that hold the value of that random number <input type=hidden value="<?php echo $random; ?>">

Oussama Elgoumri
  • 609
  • 1
  • 5
  • 15