Jump to content

Filling in form field from url variable


GeekMan
 Share

Recommended Posts

Background: Our website is hosted and they use processwire.  I can update information and create forms on the website but I do not do any programming or settings in processwire.  So I'm really a processwire noob.

So is it possible for me to have a url like /registration/intro-to-computers/?name="Intro to Computers" and then on the form that I've created to have the name field on the form to autopopulate to "Intro to Computers"???

This way I can create my urls for many different classes and use 1 form and not make the student type in the class name each time they register.

thanks in advance.

Link to comment
Share on other sites

That's certainly possible, but how to do it depends on how you're creating these forms. Also you should keep security in mind, when building such a thing, as everyone can change and request an url of this type, but with totally different values. 

Link to comment
Share on other sites

you would need to:

1.) allow the form to accept GET params (in the form setting)

2.) Use a select field for the class, or a text field

3.) make your link to the form that references the page ID of the class, like:

/registration/intro-to-computers/?class=1298 (page select)

or url encode the title if using a text field

/registration/intro-to-computers/?name=Intro%20to%20Computers%22

and you probably would want to sanitize the input, though i think FB sanitizes input by default?

Link to comment
Share on other sites

I got it to work!!!

I was putting the variable in the wrong place. At first I did this:   form-builder/test/?course_name=Intro%20to%20Computers

The form-builder should really just be: form-builder/test

and the link calling it should be:  /registrations/test/?course_name=Intro%20to%20Computers

this calls the form and puts the variable into the course_name field like it is suppose too.

Link to comment
Share on other sites

  • 3 years later...
On 8/3/2015 at 3:50 PM, Macrura said:

you would need to:

1.) allow the form to accept GET params (in the form setting)

2.) Use a select field for the class, or a text field

3.) make your link to the form that references the page ID of the class, like:

/registration/intro-to-computers/?class=1298 (page select)

or url encode the title if using a text field

/registration/intro-to-computers/?name=Intro%20to%20Computers%22

and you probably would want to sanitize the input, though i think FB sanitizes input by default?

Can you give more detail on #3?

Link to comment
Share on other sites

2 hours ago, J_Szwarga said:

Can you give more detail on #3? 

it means for example if you were linking from a page to a form and what that page reference, you'd echo the url like

<a href="<?=$pages->get(9999)->url?>?pageref=<?=$page->id?>">Register Now</a>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...