I recently had a pretty intensive PHPR project where I had to create a page for a client that called in records from their database as well as displaying a form that visitors could us to contact the “name” and “email” from that particular record. In theory this isn’t a complicated thing to get your mind around but I found that building this in PHPR *PHPRUNNER) was going to be a task for a couple of reasons.
I have had a fellow PHPR user drop me a note and ask me to document how I put all of this together so I figured I would do so here. I am going to prepare some documentation later on regarding two aspects of this project and post them to the PHPR forums later once I have a chance to document everything a little bit better…
The biggest thing that I ran into was issues with Smarty Templates and just inserting a standard PHP Form into them, that was a no-go all the way around for the most part, I did stumble on some ways to do this if anyone is interested but I ultimately didn’t use this on this project. I went back and forth with Jane from Xlinesoft for a while and she was awesome in helping get my mind around this, she also really helped me out a lot with some javascript features that the client was wanting to have with their photo gallery. Xline is awesome! If you build web portals with PHP/MySQL you owe it to yourself to checkout PHPR!
Here’s how I was able to get this particular process to work. I created a new table in the database to store the visitors (people requesting information) information in. I set my permissions so that public could hit this form and store data into it (with validation). Once I created this table and generated it’s add page in PHPR I then went and added that code to the already generated view page from PHPR of the records that I wanted to also have this form on. I then coped my form code into the view page at the appropriate place and saved it out. It took a little while inside the visual editor’s code view to get this to work exactly right but I eventually was able.
The very next part was probably the trickiest to figure out inside of PHPR because if you are familiar with PHPR you will know that you primarily are working with generated smarty pages. In order to add some logic to the form I added this event code in the event editor, (after record added)
1: // Parameters:
2: // $values - Array object.
3: // Each field on the Add form is represented as a 'Field name'-'Field value' pair
4: // $keys - Array object with added record key column values
5: // target_email and target_name are called from the existing database
6:
7:
8: //********** Send email with new data ************
9:
10: $email="".$values["target_email"];
11: $message="";
12: $subject="Resort Inquiry - ".$values["target_name"];
13: $from="Client's Name <info@clientsdomain.com>";
14:
15: foreach($values as $field=>$value)
16: $message.= $field." : ".$value."rn";
17:
18: //Headers
19: $headers = "To: " . "rn";
20: $headers.= "From: $from" . "rn";
21:
22: mail($email, $subject, $message, $headers);
23:
24:
25: //********** Redirect to another page ************
26: header("Location: http://www.clientsdomain.com/confirmation.php");
27: exit();
After I added this and tested the form it was working great. Here is something that I probably need to make sure I mention. In my trials building this particular app, I learned that i had to go in and predefine the value for 2 hidden fields in the form, one was the “name on the record” and the “email on the record”. Once i had this part knocked out everything worked great. This is pretty good to know because there wasn’t a whole lot of information on the forums when I started trying to build this particular app and I had to hunt around and find info from various places. As I mentioned, Jane at Xlinesoft was awesome to help me out with this project.
Questions or Comments?