0

I have this webpage. It has a page called "services.php". I have several buttons (made of classes), that belong to different "package" prices i offer.

I want the links that say "Select" to autofill a form in another page, or alternativly in a popup form in the page.. I don't really know how to explain it, but as short as possible:
When link is pressed autofill form (in this or other page) with the type of package they chose. Only text autofill

2
  • how do you make a button out of classes? ;)
    – Jakub
    Dec 2, 2010 at 14:07
  • He probably meant css classes :P
    – Ali
    Dec 2, 2010 at 14:20

6 Answers 6

0

What you seem to be asking is 'loading' a page pre-filled with specific information, you can do this a number of ways, either by utilizing javascript (like jQuery for instance). Or using your PHP, make links that pass variables (say a flag or a reference to pre-fill the fields -- if you want a popup or next page, etc).

Your url would like like the following for the button that a user presses (button would be a simple http link):

http://mywebsite.com/prefill.php?user=bob&package=2

This would have the values bob as the user that requests it (you can reference an id for user info here as well), and package=2 to designate your package options.

Then on the prefill.php page, you would have something that checks for:

$user = $_GET['user'];
$package = $_GET['package'];

Hope that helps

0

This will populate form fields with whatever you pass to the autoFill() function. This would be a same page example.

<html>
<body>

    <form>
        <input type="text" id="packageDescription">
        <input type="text" id="packagePrice">
    </form>

    <script>

        function autoFill(packageDescription, packagePrice) {

            document.getElementById('packageDescription').value = packageDescription;
            document.getElementById('packagePrice').value = packagePrice;

        }

    </script>

    <a href="#" onClick="autoFill('Premium Package', 150); return false;">Premium Package</a><br>
    <a href="#" onClick="autoFill('Platinum Package', 350); return false;">Platinum Package</a>

</body>
</html>
0

You could do something like this:

<select id="packages">
  <option value="package1">Package 1</option>
  <option value="package2">Package 2</option>
</select>

<a href="javascript:submitPackage();">Submit</a>

When the link is clicked, the following javascript will fire off:

function submitPackage()
{
  var package = $("#package").val();
   window.open("http://your-site.com/some-script.php?package=" + package);
}

The above will open a pop up window to a page such as this:

http://your-site.com/some-script.php?package=package1

In some-script.php you will do something like this:

You selected the package: <b><?php echo $_GET['package'];?></b>.

Or:

<?php
//Put the packages in an array:
$packages = array();
$packages['package1'] = 'Package 1';
$packages['package2'] = 'Package 2';
//...
?>   

<select id="package">
 <?php foreach ($packages as $name => $text):?>
   <? $selected = ($name == $_GET['package']) ? 'selected' : '';?>
    <option value="<? php echo $name;?>" <?php echo $selected;?>> 
       <?php echo $text;?>
   </option>
 <? endforeach;?>
</select>

The above will auto select the package they selected in a dropdown box.

0

if i understood your problem, you want to fill some input fields with information when the user clicks on some links

i can think of 2 ways of doing this : either have the links point to a page like services.php?req=package1 (or any other url you want) and on that page generate the input fields with the information you need (set the default values in the fields with the ones you want), or, use javascript to change the values of the forms without changing the actual page (either via ajax or predefined values)

for javascript you can use the jQuery framework, it has a pretty extensive community of enthusiasts and plenty of examples to get you started with it.

an example for your case would be

$('#btn1').bind('click', function() {
  $('#input1').val("value");
  $('#input2').val("value2");
});

replace btn1 with the id of the first button or link you have, input1 with the id of the first input in your form, and value with the value you want

0

I just did this myself. My solution was with jQuery. Just assign an id to your link. The first ID in the code is the link id and the second is the id for the input element you want to populate.

Here is the script:

 <script>

   $(document).ready(function() {

    $('#link_id').click(function() {
        $('#input_id').val( $(this).text() ).keyup();
         return false;
     });

   });

 </script>

Hope it works!

0

I've ran several time into the same issue, so I had to write my own script doing this. It's called Autofiller and its pretty simple but does great job.

Here is an example

http://example.com/?autofiller=1&af=1&pof=package&package=package1

So basically it takes several parameters to init the script:

autofiller=1 - init AutoFiller

af=1 - Autofill after page is loaded

pof=package - Find the parent form element of the select with name attribute package. Works also with input form elements.

package=package1 - Will set the select element's value to package1

Hope it helps you! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.