form submit

iceman19330 used Ask the Experts™
So I have a link that submits to a form and the process takes the id and loads the information from node load.

$p = node_load($_GET['p']);

The problem I am running into is that I have the option to have more then one id.  How do I get the different ids out of $p.  The come over delimited by a comma (1,2,3).  Any thoughts?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The problem is not very clear. Can you please explain in detail what are you trying to do and what value is coming on $_GET['p']


So some gets to a page like this and either check the additional products below or just click "Initiate Order".  That sends the user to the order page where there is a form pre-populated with the item information.  The form was built for 1 item to be populated but I have had to alter the product page for additional items to be added.  I have run into a snag where I am unsure how to loop through on GET to get the additional ids.  The URL would look like order?p=2 for 1 or order?p=2,33,34 and so on.

<?php if($_GET['p']):

print $_GET['p'];

$p = node_load($_GET['p']); 

$form['submitted']['product_name']['#value'] 	= $p->title;
$form['submitted']['serial_number']['#value'] 	= $p->field_serial[0]['value'];
$form['submitted']['dimensions']['#value'] 		= $p->field_dimensions[0]['value'];
$form['submitted']['wood']['#value'] 			= $p->field_wood[0]['value'];
$form['submitted']['finish']['#value'] 			= $p->field_finish[0]['value'];
$form['submitted']['upholstery']['#value'] 		= $p->field_upholstery[0]['value'];
$form['submitted']['hardware']['#value'] 		= $p->field_hardware[0]['value'];
$form['submitted']['irregular_price']['#value']	= $p->field_irr_price[0]['value'];
$form['submitted']['standard_price']['#value'] 	= $p->field_std_price[0]['value'];

print drupal_render($form);

else: ?>

<p>You have not selected any product</p>

<?php endif ?>

Open in new window

I was thinking for the additional items that I would need to do a textarea or just to put it all in a text area.
you can do one thing explode the values in p into an array.


$p = explode(',', $_GET['p']);
//Now you can process $p iteratively and do whatever you want.

foreach($p as $val) {
    //do something with $val.

Hope this helps.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.


Hopefully the last issue.  So I have the form rendering and everything is populated.  The start of the additional items the textarea is populated only with the title, none of the other lines are coming in.


$p = explode(',', $_GET['p']);
$i = 1;

foreach($p as $val):
	$q = node_load($val);

	if ($i==1) {
		$form['submitted']['product_name']['#value'] 	= $q->title;
		$form['submitted']['serial_number']['#value'] 	= $q->field_serial[0]['value'];
		$form['submitted']['dimensions']['#value'] 		= $q->field_dimensions[0]['value'];
		$form['submitted']['wood']['#value'] 			= $q->field_wood[0]['value'];
		$form['submitted']['finish']['#value'] 			= $q->field_finish[0]['value'];
		$form['submitted']['upholstery']['#value'] 		= $q->field_upholstery[0]['value'];
		$form['submitted']['hardware']['#value'] 		= $q->field_hardware[0]['value'];
		$form['submitted']['irregular_price']['#value']	= $q->field_irr_price[0]['value'];
		$form['submitted']['standard_price']['#value'] 	= $q->field_std_price[0]['value'];
	} else {
		$form['submitted']['additional_items']['#value'] 	= $q->title." ".$q->field_serial[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_serial[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_dimensions[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_wood[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_finish[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_upholstery[0]['value'];
		$form['submitted']['additional_items']['#value'] 	.= $q->field_hardware[0]['value'];
		$form['submitted']['additional_items']['#value']	.= $q->field_irr_price[0]['value'];
		$form['submitted']['additional_items']['#value']	.= $q->field_std_price[0]['value'];


print drupal_render($form);


Open in new window

One thing I can see is that even the first assignment should be with a . (concatenation) else the last product will override the information of previous additional products.

So replace, $form['submitted']['additional_items']['#value']        = $q->title." ".$q->field_serial[0]['value'];
$form['submitted']['additional_items']['#value']        .= $q->title." ".$q->field_serial[0]['value'];
Also, please do a print_r($q) and try to see how the object is constructed. This would be helpful in debugging.


The last bit was boneheadedness :D  The field names are different for additional items then products and I just copied and pasted them over and didnt change the names.

One last question.  on the textarea is there a way to do returns so it looks more like
Serial Number
Try using "\n" at the end of each line.

For e.g. (using your existing code for reference)

$form['submitted']['additional_items']['#value']       .= "Title: " . $q->title." ".$q->field_serial[0]['value'] . "\n";
$form['submitted']['additional_items']['#value']       .= "Serial: " . $q->field_serial[0]['value'] . "\n";
Satisfactory answers were provided to the questions posted by author.
I recommend to accept post ID 35760117 as the answer.


DId I select my own post?  Boy its been a long night.  Sorry about that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial