Author |
Message |
killing-hours
RavenNuke(tm) Development Team

Joined: Oct 01, 2010
Posts: 438
Location: Houston, Tx
|
Posted:
Thu Nov 11, 2010 3:44 pm |
|
Hey all-
I've started porting a contact form tutorial over to RN and something about the following code and the way it's coded just isn't sitting right with me.
Code:<?php
session_name("form");
session_start();
$_SESSION['n1'] = rand(1,20);
$_SESSION['n2'] = rand(1,20);
$_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2'];
$str='';
if($_SESSION['errStr'])
{
$str='<div class="error">'.$_SESSION['errStr'].'</div>';
unset($_SESSION['errStr']);
}
$success='';
if($_SESSION['sent'])
{
$success='<h1>Thank you!</h1>';
$css='<style type="text/css">#contact-form{display:none;}</style>';
unset($_SESSION['sent']);
}
include('header.php');
openTable();
|
This is not the complete code... it's just what comes before the rest of the coding and is used later in the script.
What I'm curious about is how they went about coding this. This comes from a .php file but it seems like they are jumping out of php into html. Do I need some echo's in here somewhere in order for this to be used properly in RN?? (seems like I need a few where the code jumps @ $str, $success & $css)
If you need the full script and reference... I can provide it.
Here's the original code from their php page.
Code:<?php
session_name("form");
session_start();
$_SESSION['n1'] = rand(1,20);
$_SESSION['n2'] = rand(1,20);
$_SESSION['expect'] = $_SESSION['n1']+$_SESSION['n2'];
$str='';
if($_SESSION['errStr'])
{
$str='<div class="error">'.$_SESSION['errStr'].'</div>';
unset($_SESSION['errStr']);
}
$success='';
if($_SESSION['sent'])
{
$success='<h1>Thank you!</h1>';
$css='<style type="text/css">#contact-form{display:none;}</style>';
unset($_SESSION['sent']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="formValidator/validationEngine.jquery.css" />
<link rel="stylesheet" type="text/css" href="demo.css" />
<?=$css?>
<script type="text/javascript" src="formValidator/jquery.validationEngine.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div id="main-container">
<div id="form-container">
<form id="contact-form" name="contact-form" method="post" action="submit.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="15%"><label for="name">Name</label></td>
<td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td>
<td width="15%" id="errOffset"> </td>
</tr>
<tr>
<td><label for="email">Email</label></td>
<td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td>
<td> </td>
</tr>
<tr>
<td><label for="subject">Subject</label></td>
<td><select name="subject" id="subject">
<option value="" selected="selected"> - Choose -</option>
<option value="Question">Question</option>
<option value="Business proposal">Business proposal</option>
<option value="Advertisement">Advertising</option>
<option value="Complaint">Complaint</option>
</select> </td>
<td> </td>
</tr>
<tr>
<td valign="top"><label for="message">Message</label></td>
<td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td>
<td valign="top"> </td>
</tr>
<tr>
<td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td>
<td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td>
<td valign="top"> </td>
</tr>
<tr>
<td valign="top"> </td>
<td colspan="2"><input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button2" id="button2" value="Reset" />
<?=$str?> <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td>
</tr>
</table>
</form>
<?=$success?>
</div>
</div>
</body>
</html>
|
As you can see in the html area of the coding... it seems that they are jumping out of html and back into php in some areas. (see <?= SOMETHING ?> if i'm understanding this correctly)
------------------
Edit**
After re-reading this code and what comes later in the sript... I believe it's correct the way it's coded.
Later in the script it has this to display success...
Code:echo ' ' . $success . '';
|
That echo should cover the div notated above I believe.
(I'm not getting my error messages back is why I was asking and I believe it's due to the script not actually firing for a maybe a broken link somewhere) |
_________________ Money is the measurement of time - Me
"You can all go to hell…I’m going to Texas" -Davy Crockett |
|
|
 |
Palbin
Site Admin

Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Thu Nov 11, 2010 4:27 pm |
|
Yes, you are understanding it correctly. PHP allows that, but I would not code that way. One thing to note if you do keep it I would do <?php ?> as some may have short tags disabled and <? ?> will not work.
I would code it as echo 'some html' . $css . 'some html';, but that is really up to you. |
_________________ "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. |
|
|
 |
killing-hours

|
Posted:
Thu Nov 11, 2010 4:57 pm |
|
Right... that's precisly how I'm coding this. (your suggestion)
It's a bit tricky the way they did this because they used 2 different plugins (validationEngine & jqtransform) to handle the submitting and form beautifying + error messages.
I'm still trying to figure out how to bring this over into RN with the echos and unsort all the crap they put in here as well as make sure I keep the session stuff in place. (I have no idea how that works yet)
I'm determined to bring this contact form to RN.  |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Thu Nov 11, 2010 5:08 pm |
|
Contact Plus (v1.3.0) module does all this and also has the ability to configure any number of departments etc.
I presume there would be more files to this to verify and sanitize the data server side as I wouldn't rely completely on client side validation?
What happens if JS is disabled in the users browser? |
|
|
|
 |
killing-hours

|
Posted:
Thu Nov 11, 2010 6:09 pm |
|
Well...
Contact Plus is a module and that's not what I'm aiming for. I'm shooting for a contact form that is written with jquery/ajax and will follow the user across all pages via a tab button on the side.
I will most likely leave this validation engine in place unless it just won't untangle from the form makeup.
If JS is disabled... I could use a no script to hide the form and present a message saying their JS is disabled I'm guessing. (if I can do that from the footer) |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Nov 14, 2010 8:44 am |
|
I want to make sure Guardian's point about client-side validation vs. server-side validation is emphasized. One can NEVER just rely on client-side validation. Anyone who does this is inviting to be hacked. Client-side validation is a convenience to the end-user only in that it gives them immediate feedback as to what is and is not allowed. That is all. Server-side, one must cleanse ALL input (don't forget cookies if you use them).
killing-hours, I don't know your experience level and this thread can also be seen down the road by those with less experience, hence why I am pointing this out so strongly. So please do not take offense as none is intended.  |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
killing-hours

|
Posted:
Sun Nov 14, 2010 2:09 pm |
|
None taken montego... and I hope I didn't come across as "all knowing" or something. The validator is as you say... more or less for instant feedback. I do have server side validation happening but I'm not very experience with php programming nor the do's and don'ts. I'm learning this as I go. (just "really" started less than two months ago)
Also, I am going to let you salty dogs look my work over before I feel satisfied with it precisely because I'm not sure of what I should or shouldn't be doing. I'm ALWAYS open to suggestions and comments as I'd be a fool for not.
Thank you for the feedback... I'm like you... I try to detail (probably more than I need to) as much as I can in threads because someone down the line will probably have the same n0b questions I have. |
|
|
|
 |
|