Avatar of iceman19330
iceman19330
 asked on

form submit

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?
DrupalContent Management

Avatar of undefined
Last Comment
iceman19330

8/22/2022 - Mon
nitinsawhney

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']
   
iceman19330

ASKER
So some gets to a page like this http://tinyurl.com/3nm46ok 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.
ASKER CERTIFIED SOLUTION
nitinsawhney

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
iceman19330

ASKER
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.


 
if($_GET['p']):

$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'];
	}

$i++;
endforeach;

print drupal_render($form);

else:

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
nitinsawhney

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'];
with
$form['submitted']['additional_items']['#value']        .= $q->title." ".$q->field_serial[0]['value'];
nitinsawhney

Also, please do a print_r($q) and try to see how the object is constructed. This would be helpful in debugging.
iceman19330

ASKER
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
Title
Serial Number
Dimension
...
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
nitinsawhney

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";
nitinsawhney

Satisfactory answers were provided to the questions posted by author.
nitinsawhney

I recommend to accept post ID 35760117 as the answer.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
iceman19330

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