Welcome Guest, Not a member yet? Register   Sign In
Trying to not go to a different page after form submit...
#1

(This post was last modified: 01-14-2015, 06:11 AM by alexandervj.)

Hello,
I have a form you can see at www.trilumina-temp.com and then click on the "Download Now!" link under the slider where it says "Download a Product Sheet" ..its not really a download though. I would like to not go to a different page after you submit the form, and just to show text or show a hidden div in the modal after the form is submitted saying "Thank you" or something like that. Is there a way I can do this? Thanks
Reply
#2

For this I would recommend submitting the form with Javascript VIA ajax (jQuery is a nice javascript lib for this) against a different controller method. That controller method can then return JSON which you can test in your Javascript for a error or link or something. Which you can then display in your <div> for example. (Thank you here is your link etc...)

I have been using this method for years to post all of my forms to have the model validation done by the model only returning the responds to the end user. If it's all good then the form is submitted "for real". Of course the controller I runs it again against the same model (just for security because it already was checked it "should" be good). That keeps me from writing form validation in Javascript AND again in PHP. I only need to write it once in PHP (in the model). This also saves me from the form post -> validate -> fail -> form redisplay -> form post -> validate -> fail.... loop. The user never posts the form until it's actually "good".

Hope that helps?
Reply
#3

That helps very much. I'm not too familiar with jquery or json - do you know of any references or tutorials that can show how to do something like this?
Reply
#4

check out jquery api documentation for ajax here: http://api.jquery.com/category/ajax/
"I reject your reality and substitute my own" - Adam Savage, M5 Inc.
Reply
#5

I found this ...
http://www.sanwebe.com/2011/12/making-si...ntact-form
I'm gonna go through this but I'm a little unsure what I need to change to make it work with codeigniter instead of just plain php. Any help is appreciated
Reply
#6

(This post was last modified: 01-17-2015, 07:29 PM by dmyers.)

(01-14-2015, 09:43 AM)alexandervj Wrote: I found this ...
http://www.sanwebe.com/2011/12/making-si...ntact-form
I'm gonna go through this but I'm a little unsure what I need to change to make it work with codeigniter instead of just plain php. Any help is appreciated

Sure, Let me try to explain some to you ok?

Of course this line handles the click on the html element with the id="submit_btn"

$("#submit_btn").click...

It then checks that a few required fields are filled in setting "proceed"

Finally if proceed is true it sets "post_data" with the post data and sends it to $.post('contact_me.php',

the contact_me.php page (therefore you would need a controller which handles that).

you then need to send json as your reply

something like this.

$data['type'] = 'error'

echo json_encode($data);

it than stays there and let's you post again.

If you like I can put together a demo which does the validation server side like I explained.

zip it up and post a link here?

Would that help? I don't mind.

dmyers
Reply
#7

Here you go https://github.com/dmyers2004/CI3-Ajax-P...Validation

This does the posting like I said.
The returned JSON could for example add a <a href="downloads/file765678765.zip">Download</a>
To the page $('#link').html(response.download);
Reply
#8

Ok, I updated the code to provide a download link you requested.


I also created a tag on the GIT repro to the original validate / post workflow.
https://github.com/dmyers2004/CI3-Ajax-P...ation-post

Hope that helps?
Reply
#9

Thanks a lot!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB