简体   繁体   中英

getting url value in input box

In my html page, i have links like this

<table width="100%" border="0" cellspacing="4" cellpadding="4">
          <tr>
            <td><a href="ApplicationRegister.php?plan=trial"><img src="images/box4.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan1"><img src="images/box1.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan2"><img src="images/box2.png" width="230" height="300" /></a></td>
            <td><a href="ApplicationRegister.php?plan=plan3"><img src="images/box3.png" width="230" height="300" /></a></td>
          </tr>
        </table>

When i click on any one of the image, it will go to ApplicationRegister.php page with plan= corresponding values.

In my ApplicationRegister.php i have a registration form

<form action="emailconfirmation.php" method="post" name="form1" id="form1"  onsubmit="return Validate();">
    Company Name: 
        <input type="text" name="CompanyName" style="width:230px; height:20px;" /><br /><br />
    Company E-mail : 
    <input type="text" name="Companyemail" style="width:230px; height:20px;" /><br /><br />
     Company Contact <input type="text" name="CompanyContact" style="width:230px; height:20px;" /><br /><br />
     Company Address: <input type="text" name="CompanyAddress" style="width:230px; height:20px;" /><br /><br />
     <input type="hidden" name="form_submitted" value="1"/> 
     <input type="submit" value="REGISTER" name="submit" />
                    </form>

In this page it should take the value from url like plan=trail or plan1... whatever there in the url. then while submitting all the values should be submitted along with these form data.

How to achieve this? Please help.

First, you need to sanitize the plan input:

<?php
    $plan = @$_GET['plan'];
    $plan = +$plan; #convert to number
?>

Just add another hidden field containing that value

<form action="emailconfirmation.php" method="post" name="form1" id="form1" onsubmit="return Validate();">
    ...
    <input type="submit" value="REGISTER" name="submit" />
    <input type="hidden" name="plan" value="<?php echo $plan ?>"/> 
</form>

Another option would be to add it as a get parameter to the action :

<form action="emailconfirmation.php?plan=<?php echo $plan ?>"
      method="post" name="form1" id="form1" onsubmit="return Validate();">
    ...
    <input type="submit" value="REGISTER" name="submit" />
</form>

Hey if you are sending a value as a part of the URL then you should have a container to grab it..use the php $_GET[] to grab that value..a bit of googling about php forms will help you rather than giving you the code.

http://www.w3schools.com/php/php_forms.asp Read from this link and keep coding!!

You need to add a hidden field to your form on ApplicationRegister.php that includes the 'plan' query parameter. The following HTML should sit within the form:

<input type="hidden" name="plan" value="<?php echo isset($_GET['plan']) ? $_GET['plan'] : 'trial'; ?>" />

The code sets the default value to be 'trial', should they visit this page without gone via the previous page.

Then you can handle the form data as you usual in 'emailconfirmation.php'. You can do something like:

 if (isset($_POST)) 
 { 
     $post_Plan = isset($_POST['plan']) ? $_POST['plan'] : null; 
     // etc ...
 } else {
     // redirect back 
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM