Jump to content

Using a form as electronic gateway


houseofdeadleg
 Share

Recommended Posts

I need to create an electronic gateway that will hide a particular file until a user first enters and confirms their country of residence, and I'm not sure where to start.

The basic process is – a form is displayed asking for country of residence, a checkbox for terms and conditions, and a submit button. After passing this there is a second screen which reiterates the conditions, possibly with extra information, and a second checkbox/submit button. Passing that will display the file. They's also like to obfuscate the URL or similar, so the screens above can't be bypassed and the file accessed directly.

I've been looking through the creating forms with the api thread but it's a very long topic and Ive not been able to get very far with it. I implemented Soma's first bit of code from that thread but it doesn't seem to process the form/pick up any errors, etc. Is this the best route to stick with, or would FormBuilder be a good alternative?

Link to comment
Share on other sites

Hej,

I haven't worked a lot with FormBuilder, yet, so my approach would be to stick with the API. I just dont know enough to have an opinion about FormBuilder. 
But also since there are not too many fields and things to consider I think it shouldn't be too complex with API forms. I guess you can easily do this on one single page, keeping the state of the transaction in the session to display the correct form.

May I give you some ingredients with which I would do this instead of giving a complete solution? :-[
Also, maybe you could post your current code so we can have a look at what is going wrong/missing? I think by copying Somas forms completely in the first place and then hacking aroung you should get an idea of how those work. It is not as much as it might seem!

My few ingredients:

So one thing I would do: Keeping track of the current step of the transaction within the form itself:
You could keep track of the transaction steps with a hidden field in the 2 forms that will be presented:

$field = $this->modules->get('InputfieldHidden');
		$field->attr('name+id', 'step_id');
		$field->attr('value', 'whatever-step-id'); 
		$form->append($field); 

And incrementing the value of that step accordingly.

In the template-file for that page I would ask for that step kinda like so - the switch statement should be implemented in somas code where it says "do with the form what you like"

if($input->post->submit) {

  $form->processInput($input->post);

  // drr drr drr
  // drr drr drr

  switch ($input->post->step_id) {
    case 'step-confirm':
    	$form_output = render_step_confirm_form();
    	break;
    case 'step-granted':
    	$form_output = render_download_link();
    	break;
    default:
    	$form_output = render_step_zero_form();
        break;
  }
}

The building of the form could be put in some functions like "render_step_1_form()" so it stays a bit cleaner.
mh.
And then of course all of your other logic.

Does that help? Hope it does - 

cheers
Steffen

  • Like 1
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

×
×
  • Create New...