Jump to content


Photo

problem fetching info from form with name + id


  • Please log in to reply
6 replies to this topic

#1 tomer_shim

tomer_shim
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 April 2006 - 02:08 AM

Hello,
I am using snoopy php class ([a href=\"http://sourceforge.net/projects/snoopy\" target=\"_blank\"]http://sourceforge.net/projects/snoopy[/a]) to build a 'auto submitter' for an online form. to do so, I used an example code from the README page included in that class docs.
this is the example:

include "Snoopy.class.php";
    $snoopy = new Snoopy;
    
    $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
    
    $submit_vars["q"] = "amiga";
    $submit_vars["submit"] = "Search!";
    $submit_vars["searchhost"] = "Altavista";

        
    if($snoopy->submit($submit_url,$submit_vars))
    {
        while(list($key,$val) = each($snoopy->headers))
            echo $key.": ".$val."<br>\n";
        echo "<p>\n";
        
        echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
    }
    else
        echo "error fetching document: ".$snoopy->error."\n";

while im trying to use this code for a regular form which has Text input boxes look like:

<input type="text" name="title" size="50" maxlength="50">

Then it works, all i need to do is edit the $submit_url and the $submit_vars array to the input 'name's.


The problem starts when i tried to use that class for input boxes which includes array's like:

<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
<input type="text" name="url[]" size="30" id="du9" onchange="donh(this.id);">

I problem is that i dont know how to write the name of each of these input boxes in the $submit_vars array. i tried stuff like $submit_vars['name[id]'] = "something" (for example $submit_vars['title[dt9]'] = "blabla") but it didnt work. I need to know what is the syntax to do so.

This will really halp my project if someone could please help me.

Thank you in advance!!

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 April 2006 - 02:26 AM

Got no idear but trying good luck mate.
$url=$submit_vars["submit_url"];

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 tomer_shim

tomer_shim
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 April 2006 - 03:16 AM

that aint really going to fix my issue :( , but thank you for trying.

anyone have other ideas?

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 03:58 AM

Simply do the same thing as before.

$submit_vars['name'] = 'Whatever';

Or to access a specific key:

$submit_vars['name'][1] = 'Whatever';
~ D Kuang

#5 tomer_shim

tomer_shim
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 April 2006 - 11:45 AM

what the name stands for though? the input line contains Name and ID, which one goes under 'name' on the $submit_vars array?
i mean, accoring to:
<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
how the line should look like?
$submit_vars['title'] = 'Whatever';
$submit_vars[dt9'] = 'Whatever';

which one should i use? in one i put the title (name in input) , in the other i put the id (id in input).
if u use title, its actually then name of the hole array cause i have lots of input boxes like that, here only ID changes. and if i put only ID i miss the Title name.
what sould i do?

thanks in advance.

#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 02:35 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<input type="text" name="title[]" size="50" maxlength="50" id="dt9" onchange="donh(this.id);">
how the line should look like?
$submit_vars['title'] = 'Whatever';
$submit_vars[dt9'] = 'Whatever';[/quote]
The "id" attribute is irrelevant, since it's not sent.

It depends, whenever you have fields named whatever[], PHP will get an array named whatever. For example:
<input type="text" name="fruit[]"><br /> <<-- If you write 'banana here',
<input type="text" name="fruit[]"><br /> <<-- 'apple' here
<input type="text" name="fruit[]"><br /> <<-- and leave this blank
You will get an array:
Array
(
    [0] => banana
    [1] => apple
    [2] => 
)
So, to access it, you must use $_POST['field_name_here']['position_here']. To get "banana", I would use $_POST['fruits'][0].


~ D Kuang

#7 tomer_shim

tomer_shim
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 April 2006 - 02:41 PM

thank you, but you have any idea how can i send the info?
with snoopy class im trying to simulate form submit, so i actually need to send the information with $submit_vars to the php page which include the form, and not get the data with $_POST.
any idea how can i send it with $submit_vars which used in snoopy class?

Thank you for trying to help, in advance!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users