| | |
preview option before form submission
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2008
Posts: 74
Reputation:
Solved Threads: 0
i want to provide an option to user to preview the form input before form submission, it runs well, but it does the same action on pressing submission or preview button
html the php script is as follow
when i press submit it enters all data to database, but the same thing happens after pressing preview button as well.
i have tried every option, i know but in vain..i am not understanding where i am doing wrong. please some one guide me in this regard.
thanks in advance
shuja
html
<form>
<tr>
<td width="26%" height="30" align="right"><font face="Calibri">Category:</font></td>
<input type="text" name="category" size="30"></td>
<td width="26%" height="30" align="right"><font face="Calibri">City:</font></td>
<input type="text" name="city" size="30"></td>
<td width="26%" height="30" align="right"><font face="Calibri">Ad Title:</font></td>
<input type="text" name="adTitle" size="30"></td>
</tr>
</table>
<p align="center">
<input name="put" type="submit" value="Submit" onclick="action='postAd.php?action=submit';">
<input name="put" type="submit" value="Preview" onclick="action='postAd.php?action=preview';">
</p>
</form>if(isset($_POST['put'])) {
$category = $_POST['category'];
$city = $_POST['city'];
$adTitle = $_POST['adTitle'];
$action = $_POST['action'];
if ($action = 'preview')
{
echo $category;
echo $city;
echo $adTitle;
}
if ($action = 'submit')
{
if (!get_magic_quotes_gpc()) {
$category = addslashes($category);
$city = addslashes($city);
$adTitle = addslashes($adTitle);
}
$sql = "INSERT INTO `class-ads`.`post-ad` (ad_id, cat_name, city_name, ad_title, )
VALUES (NULL,'$category', '$city', '$adTitle')";
mysql_query($sql) or die('Error, Posting Ad failed : ' . mysql_error());
echo "You successfully posted the advertisment";
}
}when i press submit it enters all data to database, but the same thing happens after pressing preview button as well.
i have tried every option, i know but in vain..i am not understanding where i am doing wrong. please some one guide me in this regard.
thanks in advance
shuja
•
•
Join Date: Aug 2007
Posts: 64
Reputation:
Solved Threads: 0
If I may try my hand at this
:
-Add the to your form tag.
-Change to
:-Add the
PHP Syntax (Toggle Plain Text)
method = "post"
-Change
PHP Syntax (Toggle Plain Text)
$action = $_POST['action'];
PHP Syntax (Toggle Plain Text)
$action = $_GET['action'];
Maybe this example will help you understand better.
I have named the buttons differently. I also don't need onclick events.
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['preview'])) { print "<pre>"; print "Preview button pressed..<br>"; print_r($_REQUEST); print "</pre>"; } if(isset($_POST['submit'])) { print "<pre>"; print "Submit button pressed..<br>"; print_r($_REQUEST); print "</pre>"; } ?> <form method='POST' action='postAd.php'> <tr> <td width="26%" height="30" align="right"><font face="Calibri">Category:</font></td> <input type="text" name="category" size="30"></td> <td width="26%" height="30" align="right"><font face="Calibri">City:</font></td> <input type="text" name="city" size="30"></td> <td width="26%" height="30" align="right"><font face="Calibri">Ad Title:</font></td> <input type="text" name="adTitle" size="30"></td> </tr> </table> <p align="center"> <input name="submit" type="submit" value="Submit""> <input name="preview" type="submit" value="Preview""> </p> </form>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Other Threads in the PHP Forum
- Previous Thread: PADL (PHP Application Distribution License System) if anybody used give guidelines?
- Next Thread: Extract URL
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube






