I'm making a social network type site, where users can upload their items to be rated. However, I'm trying to improve the way the site is laid out, so want to automatically generate pages once the user inserts a new item. The add.php page has the following form:
<form action="add.php" method="post" autocomplete="on" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" id="pic">
<p> <label for="jname" class="iconic user"> Name of Jam <span class="required">*</span></label> <input type="text" name="jname" id="jname" value="<?php if (isset($_POST['jname'])) echo $_POST['jname']; ?>" required="required" placeholder="Input your Name of Jam here" /> </p>
<p> <select name="jtype" id="jtype" value="<?php if (isset($_POST['jtype'])) echo $_POST['jtype']; ?>" required="required">
<option value="jam">Jam</option>
<option value="jelly">Jelly</option>
<option value="marmalade">Marmalade</option>
<option value="preserve">Preserve</option>
</select> </p>
<p> <label for="producer" class="iconic user"> Jam Producer <span class="required">*</span></label> <input type="text" name="producer" id="producer" value="<?php if (isset($_POST['producer'])) echo $_POST['producer']; ?>" required="required" placeholder="Input the producer of the Jam here" /> </p>
Upload a picture of your jam: </br> </br> <input name="userfile" type="file" /> </br>
<input type="submit" name="submit" value="Register" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
When the form is submitted, I then want it to generate a new page for that new user created item. Is there a fairly simple way of doing this?
Cheers
You don't have to actually 'create' new html page for each item.
You could save this information to database (mysql for example).
Then you could create another php file, say 'item.php' and access different entries from mysql database like so:
item.php?id=1
This generally isn't the way such sites are created. (i.e.: You don't generate the physical pages themselves at the point of form submission.) Instead, you'd usually store the form data in a database and then retrieve/display it based on the URL - either by decoding the URL itself via a "controller" or by using a query string variable such as ?producerid=x. This data would then be used to populate a template.
To be honest, I'd really recommend getting hold of a recent PHP book (as far as database access is concerned, you should be using PDO or MySQLi) or following some online tutorials - whilst it might initially seem like this won't be a meaningful form of progress, its likely to pay substantial dividends in the long run.
The best and efficient way to do it is to store the data in a database and retrieve it whenever user clicks on specific item. One thing though, if part of your plan is to make your site accessible by google search engine, you have to generate the individual web pages... because, google is only a web crawler...it cant get into mysql or other databases.
Usually there's no new page generation for things like that. You should create a template and load dynamic informations from other sources (such an XML file or a database) to it so that it seems a completely new page.
Just:
See what each item page has in common
Define a template which contains the common code
Retrieve dynamic informations (item infos for example) from a database
Use PHP embedded in HTML to load dynamic HTML
An example:
Facebook does not create a new page per each user registration. There's an HTML template which defines the position of the profile photo, the position and style of the posts, the position and style of the friend list and stuff common to any profile page, and then just load different informations when you call such a page for Mark, Frank, Jeff and so on.
Related
CMF MODX revolution
There is a template with a form
<form action="http://localhost/index.php?id=3" method="post">
<input type="name" name="name">
<input type="search" placeholder="Все товары" name="search_bar">
<input type="submit" value="">
<div style="clear: both;"></div>
</form>
which call a snippet which contains debugging line:
echo '|||||||||||| ', $_POST['search_bar'];
The problem.
If I put a value into search bar - echo will not show anything. But if I save the template
before I putt the value into the search bar and click submit button, then echo display right value from the search bar
Suppose the problem is in caching. But I cleaned it and it is cancelled everywhere (at least I think so, exploring administrator panel).
For Snippets that depend on user input (like a search query) you will want to call them uncached: [[!mySnippet]]
However if you want to gain a bit of performance you can wrap the Snippet call with Jason Coward's getCache, and by default it caches to a unique cache key based on the $_GET parameters. In other words, each search query would get its own cache object. This helps when there are repeat searches for the same string.
Here is the Form Code i am using :
<form name="download_frm" action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<input type=hidden name="oid" value="***********">
<input type=hidden name="retURL" value="http://----/">
<!--<input type="hidden" name="debug" value="1"> -->
<p><input type="text" value="" name="name" id="name" maxlength="50" class="" placeholder="Name"/></p>
<p><input type="text" value="" name="mail" id="mail" maxlength="50" class="" placeholder="E-mail"/></p>
<p><input type="text" value="" name="org_name" id="org_name" maxlength="50" class="" placeholder="Organization Name"/></p>
<p>
<select name="org_typ" id="org_typ" >
<option selected="selected">Organization Type</option>
{if isset($orgtypes)}
{foreach $orgtypes as $array}
<option value="">{$array->Dev_Type}</option>
{/foreach}
{/if}
</select>
</p>
<p><input type="number" value="" name="phnum" id="phnum" maxlength="50" class="" placeholder="Phone Number(Optional)"/></p>
<p><input type="text" value="" name="cntry" id="cntry" maxlength="50" class="" placeholder="Country (Optional)"/></p>
<p><input type="submit" name="submit" id="submit" value="submit form" /></p>
</form>
After submitting the form,it is returning to the given returnURL.But i want to get the information whether the form data is stored successfully or not.
Please Advise me..
Thanks in Advance.
Because the Salesforce Web to Lead code is designed to work with all web servers / web sites / pages, by design it doesn't retrieve that information in regular usage. Whether the submission is successful, or fails, it will simply redirect the visitor to the page specified in retURL.
This behavior might be frustrating if you want information back, but it does allow the web-to-lead to be used practically anywhere, which is the point.
You can, in testing, enable debugging mode. See the original HTML produced by the Salesforce Web to Lead code generator. This will enable an intermediary page that will show you what is being submitted. However, you would not want to use this on a production site, as all of your customers would see this intermediary page.
If you're worried about rejected submissions, that is rare, and in any case Salesforce will send you an email with the submitted form values and why it failed. It will usually fail because of validation rules (to get around this, use Page Layout rules rather than validation rules if you want to require a field to be populated).
You still have a couple options to accomplish what you are trying to do.
One is simply to check Salesforce Leads for submissions - but I presume this information need to be processed, not just viewed by a human.
In that case, the rest of your options require you to do something more than use the standard web to lead code if you want your website to know about the form submission.
Presuming you're using a common CMS you can use plugins for Wordpress (Gravity Forms Salesforce Add-On or Wordpress to Lead) or Drupal's Webforms with the Salesforce add-on.
Or, alternatively, you can re-write the form as a PHP file (or a similar language) that passes the information to Salesforce via CURL - and does any other number of things at the same time using PHP, like passing it to another database. There's a lot on the internet - just google 'salesforce web to lead php curl'
All of the above options work for all versions of Salesforce. If you have Enterprise and higher, or Professional with the API, you can also pass the information to Salesforce via the API. This will allow you to bring back information such as the Lead ID - or pass the information to other objects, de-dupe, upsert, etc. Keep in mind this level of coding is both more complex and will require authentication into Salesforce, so only follow this option if the added functionality is worth the additional overhead.
I decided to open a new question for this topic, as I have been having issues with it. My blog has a mysql database with the table posts complete with a post_user field. Each user has a form and can submit a post to a public blog. Once they submit this form, complete with a title and a body, when it is posted on the blog it should say by Username. My idea is that I can save the username to the post_user in the database upon form submission using $_SESSION info, but I am not exactly sure how to do this. Any help would be greatly appreciated.
The form, with the old UNSECURE way of entering the session author, note I am only including session data in the form to display what I am trying to show on a blog post, I don't know how to do it any other way hence my question:
<form action="" method="post">
<p>
<input type="hidden" name="user" id="user" value="<?php echo $_SESSION['user']['username'] ?>" readonly />
</p>
<p>
<input type="hidden" name="userid" id="userid" value="<?php echo $_SESSION['user']['id'] ?>" readonly />
</p>
<p>
<label for="title">Title: </label>
<input type="text" name="title" id="title" />
</p>
<p>
<textarea name="body" rows="20" cols="60"></textarea>
</p>
<p>
<input type="submit" value="Add Post" />
</p>
</form>
Code that posts the entry:
$posts = get_posts();
foreach($posts as $post)
{
?>
<h2><?php echo $post['title']; ?></h2>
<h4>By <font color="#FF6347"><?php echo $post['user']; ?></a></font> on <?php echo $post['date']; ?></h4>
<h4><?php echo $post['total_comments']; ?> comments, last comment <?php echo $post['last_comment']; ?>
<hr />
<p><?php echo $post['preview']; ?></p>
<?php
}
?>
You shouldn't save the username on the posts table. You should have two separate tables: one for the posts and one for the users, which are linked via a user_id field, a.k.a foreign key.
This is the way relational databases, such as MySQL, operate. This serves a few purposes:
You avoid repetition in case of one to many relations, which is exactly your case: one user can post many posts.
You use a unique identifier.
The information is organised better instead of mixing data together.
The way to tie the tables together when retrieving data is by using a JOIN statement, which links the two tables via the common user_id field. It is highly recommended to make this field an index, which would significantly speed up data retrieval. (Think about the difference between finding a certain word or sentence in a book by scanning through each and every page, and finding a chapter using the, well, index)
To sum up, you should have an id key in your $_SESSION super-global array, which you then insert to the user_id field upon post submission.
As for your question, you don't need to send the session data with a hidden input field, because it will be available even after submission - after all this is what session is all about. So why convert it to $_POST and expose it publicly?
I have a problem in my php form :
isbn number is a GET variable .
Thus view.php opens in a URL like : localhost/../view.php?isbn=0810982463. Whereas I want the url structure to be like localhost/..../0810982463. I know it can be done by using the Post method, Can it be done using the GET method ?
<form action="view.php" method="get">
<p class="name">
<label for="isbn">ISBN No. </label>
<input type="text" name="isbn" id="isbn" value="0199555311">
</p>
<p class="submit">
<input type="submit" value="Search Book" />
</p>
</form>
No matter what, the GET form submission will be in a query string format, just look at Google's form submission, or even Stack Overflow's own searching. This is the way things have been standardized across browsers.
If you want it to look pretty, after the submission, you'll need to redirect the user to a pretty URL.
This question has been asked multiple times before,
but I have a different situation from those I've read.
My Database multiple forms that are to be loaded upon user request. This is not the problem and I can handle this. Within these forms, there are fields that are filled dynamically from 2 queries.
One of my fields that is to be filled from the database looks like this:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="<? echo $queryB[1]; ?>" readonly="readonly" />
as you can see, the value is set to be a PHP code echo $queryB[1] ... When I got the form from the DB and echoed it, the fields got the value <? echo $queryB[1]; ?> instead of the actual value.
I've tried to use eval($myForm) where my form is retrieved from the DB, but nothing appeared in the place where the form should appear. I would appreciate if someone can help me with this.
Your PHP instance has short_open_tag disabled.
Change it to:
<?php echo $queryB[1]; ?>
...and it should do what you expect.
There is nothing different in your situation and it is exactly the same as others.
and the answer is the same as well: do not mix the code and the data.
Do not store the code in the database.
Do not pass GO, do not collect $200
Implement some sort of placeholders or - even better - some form builder and create these forms on the fly, based on the data from database.
Why not to store only relevant data in the database, like
name
type
value
class
and some flags like disabled, readonly and such?
take a look at http://pear.php.net/package/HTML_QuickForm2/
Building on my comment and Col Shrapnel's answer, here is a simple placeholder example. You should really maintain the HTML in a flat file (as it effectively seems to be part of the view in your application), but for simplicity's sake let's say it still resides in the database. Store the following value:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="{queryValue}" readonly="readonly" />
Now, when you load the value from the database, you can replace the placeholder from the text:
$html = str_replace('{queryValue}', $queryB[1], $htmlTemplate);
This is an incredibly simplified example, and masks a load of potential issues regarding placeholder names, formats etc., but it might get you started.
Alternatively, if you decide to opt for the file route, you could have two files:
view.phtml:
<label class="itemLabel" for="name">Name : </label>
<input name="name" type="text" class="itemInput" value="<?php echo $this->value; ?>" readonly="readonly" />
In your current PHP script:
class View {
public function render($file) {
// check for file existence etc.
require_once $file;
}
}
$view = new View();
$view->value = $queryB[1];
$view->render('view.phtml');