help with php

goldy300

New Member
Messages
33
Reaction score
0
Points
0
I'm here all night to try and get this done. I have to fix a form up to take petition title, petition, category, duation, target, short title (for url) and keywords and insert them into a database.

I need the form to validate. No empty fields and the form has to pass to a preview page before its inserted into the database for review. The petition should not submit if the user has not signed up and logged in.

I can show you some of what I have but its the basics as I'm not very well versed on php and need the help urgently.

I would appreciate if you contact me via msn and I can work, chat and upload files as we go. Add me airbrushkits@live.com

Here is a link to the page: http://daniel.classroomonline.info/govpetitions/startpetition.php?pagename=startpetition

Heres what I have:
HTML:
<?php

    
    mysql_query("INSERT INTO petitons SET petitions_id='',members_id='',short_name='$_POST[short_name]',p_title='$_POST[p_title]',target='$_POST[target]',petition='$_POST[petition]',duration='$_POST[duration]',category='$_POST[category]',keywords='$_POST[keywords]'");
   

?>
                    <p>&nbsp;</p>

                    <form method="post" name="form1" action="insertpetition.php"> 

                    
                    <b>The petition of citizens and residents of Australia call on the Australian Government to...</b><br>
                        <input type="text" name="p_title" size="60" class="normtext"></p>

                    <p>&nbsp;</p>

                    More details about your petition (1000 characters maximum):<br>
                        <textarea rows="6" cols="60" class="normtext" name="petition"></textarea><p>
                    <p>&nbsp;</p>

                    Select Duration:    <select name="duration">
                                                        <option value="1month">1 Month</option>
                                                         <option value="3months">3 Months</option>
                                                        <option value="6months">6 Months</option>
                                                        <option value="1year">1 Year</option>
                                                    </select>
                                                        
                    
                    <p>&nbsp;</p>    

                    Select a short name for your petition (Max 20 characters): <input type="text" name="short_name" class="normtext"><br>
                        <span class="smalltext">This gives your petition an easy web address. e.g. (http://www.govpetitions.com.au/newpark)</span><p>
                    
                    <p>&nbsp;</p>

                            Please select a category for your petition<br>
                            <select class="normtext" name="category">
                                <OPTION>Select a category</OPTION>
                                <option value="counsel">Counsel</option>
                                <option value="roads">Roads & Traffic</option>
                                <option value="aboriginal">Aboriginal Affairs</option>
                                <option value="health">Health</option>
                                <option value="rural">Rural</option>
                                <option value="residential">Residential</option>
                                <option value="education">Education</option>
                                <option value="law_enforcement">Law Enforcement</option>
                                <option value="correctional">Correctional</option>
                                <option value="development">Development</option>
                                <option value="work_rights">Work Rights</option>
                                <option value="religion">Religion</option>
                                <option value="imigration">Imigration</option>
                                <option value="national">National</option>
                                <option value="state">State</option>
                                <option value="other">Other</option>
                            </select>

                    <p>&nbsp;</p>
                        
                    Please enter keyword which are relevant to what your petition is about:<br>
                    <span class="smalltext">Separate keywords with comma only. E.g. license,driving,disqalified</span><br>
                    <input type="text" name="keywords" size="50">
                    <br>&nbsp;</br>

                    <center><input type="image" name="submit" src="http://forums.x10hosting.com/images/preview.gif" ></center>

                    </form>

My table in the db is like this:

Table name is petitions

Fields:

  • petitions_id
  • members_id
  • short_name
  • p_title
  • target
  • petition
  • duration
  • category
  • keywords
In that order
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
First off, you already have a form validation topic running at http://forums.x10hosting.com/programming-help/91771-validating-forms-javascript-help-needed.html

The petition should not submit if the user has not signed up and logged in.

Simple - just have a bit of code like this at the top of the page (after session_start();)

PHP:
<?php

if (isset($_SESSION['username'])) { //ask if a user is logged in by checking if a username variable is in session memory

****put your form and processing code here****
} else {// if a user is not logged in then...
echo "You need to be logged in to do this";
?>

the form has to pass to a preview page before its inserted into the database

If you want to do this, forget about inserting anything on this page. (i.e. remove the mysql_query) and just stick to the form.

The form action will simply be the URL of a preview page (we'll call it "formpreview.php"

To create your preview page, simply put your mysql_query at the top with a condition that the entries have been confirmed and then echo each value to be inserted from the $_POST values from the previous page.

i.e.

PHP:
<?php

echo $_POST['p_title']."</br>";
echo $_POST['petition']."</br>";
echo $_POST['duration']."</br>";
echo $_POST['category']."</br>";
echo $_POST['keywords']."</br>";
?>

Then create a form at the base.

Put in a hidden field with a name like "form_submitted" and a default value of "Y".

Put in a "confirm" or "submit" button) and form action is "" (submit only)

I haven't checked the following code but its along the right lines for your preview page.

PHP:
<?php
session_start();
if (isset($_SESSION['username'])) { //ask if a user is logged in by checking if a username variable is in session memory
$post_form = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $post_form .= "?" . $_SERVER['QUERY_STRING'];
}
if ((isset($_POST["form_submitted"])) && ($_POST["form_submitted"] == "form1")) {
  mysql_query("INSERT INTO ... blah blah values from $_POST") or die(mysql_error());
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Preview</h1>
<?php
echo $_POST['p_title']."</br>";
echo $_POST['petition']."</br>";
echo $_POST['duration']."</br>";
echo $_POST['category']."</br>";
echo $_POST['keywords']."</br>";
?>
<form name="form1" method="POST" action="<?php echo $post_form; ?>">
<input name="form_submitted" type="hidden" id="form_submitted" value="Y">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
<?php } else {// if a user is not logged in then...
echo "You need to be logged in to do this";
?>
 
Top